idoo 发表于 2006-8-14 21:11:00

飞狐版主请进+《AutoCAD VBA开发精彩实例教程》问题

本帖最后由 作者 于 2006-8-20 18:30:21 编辑 <br /><br /> <P>在《AutoCAD VBA开发精彩实例教程》2004年1月第一版中,第3.8节的程序在执行时为什么总是提示“不支持的对象库功能”??焦点锁定在</P>
<P>If Not IsNull(ThisDrawing.SelectionSets.item("this")) Then<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Set SSet = ThisDrawing.SelectionSets.item("this")<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; SSet.Delete<BR>&nbsp;&nbsp;&nbsp; End If</P>
<P>的SSet=上,该如何解决?</P>

idoo 发表于 2006-8-15 19:04:00

<P>不会大家都用不到这个吧??</P>

chenfeng22 发表于 2006-8-15 19:47:00

<P>少了定义了吧</P>
<P>dim SSet as&nbsp;SelectionSets</P>

idoo 发表于 2006-8-15 20:59:00

<P>是的,应该是定义为SelectionSets,源程序定义成了SelectionSet,以及第66行,也应该为Dim objUcs As AcadUCSs,源程序错误成Dim objUcs As AcadUCS。可是第89行开始:</P>
<P>Dim blkRef As AcadBlockReference<BR>&nbsp;&nbsp;&nbsp; Dim element As AcadEntity<BR>&nbsp;&nbsp;&nbsp; Set element = ThisDrawing.ModelSpace.item(ThisDrawing.ModelSpace.Count - 1)<BR>&nbsp;&nbsp;&nbsp; If TypeOf element Is AcadBlockReference Then<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Set blkRef = element<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; blkRef.Explode<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; blkRef.Delete<BR>&nbsp;&nbsp;&nbsp; End If</P>
<P>又有问题,提示不支持的对象库功能,焦点锁定在blkRef =上,请问哪里还有问题啊~~</P>

idoo 发表于 2006-8-15 21:22:00

<P>将AcadBlockReference更改为AcadBlock,能够运行,可是得不到结果……</P>

idoo 发表于 2006-8-15 21:24:00

