明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 3856|回复: 10

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

  [复制链接]
发表于 2006-8-2 13:31:00 | 显示全部楼层 |阅读模式

Sub block()
Dim Po() As Double
Dim ss As AcadSelectionSet
Dim Bk As AcadBlock

On Error Resume Next

Po(0) = 0
Po(1) = 0
Po(2) = 0

'ThisDrawing.Blocks.Item("ok").Delete

Set Bk = ThisDrawing.Blocks.Add(Po, "tempb")

Set ss = ThisDrawing.SelectionSets.Item("ssss")
'------------------------------------------------
If Err Then
Err.Clear
Set ss = ThisDrawing.SelectionSets.Add("ssss")
End If
'------------------------------------------------
ss.Select acSelectionSetAll
'------------------------------------------------过滤对象
Dim retVal() As AcadEntity
Dim Ent As AcadEntity


Dim i As Integer
i = 0

    ReDim retVal(0 To ss.Count - 1)
   
    For Each Ent In ss
       
        If (Ent.Layer = "layer") Then
            Set retVal(i) = Ent
            Ent.Delete
            i = i + 1
        End If
       
    Next
    ReDim Preserve retVal(0 To i - 1)

'------------------------------------------------
MsgBox "shiti" & ss.Count
ThisDrawing.CopyObjects retVal(), Bk  '  在这里出问题了
MsgBox "bk" & Bk.Count
ThisDrawing.ModelSpace.InsertBlock Po, "tempb", 1, 1, 1, 90
ss.Delete
MsgBox "end"
End Sub

 楼主| 发表于 2006-8-2 14:40:00 | 显示全部楼层

版主快回答我呀,我急死了

发表于 2006-8-2 16:47:00 | 显示全部楼层
    For Each Ent In ss
       
        If (Ent.Layer = "layer") Then
            Set retVal(i) = Ent
            Ent.Delete
            i = i + 1
        End If
       
    Next
Ent.Delete有问题。你都把Ent给删除了,怎么拷贝到块里去?
发表于 2006-8-2 21:32:00 | 显示全部楼层
  1. Sub tt()
  2. On Error Resume Next
  3.     Dim objs() As AcadEntity
  4.     Dim ss As AcadSelectionSet
  5.     ThisDrawing.SelectionSets("Test").Delete
  6.     Set ss = ThisDrawing.SelectionSets.Add("Test")
  7.    
  8.     Dim ft(0) As Integer, fd(0)
  9.     ft(0) = 8: fd(0) = "layer"
  10.     ss.Select acSelectionSetAll, , , ft, fd
  11.    
  12.     ReDim objs(ss.Count - 1)
  13.     Dim i
  14.     For i = 0 To ss.Count - 1
  15.         Set objs(i) = ss(i)
  16.     Next i
  17.    
  18.     Dim blk As AcadBlock
  19.     Dim pnt(2) As Double
  20.     Set blk = ThisDrawing.Blocks.Add(pnt, "tempb")
  21.    
  22.     ThisDrawing.CopyObjects objs, blk
  23. End Sub

发表于 2006-8-3 12:44:00 | 显示全部楼层
Please make sure all objects to be copied are in the same space, ie, modelspace
Otherwise the CopyObjects method will fail.
 楼主| 发表于 2006-8-3 23:15:00 | 显示全部楼层

lzh741206老大,非常感谢,我照你的方法成功了,但我一直搞不懂我的程序错在那儿了,恳请指点!也希望能得到其他高手出招支持,但决不是霹雳啪啦啦说的ent.delete的问题

我现在想做个程序,就是在程序中创建若干个实体,比如建一个圆,然后创建个矩形,再画一条多义线(上述三项不在同一层),然后加入这三个到同一个块中.在modespace中插入这个块,并删除刚刚建的圆\矩形\多义线,只保留这个块.希望lzh741206版主给我帮助,谢谢了

 

 

 楼主| 发表于 2006-8-3 23:20:00 | 显示全部楼层
alin发表于2006-8-3 12:44:00Please 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.
发表于 2006-8-4 08:40:00 | 显示全部楼层

Sub block()
Dim Po(2) As Double
Dim ss As AcadSelectionSet
Dim Bk As AcadBlock

On Error Resume Next

Po(0) = 0
Po(1) = 0
Po(2) = 0

'ThisDrawing.Blocks.Item("ok").Delete

Set Bk = ThisDrawing.Blocks.Add(Po, "tempb")

Set ss = ThisDrawing.SelectionSets.Item("ssss")
'------------------------------------------------
If Err Then
Err.Clear
Set ss = ThisDrawing.SelectionSets.Add("ssss")
End If
'------------------------------------------------
ss.Select acSelectionSetAll
'------------------------------------------------????
Dim retVal() As AcadEntity
Dim Ent As AcadEntity


Dim i As Integer
i = 0

    ReDim retVal(ss.Count - 1)
   
    For Each Ent In ss
       
        If (Ent.Layer = "Layer") Then
            Set retVal(i) = Ent
'            Ent.Delete
            i = i + 1
        End If
       
    Next
    ReDim Preserve retVal(i - 1)

'------------------------------------------------
MsgBox "shiti" & ss.Count
ThisDrawing.CopyObjects retVal, Bk  '  ???????
MsgBox "bk" & Bk.Count
'ThisDrawing.ModelSpace.InsertBlock Po, "tempb", 1, 1, 1, 90
ss.Delete
MsgBox "end"
End Sub


 

 楼主| 发表于 2006-8-4 11:07:00 | 显示全部楼层
alin版大 ,仍然失败!
发表于 2006-8-4 16:11:00 | 显示全部楼层

怎样的“失败”?你的图中有在图层Layer上的图元吗?最好你把你的图贴上来。

您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2024-11-27 00:48 , Processed in 0.198018 second(s), 23 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表