14.5 数据记录和AutoCAD实体的对应(VBA 二次开发教程)
<P>14.5.2 编程思路</P><P>1 ObjectID、Handle和对象本身</P>
<P>2 记录和实体对应的惟一性</P>
<P>我希望与各位VBA发烧友和班竹共同探讨以上两个问题。</P>
<P>a ObjectID、Handle相关语句的描述</P>
<P>b 记录和实体对应的惟一性的认识</P>
<P>c lsp语句的相关表述</P> <P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US><FONT face="Times New Roman">Handle</FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt">根据“开发者文档”的一个实例对<FONT face="Times New Roman">Handle</FONT>的理解<FONT face="Times New Roman"></FONT></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><FONT face="Times New Roman">Sub Example_Handle()</FONT></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><FONT face="Times New Roman"><SPAN style="mso-spacerun: yes"> ' This example creates several objects in model space.</FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><FONT face="Times New Roman"><SPAN style="mso-spacerun: yes"> ' It then iterates through the objects in model space and displays the</FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><FONT face="Times New Roman"><SPAN style="mso-spacerun: yes"> ' Handle for each object found.</FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN style="mso-spacerun: yes"><FONT face="Times New Roman"> </FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><FONT face="Times New Roman"><SPAN style="mso-spacerun: yes"> ' Create a Ray object in model space</FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><FONT face="Times New Roman"><SPAN style="mso-spacerun: yes"> Dim rayObj As AcadRay</FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><FONT face="Times New Roman"><SPAN style="mso-spacerun: yes"> Dim basePoint(0 To 2) As Double</FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><FONT face="Times New Roman"><SPAN style="mso-spacerun: yes"> Dim SecondPoint(0 To 2) As Double</FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><FONT face="Times New Roman"><SPAN style="mso-spacerun: yes"> basePoint(0) = 3#: basePoint(1) = 3#: basePoint(2) = 0#</FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><FONT face="Times New Roman"><SPAN style="mso-spacerun: yes"> SecondPoint(0) = 1#: SecondPoint(1) = 3#: SecondPoint(2) = 0#</FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><FONT face="Times New Roman"><SPAN style="mso-spacerun: yes"> Set rayObj = ThisDrawing.ModelSpace.AddRay(basePoint, SecondPoint)</FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN style="mso-spacerun: yes"><FONT face="Times New Roman"> </FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><FONT face="Times New Roman"><SPAN style="mso-spacerun: yes"> ' Create a polyline object in model space</FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><FONT face="Times New Roman"><SPAN style="mso-spacerun: yes"> Dim plineObj As AcadLWPolyline</FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><FONT face="Times New Roman"><SPAN style="mso-spacerun: yes"> Dim points(0 To 5) As Double</FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><FONT face="Times New Roman"><SPAN style="mso-spacerun: yes"> points(0) = 3: points(1) = 7</FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><FONT face="Times New Roman"><SPAN style="mso-spacerun: yes"> points(2) = 9: points(3) = 2</FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><FONT face="Times New Roman"><SPAN style="mso-spacerun: yes"> points(4) = 3: points(5) = 5</FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><FONT face="Times New Roman"><SPAN style="mso-spacerun: yes"> Set plineObj = ThisDrawing.ModelSpace.AddLightWeightPolyline(points)</FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><FONT face="Times New Roman"><SPAN style="mso-spacerun: yes"> plineObj.Closed = True</FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><FONT face="Times New Roman"> <?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p></FONT></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><FONT face="Times New Roman"><SPAN style="mso-spacerun: yes"> ' Create a line object in model space</FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><FONT face="Times New Roman"><SPAN style="mso-spacerun: yes"> Dim lineObj As AcadLine</FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><FONT face="Times New Roman"><SPAN style="mso-spacerun: yes"> Dim startPoint(0 To 2) As Double</FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><FONT face="Times New Roman"><SPAN style="mso-spacerun: yes"> Dim endPoint(0 To 2) As Double</FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><FONT face="Times New Roman"><SPAN style="mso-spacerun: yes"> startPoint(0) = 0: startPoint(1) = 0: startPoint(2) = 0</FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><FONT face="Times New Roman"><SPAN style="mso-spacerun: yes"> endPoint(0) = 2: endPoint(1) = 2: endPoint(2) = 0</FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><FONT face="Times New Roman"><SPAN style="mso-spacerun: yes"> Set lineObj = ThisDrawing.ModelSpace.AddLine(startPoint, endPoint)</FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN style="mso-spacerun: yes"><FONT face="Times New Roman"> </FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><FONT face="Times New Roman"><SPAN style="mso-spacerun: yes"> ' Create a circle object in model space</FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><FONT face="Times New Roman"><SPAN style="mso-spacerun: yes"> Dim circObj As AcadCircle</FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><FONT face="Times New Roman"><SPAN style="mso-spacerun: yes"> Dim centerPt(0 To 2) As Double</FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><FONT face="Times New Roman"><SPAN style="mso-spacerun: yes"> Dim radius As Double</FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><FONT face="Times New Roman"><SPAN style="mso-spacerun: yes"> centerPt(0) = 5: centerPt(1) = 3: centerPt(2) = 0</FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><FONT face="Times New Roman"><SPAN style="mso-spacerun: yes"> radius = 3</FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><FONT face="Times New Roman"><SPAN style="mso-spacerun: yes"> Set circObj = ThisDrawing.ModelSpace.AddCircle(centerPt, radius)</FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><FONT face="Times New Roman"> <o:p></o:p></FONT></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><FONT face="Times New Roman"><SPAN style="mso-spacerun: yes"> ' Create an ellipse object in model space</FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><FONT face="Times New Roman"><SPAN style="mso-spacerun: yes"> Dim ellObj As AcadEllipse</FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><FONT face="Times New Roman"><SPAN style="mso-spacerun: yes"> Dim majAxis(0 To 2) As Double</FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><FONT face="Times New Roman"><SPAN style="mso-spacerun: yes"> Dim center(0 To 2) As Double</FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><FONT face="Times New Roman"><SPAN style="mso-spacerun: yes"> Dim radRatio As Double</FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><FONT face="Times New Roman"><SPAN style="mso-spacerun: yes"> center(0) = 5#: center(1) = 5#: center(2) = 0#</FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><FONT face="Times New Roman"><SPAN style="mso-spacerun: yes"> majAxis(0) = 10: majAxis(1) = 20#: majAxis(2) = 0#</FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><FONT face="Times New Roman"><SPAN style="mso-spacerun: yes"> radRatio = 0.3</FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><FONT face="Times New Roman"><SPAN style="mso-spacerun: yes"> Set ellObj = ThisDrawing.ModelSpace.AddEllipse(center, majAxis, radRatio)</FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><FONT face="Times New Roman"> <o:p></o:p></FONT></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><FONT face="Times New Roman"> <o:p></o:p></FONT></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><FONT face="Times New Roman"><SPAN style="mso-spacerun: yes"> ZoomAll</FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN style="mso-spacerun: yes"><FONT face="Times New Roman"> </FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><FONT face="Times New Roman"><SPAN style="mso-spacerun: yes"> ' Iterate through the model space collection and display</FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><FONT face="Times New Roman"><SPAN style="mso-spacerun: yes"> ' the handle of each object found.</FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN style="mso-spacerun: yes"><FONT face="Times New Roman"> </FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><FONT face="Times New Roman"><SPAN style="mso-spacerun: yes"> Dim entHandle As String</FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><FONT face="Times New Roman"><SPAN style="mso-spacerun: yes"> Dim entry As AcadEntity</FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><FONT face="Times New Roman"><SPAN style="mso-spacerun: yes"> For Each entry In ThisDrawing.ModelSpace</FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><FONT face="Times New Roman"><SPAN style="mso-spacerun: yes"> entHandle = entry.Handle</FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><FONT face="Times New Roman"><SPAN style="mso-spacerun: yes"> entry.Highlight (True)</FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><FONT face="Times New Roman"><SPAN style="mso-spacerun: yes"> MsgBox "The handle of this object is " & entHandle, vbInformation, "Handle Example"</FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><FONT face="Times New Roman"><SPAN style="mso-spacerun: yes"> entry.Highlight (False)</FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><FONT face="Times New Roman"><SPAN style="mso-spacerun: yes"> Next</FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><FONT face="Times New Roman">End Sub</FONT></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><FONT face="Times New Roman"> <o:p></o:p></FONT></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><FONT face="Times New Roman"> <o:p></o:p></FONT></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><FONT face="Times New Roman"> <o:p></o:p></FONT></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt">问题<FONT face="Times New Roman">1: Dim entry As AcadEntity </FONT>在开发者文档中没有查到<FONT face="Times New Roman">AcadEntity</FONT>,<FONT face="Times New Roman">AcadEntity</FONT>什么意思?</P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt">问题<FONT face="Times New Roman">2: entry.Highlight (True) </FONT>是否为<FONT face="Times New Roman"> </FONT>在<FONT face="Times New Roman">AutoCAD </FONT>的<FONT face="Times New Roman">select</FONT>命令,控制选择亮显功能</P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt">问题<FONT face="Times New Roman">3: vbInformation</FONT>在开发者文档中没查到,<FONT face="Times New Roman">Debug.print</FONT>为<FONT face="Times New Roman">64</FONT>,从字面翻译为<FONT face="Times New Roman">VB</FONT>信息,是版号还是其它意思?</P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt">问题<FONT face="Times New Roman">4: </FONT>对<FONT face="Times New Roman">Each entry In ThisDrawing.ModelSpace</FONT>的理解<FONT face="Times New Roman">,</FONT>在这个模型空间在循环找到每个实体?相比在<FONT face="Times New Roman">lsp</FONT>中完成这个功能要简单。</P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><FONT face="Times New Roman"> <o:p></o:p></FONT></P> <P>1,<FONT face="Times New Roman">AcadEntity即object</FONT></P>
<P><FONT face="Times New Roman">2,对,高亮显示</FONT></P>
<P><FONT face="Times New Roman">3,vbInformation在msgbox下可以察看许多这样的vb变量</FONT></P>
<P><FONT face="Times New Roman">4,对</FONT></P> <P>1、ObjectID是对象ID,在当前的整个AutoCAD应用程序内是唯一的。Handle是对象句柄,仅在一个文档内是唯一的。</P>
<P>2、<FONT face="Times New Roman">AcadEntity是图元对象的基类,只限于有图形的对象使用。AcadObject是所有对象的基类,可以用于非图形对象,如层,文字样式等。</FONT></P>
<P><FONT face="Times New Roman">3、vbInformation是用于MsgBox中,代表弹出的是信息提示框,还可以是警告、疑问之类的。</FONT></P>
页:
[1]