<P>这里是所有的代码,能不能帮我看看。</P>
<P>Option Explicit</P>
<P>Sub ExplodeText()<BR>&nbsp;&nbsp;&nbsp; '输出WMF文件*****************************************<BR>&nbsp;&nbsp;&nbsp; '选择文字<BR>&nbsp;&nbsp;&nbsp; Dim objText As AcadText<BR>&nbsp;&nbsp;&nbsp; Dim objMtext As AcadMText<BR>&nbsp;&nbsp;&nbsp; Dim ptMin, ptMax&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; '文字限制框的角点<BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; Dim objEnt As AcadEntity<BR>&nbsp;&nbsp;&nbsp; Dim pt As Variant<BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; On Error Resume Next<BR>Retry:<BR>&nbsp;&nbsp;&nbsp; ThisDrawing.Utility.GetEntity objEnt, pt, "选择要分解的文字:"<BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; If Err &lt;&gt; 0 Then&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; '错误处理<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Err.Clear<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; GoTo Retry<BR>&nbsp;&nbsp;&nbsp; End If<BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; '获得文字的限制框角点<BR>&nbsp;&nbsp;&nbsp; If objEnt.ObjectName = "AcDbText" Then<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Set objText = objEnt<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; objText.GetBoundingBox ptMin, ptMax<BR>&nbsp;&nbsp;&nbsp; ElseIf objEnt.ObjectName = "AcDbMtext" Then<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Set objMtext = objEnt<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; objMtext.GetBoundingBox ptMin, ptMax<BR>&nbsp;&nbsp;&nbsp; Else<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; MsgBox "所选择的实体不是文字或者多行文字对象!", vbCritical<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Exit Sub<BR>&nbsp;&nbsp;&nbsp; End If<BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; '为了提高分辨率,保证对象完全在当前视口中,进行缩放操作<BR>&nbsp;&nbsp;&nbsp; ZoomWindow ptMin, ptMax<BR>&nbsp;&nbsp;&nbsp; 'ZoomScaled 0.9, acZoomScaledRelative<BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; '创建选择集<BR>&nbsp;&nbsp;&nbsp; Dim SSet As AcadSelectionSets<BR>&nbsp;&nbsp;&nbsp; If Not IsNull(ThisDrawing.SelectionSets.item("this")) Then<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Set SSet = ThisDrawing.SelectionSets.item("this")<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; SSet.Delete<BR>&nbsp;&nbsp;&nbsp; End If<BR>&nbsp;&nbsp;&nbsp; Set SSet = ThisDrawing.SelectionSets.Add("this")<BR>&nbsp;&nbsp;&nbsp; Dim item(0) As AcadEntity<BR>&nbsp;&nbsp;&nbsp; Set item(0) = objEnt<BR>&nbsp;&nbsp;&nbsp; SSet.AddItems item<BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; '输出WMF文件<BR>&nbsp;&nbsp;&nbsp; ThisDrawing.Export "C:\temp", "WMF", SSet<BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; '输入WMF文件*****************************************<BR>&nbsp;&nbsp;&nbsp; '当前视口的高宽<BR>&nbsp;&nbsp;&nbsp; Dim height As Double, width As Double&nbsp;&nbsp; '当前图形窗口的宽、高<BR>&nbsp;&nbsp;&nbsp; height = ThisDrawing.GetVariable("ViewSize")&nbsp;&nbsp;&nbsp; '返回当前视口的高度(图形单位)<BR>&nbsp;&nbsp;&nbsp; Dim dblScale As Variant&nbsp;&nbsp;&nbsp;&nbsp; '高宽比例<BR>&nbsp;&nbsp;&nbsp; dblScale = ThisDrawing.GetVariable("ScreenSize")&nbsp;&nbsp;&nbsp; '该系统变量返回当前视口的像素单位(x和y值)<BR>&nbsp;&nbsp;&nbsp; width = (dblScale(0) / dblScale(1)) * height<BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; '视图中心点的绝对坐标<BR>&nbsp;&nbsp;&nbsp; Dim ptCen, ptTemp<BR>&nbsp;&nbsp;&nbsp; Dim ucsName As String<BR>&nbsp;&nbsp;&nbsp; ucsName = ThisDrawing.GetVariable("UCSNAME")&nbsp;&nbsp;&nbsp; '该系统变量返回当前UCS的名称<BR>&nbsp;&nbsp;&nbsp; If ucsName &lt;&gt; "" Then<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dim objUcs As AcadUCSs<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Set objUcs = ThisDrawing.ActiveUCS<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ptTemp = ThisDrawing.GetVariable("viewctr")&nbsp;&nbsp;&nbsp;&nbsp; '返回当前视口的中心点(UCS坐标)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ptCen = ThisDrawing.Utility.TranslateCoordinates(ptTemp, acUCS, acWorld, False)<BR>&nbsp;&nbsp;&nbsp; ElseIf ucsName = "" Then<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ptCen = ThisDrawing.GetVariable("viewctr")<BR>&nbsp;&nbsp;&nbsp; End If<BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; '视图左上角点的坐标(即WMF图形插入的基点)<BR>&nbsp;&nbsp;&nbsp; Dim ptBase(0 To 2) As Double<BR>&nbsp;&nbsp;&nbsp; ptBase(0) = ptCen(0) - width / 2: ptBase(1) = ptCen(1) + height / 2: ptCen(2) = 0<BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; '输入文件<BR>&nbsp;&nbsp;&nbsp; If Dir("C:\temp.wmf") &lt;&gt; "" Then&nbsp;&nbsp;&nbsp; '判断文件是否存在<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ThisDrawing.Import "C:\temp.wmf", ptBase, 2<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Kill ("c:\temp.wmf")&nbsp;&nbsp;&nbsp; '删除临时文件<BR>&nbsp;&nbsp;&nbsp; Else<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; MsgBox "程序使用的临时文件不存在,请重新运行程序!", vbCritical<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Exit Sub<BR>&nbsp;&nbsp;&nbsp; End If<BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; '分解得到的块参照************************************<BR>&nbsp;&nbsp;&nbsp; Dim blkRef As AcadBlockReference<BR>&nbsp;&nbsp;&nbsp; Dim element As AcadEntity<BR>&nbsp;&nbsp;&nbsp; Set element = ThisDrawing.ModelSpace.item(ThisDrawing.ModelSpace.Count - 1)<BR>&nbsp;&nbsp;&nbsp; If TypeOf element Is AcadBlockReference Then<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Set blkRef = element<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; blkRef.Explode<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; blkRef.Delete<BR>&nbsp;&nbsp;&nbsp; End If<BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; objEnt.Delete&nbsp;&nbsp; '删除原来的文字对象<BR>&nbsp;&nbsp;&nbsp; SSet.Delete<BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; '缩放图形,返回原来的视图<BR>&nbsp;&nbsp;&nbsp; ZoomPrevious<BR>&nbsp;&nbsp;&nbsp; 'ZoomPrevious<BR>End Sub<BR></P>

