明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 2088|回复: 4

求助,无名块插入的程序,错在哪?

[复制链接]
发表于 2006-3-22 22:25:00 | 显示全部楼层 |阅读模式
无名块插入的程序,错在哪?
  1. Sub Example_InsertBlock()
  2.     ' This example creates a block containing a circle.
  3.     ' It then inserts the block
  4.     ' Create the block
  5.     Dim blockObj As AcadBlock
  6.     Dim insertionPnt(0 To 2) As Double
  7.     insertionPnt(0) = 0#: insertionPnt(1) = 0#: insertionPnt(2) = 0#
  8.     Set blockObj = ThisDrawing.Blocks.Add(insertionPnt, "*u")
  9.     ' Add a circle to the block
  10.     Dim circleObj As AcadCircle
  11.     Dim center(0 To 2) As Double
  12.     Dim radius As Double
  13.     center(0) = 0: center(1) = 0: center(2) = 0
  14.     radius = 1
  15.     Set circleObj = blockObj.AddCircle(center, radius)
  16.     ' This example creates an attribute definition in model space.
  17.     Dim attributeObj As AcadAttribute
  18.     Dim height As Double
  19.     Dim mode As Long
  20.     Dim prompt As String
  21.     Dim insertionPoint(0 To 2) As Double
  22.     Dim tag As String
  23.     Dim value As String
  24.     ' Define the attribute definition
  25.     height = 1#
  26.     mode = acAttributeModeVerify
  27.     prompt = "New Prompt"
  28.     insertionPoint(0) = 5#: insertionPoint(1) = 5#: insertionPoint(2) = 0
  29.     tag = "New Tag"
  30.     value = "New Value"
  31.     ' Create the attribute definition object in model space
  32.     Set attributeObj = blockObj.AddAttribute(height, mode, prompt, insertionPoint, tag, value)
  33.     ' Insert the block
  34.     Dim i As Long
  35.     i = 0&
  36.     Dim scaX As Double
  37.     Dim scaY As Double
  38.     Dim scaZ As Double
  39.     scaX = 1#
  40.     scaY = 1#
  41.     scaZ = 1#
  42.     Dim strname As String
  43.     Dim strname1 As String
  44.     Dim blockRefObj As AcadBlockReference
  45.     For i = 1& To 10&
  46.     scaX = scaX + i
  47.     scaY = scaY + i
  48.     scaZ = scaZ + i
  49.     strname1 = Format(i, "")
  50.     strname = "*u"
  51.     MsgBox strname1
  52.     strname = strname + strname1
  53.     MsgBox strname
  54.     insertionPnt(0) = 2# + i
  55.     insertionPnt(1) = 2# + i
  56.     insertionPnt(2) = 0#
  57.     Set blockRefObj = ThisDrawing.ModelSpace.InsertBlock(insertionPnt, strname, scaX, scaY, scaZ, 0)
  58.     Next i
  59.     ZoomAll
  60. End Sub

发表于 2006-3-23 13:39:00 | 显示全部楼层
strname = "*u"
改为
strname = blockObj.name
 楼主| 发表于 2006-3-23 22:04:00 | 显示全部楼层

版主你好,我的本意是要创建从*U1至*U10的不同的无名块,像INTECAD中的材料明细表一样的。而本程序运行时每次只能(依次)创建一个无名块,然后出现“运行时错误‘2147418113(8000FFFF)’;方法‘Insertblock’作用于‘IAcadmodelspace’时失败”后退出。就是第一次运行时创建*U1后出错退出,第二次运行时创建*U1,*U2后退出,第三次创建*U1,*U2,*U3.....

发表于 2006-3-23 22:42:00 | 显示全部楼层

无名块要创建一次,插入一次

如果要创建从*U1至*U10的不同的无名块,就要创建10个块定义,*U后面的数字也不会由你来控制,要获取无名块的名字,只能用strname = blockObj.name 的形式调用

 楼主| 发表于 2006-3-24 21:53:00 | 显示全部楼层
谢谢版主,这下明白了.
您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2024-11-27 06:34 , Processed in 0.189118 second(s), 24 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表