qsl707 发表于 2006-8-2 13:31:00

实体加入到块中,怎么用CopyObjects 的方法copy不到块去

<P>Sub block()<BR>Dim Po() As Double<BR>Dim ss As AcadSelectionSet<BR>Dim Bk As AcadBlock</P>
<P>On Error Resume Next</P>
<P>Po(0) = 0<BR>Po(1) = 0<BR>Po(2) = 0</P>
<P>'ThisDrawing.Blocks.Item("ok").Delete</P>
<P>Set Bk = ThisDrawing.Blocks.Add(Po, "tempb")</P>
<P>Set ss = ThisDrawing.SelectionSets.Item("ssss")<BR>'------------------------------------------------<BR>If Err Then<BR>Err.Clear<BR>Set ss = ThisDrawing.SelectionSets.Add("ssss")<BR>End If<BR>'------------------------------------------------<BR>ss.Select acSelectionSetAll<BR>'------------------------------------------------过滤对象<BR>Dim retVal() As AcadEntity<BR>Dim Ent As AcadEntity</P>
<P><BR>Dim i As Integer<BR>i = 0</P>
<P>&nbsp;&nbsp;&nbsp; ReDim retVal(0 To ss.Count - 1)<BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; For Each Ent In ss<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; If (Ent.Layer = "layer") Then<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Set retVal(i) = Ent<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Ent.Delete<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; i = i + 1<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; End If<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; Next<BR>&nbsp;&nbsp;&nbsp; ReDim Preserve retVal(0 To i - 1) </P>
<P>'------------------------------------------------<BR>MsgBox "shiti" &amp; ss.Count<BR>ThisDrawing.CopyObjects retVal(), Bk&nbsp; '&nbsp; 在这里出问题了<BR>MsgBox "bk" &amp; Bk.Count<BR>ThisDrawing.ModelSpace.InsertBlock Po, "tempb", 1, 1, 1, 90<BR>ss.Delete<BR>MsgBox "end"<BR>End Sub<BR></P>

qsl707 发表于 2006-8-2 14:40:00

<P>版主快回答我呀,我急死了</P>

霹雳啪啦啦 发表于 2006-8-2 16:47:00

&nbsp;&nbsp;&nbsp; For Each Ent In ss<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; If (Ent.Layer = "layer") Then<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Set retVal(i) = Ent<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Ent.Delete<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; i = i + 1<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; End If<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; Next<BR>Ent.Delete有问题。你都把Ent给删除了,怎么拷贝到块里去?

雪山飞狐_lzh 发表于 2006-8-2 21:32:00

Sub tt()
On Error Resume Next
    Dim objs() As AcadEntity
    Dim ss As AcadSelectionSet
    ThisDrawing.SelectionSets("Test").Delete
    Set ss = ThisDrawing.SelectionSets.Add("Test")
   
    Dim ft(0) As Integer, fd(0)
    ft(0) = 8: fd(0) = "layer"
    ss.Select acSelectionSetAll, , , ft, fd
   
    ReDim objs(ss.Count - 1)
    Dim i
    For i = 0 To ss.Count - 1
      Set objs(i) = ss(i)
    Next i
   
    Dim blk As AcadBlock
    Dim pnt(2) As Double
    Set blk = ThisDrawing.Blocks.Add(pnt, "tempb")
   
    ThisDrawing.CopyObjects objs, blk
End Sub

alin 发表于 2006-8-3 12:44:00

Please make sure all objects to be copied are in the same space, ie, modelspace<BR>Otherwise the CopyObjects method will fail.

qsl707 发表于 2006-8-3 23:15:00

<P><A name=26396><FONT color=#990000><B>lzh741206</B></FONT></A>老大,非常感谢,我照你的方法成功了,但我一直搞不懂我的程序错在那儿了,恳请指点!也希望能得到其他高手出招支持,但决不是<A name=26357><FONT color=#000066><B>霹雳啪啦啦</B></FONT></A>说的ent.delete的问题</P>
<P>我现在想做个程序,就是在程序中创建若干个实体,比如建一个圆,然后创建个矩形,再画一条多义线(上述三项不在同一层),然后加入这三个到同一个块中.在modespace中插入这个块,并删除刚刚建的圆\矩形\多义线,只保留这个块.希望<A name=26396><FONT color=#990000><B>lzh741206</B></FONT></A>版主给我帮助,谢谢了</P>
<P>&nbsp;</P>
<P>&nbsp;</P>

qsl707 发表于 2006-8-3 23:20:00

alin发表于2006-8-3 12:44:00static/image/common/back.gifPlease make sure all objects to be copied are in the same space, ie, modelspaceOtherwise the CopyObjects method will fail.

Dear alin,thank you!Iam sure all my objects are copied in the same space(modelspace),why failure always keep up with me.<BR>

alin 发表于 2006-8-4 08:40:00

<P>Sub block()<BR>Dim Po(2) As Double<BR>Dim ss As AcadSelectionSet<BR>Dim Bk As AcadBlock</P>
<P>On Error Resume Next</P>
<P>Po(0) = 0<BR>Po(1) = 0<BR>Po(2) = 0</P>
<P>'ThisDrawing.Blocks.Item("ok").Delete</P>
<P>Set Bk = ThisDrawing.Blocks.Add(Po, "tempb")</P>
<P>Set ss = ThisDrawing.SelectionSets.Item("ssss")<BR>'------------------------------------------------<BR>If Err Then<BR>Err.Clear<BR>Set ss = ThisDrawing.SelectionSets.Add("ssss")<BR>End If<BR>'------------------------------------------------<BR>ss.Select acSelectionSetAll<BR>'------------------------------------------------????<BR>Dim retVal() As AcadEntity<BR>Dim Ent As AcadEntity</P>
<P><BR>Dim i As Integer<BR>i = 0</P>
<P>&nbsp;&nbsp;&nbsp; ReDim retVal(ss.Count - 1)<BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; For Each Ent In ss<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; If (Ent.Layer = "Layer") Then<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Set retVal(i) = Ent<BR>'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Ent.Delete<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; i = i + 1<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; End If<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; Next<BR>&nbsp;&nbsp;&nbsp; ReDim Preserve retVal(i - 1)</P>
<P>'------------------------------------------------<BR>MsgBox "shiti" &amp; ss.Count<BR>ThisDrawing.CopyObjects retVal, Bk&nbsp; '&nbsp; ???????<BR>MsgBox "bk" &amp; Bk.Count<BR>'ThisDrawing.ModelSpace.InsertBlock Po, "tempb", 1, 1, 1, 90<BR>ss.Delete<BR>MsgBox "end"<BR>End Sub</P>
<P><BR>&nbsp;</P>

qsl707 发表于 2006-8-4 11:07:00

alin版大 ,仍然失败!

alin 发表于 2006-8-4 16:11:00

<P>怎样的“失败”?你的图中有在图层Layer上的图元吗?最好你把你的图贴上来。</P>
页: [1] 2
查看完整版本: 实体加入到块中,怎么用CopyObjects 的方法copy不到块去