idoo 发表于 2006-8-19 12:11:00

有没有用过啊???

雪山飞狐_lzh 发表于 2006-8-19 13:26:00

Sub ExplodeText()<BR>&nbsp;&nbsp;&nbsp; '输出WMF文件*****************************************<BR>&nbsp;&nbsp;&nbsp; '选择文字<BR>&nbsp;&nbsp;&nbsp; Dim objText As AcadText<BR>&nbsp;&nbsp;&nbsp; Dim objMtext As AcadMText<BR>&nbsp;&nbsp;&nbsp; Dim ptMin, ptMax&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; '文字限制框的角点<BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; Dim objEnt As AcadEntity<BR>&nbsp;&nbsp;&nbsp; Dim pt As Variant<BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; On Error Resume Next<BR>Retry:<BR>&nbsp;&nbsp;&nbsp; ThisDrawing.Utility.GetEntity objEnt, pt, "选择要分解的文字:"<BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; If Err &lt;&gt; 0 Then&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; '错误处理<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Err.Clear<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Exit Sub<BR>&nbsp;&nbsp;&nbsp; End If<BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; '获得文字的限制框角点<BR>&nbsp;&nbsp;&nbsp; If objEnt.ObjectName = "AcDbText" Then<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Set objText = objEnt<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; objText.GetBoundingBox ptMin, ptMax<BR>&nbsp;&nbsp;&nbsp; ElseIf objEnt.ObjectName = "AcDbMtext" Then<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Set objMtext = objEnt<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; objMtext.GetBoundingBox ptMin, ptMax<BR>&nbsp;&nbsp;&nbsp; Else<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; MsgBox "所选择的实体不是文字或者多行文字对象!", vbCritical<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Exit Sub<BR>&nbsp;&nbsp;&nbsp; End If<BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; '为了提高分辨率,保证对象完全在当前视口中,进行缩放操作<BR>&nbsp;&nbsp;&nbsp; ZoomWindow ptMin, ptMax<BR>&nbsp;&nbsp;&nbsp; 'ZoomScaled 0.9, acZoomScaledRelative<BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; '创建选择集<BR>&nbsp;&nbsp;&nbsp; Dim SSet As AcadSelectionSet<BR>&nbsp;&nbsp;&nbsp; ThisDrawing.SelectionSets.item("this").Delete<BR>&nbsp;&nbsp;&nbsp; Set SSet = ThisDrawing.SelectionSets.Add("this")<BR>&nbsp;&nbsp;&nbsp; Dim item(0) As AcadEntity<BR>&nbsp;&nbsp;&nbsp; Set item(0) = objEnt<BR>&nbsp;&nbsp;&nbsp; SSet.AddItems item<BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; '输出WMF文件<BR>&nbsp;&nbsp;&nbsp; ThisDrawing.Export "d:\temp", "WMF", SSet<BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; '输入WMF文件*****************************************<BR>&nbsp;&nbsp;&nbsp; '当前视口的高宽<BR>&nbsp;&nbsp;&nbsp; Dim height As Double, width As Double&nbsp;&nbsp; '当前图形窗口的宽、高<BR>&nbsp;&nbsp;&nbsp; height = ThisDrawing.GetVariable("ViewSize")&nbsp;&nbsp;&nbsp; '返回当前视口的高度(图形单位)<BR>&nbsp;&nbsp;&nbsp; Dim dblScale As Variant&nbsp;&nbsp;&nbsp;&nbsp; '高宽比例<BR>&nbsp;&nbsp;&nbsp; dblScale = ThisDrawing.GetVariable("ScreenSize")&nbsp;&nbsp;&nbsp; '该系统变量返回当前视口的像素单位(x和y值)<BR>&nbsp;&nbsp;&nbsp; width = (dblScale(0) / dblScale(1)) * height<BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; '视图中心点的绝对坐标<BR>&nbsp;&nbsp;&nbsp; Dim ptCen, ptTemp<BR>&nbsp;&nbsp;&nbsp; Dim ucsName As String<BR>&nbsp;&nbsp;&nbsp; ucsName = ThisDrawing.GetVariable("UCSNAME")&nbsp;&nbsp;&nbsp; '该系统变量返回当前UCS的名称<BR>&nbsp;&nbsp;&nbsp; If ucsName &lt;&gt; "" Then<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dim objUcs As AcadUCSs<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Set objUcs = ThisDrawing.ActiveUCS<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ptTemp = ThisDrawing.GetVariable("viewctr")&nbsp;&nbsp;&nbsp;&nbsp; '返回当前视口的中心点(UCS坐标)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ptCen = ThisDrawing.Utility.TranslateCoordinates(ptTemp, acUCS, acWorld, False)<BR>&nbsp;&nbsp;&nbsp; ElseIf ucsName = "" Then<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ptCen = ThisDrawing.GetVariable("viewctr")<BR>&nbsp;&nbsp;&nbsp; End If<BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; '视图左上角点的坐标(即WMF图形插入的基点)<BR>&nbsp;&nbsp;&nbsp; Dim ptBase(0 To 2) As Double<BR>&nbsp;&nbsp;&nbsp; ptBase(0) = ptCen(0) - width / 2: ptBase(1) = ptCen(1) + height / 2: ptCen(2) = 0<BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; '输入文件<BR>&nbsp;&nbsp;&nbsp; If Dir("d:\temp.wmf") &lt;&gt; "" Then&nbsp;&nbsp;&nbsp; '判断文件是否存在<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ThisDrawing.Import "d:\temp.wmf", ptBase, 2<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Kill ("d:\temp.wmf")&nbsp;&nbsp;&nbsp; '删除临时文件<BR>&nbsp;&nbsp;&nbsp; Else<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; MsgBox "程序使用的临时文件不存在,请重新运行程序!", vbCritical<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Exit Sub<BR>&nbsp;&nbsp;&nbsp; End If<BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; '分解得到的块参照************************************<BR>&nbsp;&nbsp;&nbsp; Dim blkRef As AcadBlockReference<BR>&nbsp;&nbsp;&nbsp; Dim element As AcadEntity<BR>&nbsp;&nbsp;&nbsp; Set element = ThisDrawing.ModelSpace.item(ThisDrawing.ModelSpace.Count - 1)<BR>&nbsp;&nbsp;&nbsp; If TypeOf element Is AcadBlockReference Then<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Set blkRef = element<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; blkRef.Explode<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; blkRef.Delete<BR>&nbsp;&nbsp;&nbsp; End If<BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; objEnt.Delete&nbsp;&nbsp; '删除原来的文字对象<BR>&nbsp;&nbsp;&nbsp; SSet.Delete<BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; '缩放图形,返回原来的视图<BR>&nbsp;&nbsp;&nbsp; ZoomPrevious<BR>&nbsp;&nbsp;&nbsp; 'ZoomPrevious<BR>End Sub<BR>

mayuezxl 发表于 2006-8-19 16:30:00

《AutoCAD VBA开发精彩实例教程》这本书哪里有买?

idoo 发表于 2006-8-19 22:42:00

书店应该都有的,要么就直接去规模大的书店找。
页: [1] 2
查看完整版本: 飞狐版主请进+《AutoCAD VBA开发精彩实例教程》问题