yuliang2477 发表于 2009-12-15 16:36:00

[求助]插入图块问题

<p><strong>请高手帮忙,在CAD中已有图块,如何将已有图块加入到另一个图块中去?</strong></p><p>Dim obj_block As Object, obj_blockref As Object, obj_blockattribute As Object&nbsp;&nbsp;&nbsp;&nbsp; '块对象、块参照、块属性<br/>Dim InsertionPoint(0 To 2) As Double&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; '块的插入点<br/>Dim point1(0 To 2) As Double, point2(0 To 2) As Double '直线的两个端点<br/>Dim Height As Double<br/>Dim panduan As Boolean</p><p>Dim obj_Acad As Object, obj_Doc As Object, obj_ModelSpace As Object</p><p>Set obj_Acad = GetObject(, "autocad.application")</p><p>Set obj_Doc = obj_Acad.ActiveDocument<br/>Set obj_ModelSpace = obj_Doc.ModelSpace<br/>'下面建立1个块对象(newblock),在块中添加文字对象和直线对象</p><p>InsertionPoint(0) = 5: InsertionPoint(1) = 5: InsertionPoint(2) = 0</p><p>panduan = False<br/>For i = 0 To obj_Doc.blocks.Count - 1 '遍历所有的块<br/>&nbsp;&nbsp;&nbsp; If obj_Doc.blocks.Item(i).Name = "newblock" Then<br/>&nbsp;&nbsp;&nbsp;&nbsp; Set obj_block = obj_Doc.blocks.Item("newblock")<br/>&nbsp;&nbsp;&nbsp;&nbsp; panduan = True</p><p>&nbsp;&nbsp;&nbsp;&nbsp; Exit For&nbsp;&nbsp;&nbsp;&nbsp;<br/>&nbsp;&nbsp;&nbsp;&nbsp; End If<br/>&nbsp;&nbsp; Next i<br/>If Not panduan Then&nbsp;&nbsp;&nbsp;&nbsp; '如果块不存在,建立块<br/>&nbsp;Set obj_block = obj_Doc.blocks.Add(InsertionPoint, "newblock")<br/>&nbsp;End If</p><p><strong>===想在此处加入图中已有的图块(图块名为“123”)请高手帮忙====</strong></p><p><br/>obj_Doc.ActiveTextStyle.SetFont "宋体", False, False, 1, 0&nbsp; '设置文字字体为"宋体"<br/>Set obj_Text = obj_block.AddText("1.25", InsertionPoint, 0.5) '在块newblock中添加文字对象<br/>point1(0) = 3#: point1(1) = 5#: point1(2) = 0#<br/>point2(0) = 5: point2(1) = 5: point2(2) = 0#<br/>obj_block.Addline point1, point2&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; '在块"newblock"中添加直线对象<br/>obj_Acad.zoomextents<br/></p>

poly168 发表于 2009-12-16 14:07:00

<p>Dim obj_block As Object, obj_blockref As Object, obj_blockattribute As Object&nbsp;&nbsp;&nbsp;&nbsp; '块对象、块参照、块属性<br/>Dim InsertionPoint(0 To 2) As Double&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; '块的插入点<br/>Dim point1(0 To 2) As Double, point2(0 To 2) As Double '直线的两个端点<br/>Dim Height As Double<br/>Dim panduan As Boolean</p><p>Dim obj_Acad As Object, obj_Doc As Object, obj_ModelSpace As Object</p><p>Set obj_Acad = GetObject(, "autocad.application")</p><p>Set obj_Doc = obj_Acad.ActiveDocument<br/>Set obj_ModelSpace = obj_Doc.ModelSpace<br/>'下面建立1个块对象(newblock),在块中添加文字对象和直线对象</p><p>InsertionPoint(0) = 5: InsertionPoint(1) = 5: InsertionPoint(2) = 0</p><p>panduan = False<br/>For i = 0 To obj_Doc.blocks.Count - 1 '遍历所有的块<br/>&nbsp;&nbsp;&nbsp; If obj_Doc.blocks.Item(i).Name = "newblock" Then<br/>&nbsp;&nbsp;&nbsp;&nbsp; Set obj_block = obj_Doc.blocks.Item("newblock")<br/>&nbsp;&nbsp;&nbsp;&nbsp; panduan = True</p><p>&nbsp;&nbsp;&nbsp;&nbsp; Exit For&nbsp;&nbsp;&nbsp;&nbsp;<br/>&nbsp;&nbsp;&nbsp;&nbsp; End If<br/>&nbsp;&nbsp; Next i<br/>If Not panduan Then&nbsp;&nbsp;&nbsp;&nbsp; '如果块不存在,建立块<br/>&nbsp;Set obj_block = obj_Doc.blocks.Add(InsertionPoint, "newblock")</p><p>Set newblock&nbsp; = newblockj.AddPoint(insertionPoitnt) '在块中定义一个点</p><p>Set obj_block&nbsp; = newblock.addline(p1(),p2())</p><p>height = 1: mode = acAttributeModeNormal<br/>prompt = "0": tag = "文字"<br/>Set attributeObj = obj_block&nbsp; j.AddAttribute(height, mode, prompt, insertionPoint, tag, &nbsp;"123.455")'在块中加入文字注记</p><p><br/>&nbsp;End If</p><p>'以上块定义完毕,块定义中有一个点一条直线一个附加属性</p><p>&nbsp;Dim mm As AcadBlockReference</p><p>Set mm = ThisDrawing.ModelSpace.InsertBlock(newblock, "图层123t",&nbsp; d, d, d, 0)</p><p>'以上创建块实体</p>
页: [1]
查看完整版本: [求助]插入图块问题