wuliang226 发表于 2007-6-20 22:18:00

DWG文件插入到DWG文件中的VBA问题

<p>请问我如何在CAD中通过VBA将一个个文件插入到一个已经打开的文件中并另存呢??我用INSERTBLOCK方法好像不行。比如下面代码:</p><p>Sub insertmoban()<br/>Dim pathname As String<br/>Dim pointbase(0 To 2) As Double</p><p><br/>pointbase(0) = 0<br/>pointbase(1) = 0<br/>pointbase(2) = 0<br/>pathname = "C:\Program Files\AutoCAD 2002\Support\塔基模板.dwg"</p><p>Dim insertedBlock&nbsp; As AcadBlockReference<br/>ThisDrawing.Application.Documents.Open pathname<br/>Set insertedBlock = ThisDrawing.ModelSpace.InsertBlock(pointbase, "C:\Documents and Settings\Administrator\桌面\试验\1.dwg", 1#, 1#, 1#, 0)<br/>&nbsp;End Sub<br/></p><p></p><p></p>

lsyinjiang 发表于 2007-6-24 23:08:00

我也很想学习一下,<br/>顶上去<br/>

johansen 发表于 2007-6-26 11:02:00

<p>我的也是这样的情况,运行后什么都看不见,我有点怀疑是不是插入图形中有些字体需要代替的原因所以导致动作中断,。x</p><p>希望有高手可以帮帮忙</p>

johansen 发表于 2007-6-26 11:20:00

<p>兄弟,把你的代码改成以下看看,我的成功了,一个小错误。!</p><p>Dim inPoint(0 To 2) As Double&nbsp;&nbsp;<br/>&nbsp;&nbsp;&nbsp; Dim sca As Double&nbsp;&nbsp;&nbsp;<br/>&nbsp;&nbsp;&nbsp; Dim ro As Double&nbsp;&nbsp;&nbsp;&nbsp;<br/>&nbsp;&nbsp;&nbsp; Dim bName As String&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br/>&nbsp;&nbsp;&nbsp; Dim blockObj As AcadBlockReference<br/>&nbsp;&nbsp;&nbsp; bName = "文件路径"<br/>&nbsp;&nbsp;&nbsp; inPoint(0) =&nbsp;0#<br/>&nbsp;&nbsp;&nbsp; inPoint(1) =&nbsp;0#<br/>&nbsp;&nbsp;&nbsp; inPoint(2) = 0#<br/>&nbsp;&nbsp;&nbsp; sca = 1#<br/>&nbsp;&nbsp;&nbsp; ro = 0<br/>&nbsp;&nbsp;&nbsp; <br/>&nbsp;&nbsp;&nbsp; On Error Resume Next<br/>&nbsp;&nbsp;&nbsp; <br/>&nbsp;&nbsp;&nbsp; Set blockObj = ThisDrawing.ModelSpace.InsertBlock(inPoint, bName, sca, sca, sca, ro)<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br/>Unload Me<br/><br/>End Sub</p><p>这是插入一个外部图形到已打开的图形中...</p>

wuliang226 发表于 2007-7-1 18:52:00

<p>我试了还是不行,命令行总是出现:块 1 参照本身,不知何故望高手赐教!谢谢。</p><p>Public Sub HH()<br/>&nbsp;&nbsp;&nbsp; Dim inPoint(0 To 2) As Double<br/>&nbsp;&nbsp;&nbsp; Dim sca As Double<br/>&nbsp;&nbsp;&nbsp; Dim ro As Double<br/>&nbsp;&nbsp;&nbsp; Dim bName As String<br/>&nbsp;&nbsp;&nbsp; Dim blockObj As AcadBlockReference<br/>&nbsp;&nbsp;&nbsp; bName = "C:\Documents and Settings\Administrator\桌面\试验\1.DWG"<br/>&nbsp;&nbsp;&nbsp; inPoint(0) = 0#<br/>&nbsp;&nbsp;&nbsp; inPoint(1) = 0#<br/>&nbsp;&nbsp;&nbsp; inPoint(2) = 0#<br/>&nbsp;&nbsp;&nbsp; sca = 1#<br/>&nbsp;&nbsp;&nbsp; ro = 0<br/>&nbsp;&nbsp;&nbsp; <br/>&nbsp;&nbsp;&nbsp; On Error Resume Next<br/>&nbsp;&nbsp;&nbsp; <br/>&nbsp;&nbsp;&nbsp; Set blockObj = ThisDrawing.ModelSpace.InsertBlock(inPoint, bName, sca, sca, sca, ro)<br/>End Sub</p><p><br/></p>

清风明月名字 发表于 2012-5-5 15:02:08

我试了,4楼的代码可以啊。

inPoint(0) = 0#
    inPoint(1) = 0#
    inPoint(2) = 0#
    sca = 1#
这其中的“#”我删除了,
页: [1]
查看完整版本: DWG文件插入到DWG文件中的VBA问题