求助,无名块插入的程序,错在哪?
无名块插入的程序,错在哪?Sub Example_InsertBlock()
' This example creates a block containing a circle.
' It then inserts the block
' Create the block
Dim blockObj As AcadBlock
Dim insertionPnt(0 To 2) As Double
insertionPnt(0) = 0#: insertionPnt(1) = 0#: insertionPnt(2) = 0#
Set blockObj = ThisDrawing.Blocks.Add(insertionPnt, "*u")
' Add a circle to the block
Dim circleObj As AcadCircle
Dim center(0 To 2) As Double
Dim radius As Double
center(0) = 0: center(1) = 0: center(2) = 0
radius = 1
Set circleObj = blockObj.AddCircle(center, radius)
' This example creates an attribute definition in model space.
Dim attributeObj As AcadAttribute
Dim height As Double
Dim mode As Long
Dim prompt As String
Dim insertionPoint(0 To 2) As Double
Dim tag As String
Dim value As String
' Define the attribute definition
height = 1#
mode = acAttributeModeVerify
prompt = "New Prompt"
insertionPoint(0) = 5#: insertionPoint(1) = 5#: insertionPoint(2) = 0
tag = "New Tag"
value = "New Value"
' Create the attribute definition object in model space
Set attributeObj = blockObj.AddAttribute(height, mode, prompt, insertionPoint, tag, value)
' Insert the block
Dim i As Long
i = 0&
Dim scaX As Double
Dim scaY As Double
Dim scaZ As Double
scaX = 1#
scaY = 1#
scaZ = 1#
Dim strname As String
Dim strname1 As String
Dim blockRefObj As AcadBlockReference
For i = 1& To 10&
scaX = scaX + i
scaY = scaY + i
scaZ = scaZ + i
strname1 = Format(i, "")
strname = "*u"
MsgBox strname1
strname = strname + strname1
MsgBox strname
insertionPnt(0) = 2# + i
insertionPnt(1) = 2# + i
insertionPnt(2) = 0#
Set blockRefObj = ThisDrawing.ModelSpace.InsertBlock(insertionPnt, strname, scaX, scaY, scaZ, 0)
Next i
ZoomAll
End Sub
strname = "*u"<BR>改为<BR>strname = blockObj.name <P>版主你好,我的本意是要创建从*U1至*U10的不同的无名块,像INTECAD中的材料明细表一样的。而本程序运行时每次只能(依次)创建一个无名块,然后出现“运行时错误‘2147418113(8000FFFF)’;方法‘Insertblock’作用于‘IAcadmodelspace’时失败”后退出。就是第一次运行时创建*U1后出错退出,第二次运行时创建*U1,*U2后退出,第三次创建*U1,*U2,*U3.....</P> <P>无名块要创建一次,插入一次</P>
<P>如果要创建从*U1至*U10的不同的无名块,就要创建10个块定义,*U后面的数字也不会由你来控制,要获取无名块的名字,只能用strname = blockObj.name 的形式调用</P> 谢谢版主,这下明白了.
页:
[1]