lusakura 发表于 2009-3-24 17:28:00

为什么这段程序会报未找到主键?

<p>我想找到一个BlockReference 然后更改它的NAME ,可到了最后一句总报未找到主键,魏森么呢?</p><p>Dim InsPoint(0 To 2) As Double<br/>Dim NewEnt As AcadBlockReference<br/>For Each Ent In ThisDrawing.ModelSpace<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; If Ent.ObjectName = "AcDbBlockReference" Then<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Select Case Ent.Name 'EffectiveName<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Case "Motor_Cable"<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Set NewEnt = Ent.Copy<br/>&nbsp;<br/>&nbsp;&nbsp;&nbsp; Dim point1(0 To 2) As Double<br/>&nbsp;&nbsp;&nbsp; point1(0) = 2: point1(1) = 1: point1(2) = 0</p><p>&nbsp;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; NewEnt.InsertionPoint = point1<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; End Select<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; End If<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Next</p><p>NewEnt.Name = "MotorAAA"&nbsp; '这里报错</p><p>End Sub<br/>谢谢!!</p>

lusakura 发表于 2009-3-25 09:36:00

<p>顶一下 期待回答 </p>

zzyong00 发表于 2009-3-25 15:45:00

<p>貌似思路不对,建新块,只能用blocks.add方法</p><p></p>

lusakura 发表于 2009-3-26 09:41:00

<p>建新块也行,怎么能建一个新的把以前的那个所有信息都拷贝过来呢?&nbsp; 这些块只有编号不一样 图形什么的都一样啊</p>

sailorcwx 发表于 2009-3-26 14:00:00

<p>你修改的应该是AcadBlock的name,AcadBlockReference的name是只读的</p><p>ThisDrawing.Blocks.Item(NewEnt.Name).Name = "MotorAAA" </p>

sailorcwx 发表于 2009-3-26 14:03:00

<p class="body">BlockRef: A block reference can be assigned the name of only a valid block definition in the drawing. Assigning a block reference a unique name will not automatically create a new block definition. To create a new block definition, use the <a href="mk:@MSITStore:C:\Program%20Files\AutoCAD%202008\help\acadauto.chm::/idh_add.htm">Add</a> method to add a new Block object to the Blocks collection. </p>

lusakura 发表于 2009-3-26 15:47:00

测试成功 太感谢了!!!!!!!!!!!!!!!
页: [1]
查看完整版本: 为什么这段程序会报未找到主键?