micro_v8 发表于 2009-5-13 16:42:00

如何获取VERTEX子实体所附带的扩展属性

如何获取VERTEX子实体所附带的扩展属性

雪山飞狐_lzh 发表于 2009-5-15 07:33:00

<p>VERTEX子实体没有在对象模型中公开,以前试过读取它,好像数据可以读出来,</p><p>方法读取pl线的句柄,然后获取此句柄后的实体</p><p>不确定是否可以成功,因为是很久以前试过的</p>

CAD学习开发 发表于 2010-4-21 13:03:00

我也很想知道,不知道哪位高手能给个答案?

CAD学习开发 发表于 2010-4-21 20:51:00

<p>终于找到答案了,真费劲啊。</p><p>CASS下通过VBA获取子对象的扩展属性<br/>(2008-05-22 09:54:47)<br/>转载<br/>标签:<br/>it<br/>&nbsp;分类:GIS二次开发<br/>背景:<br/>&nbsp;&nbsp;&nbsp; CASS中,录入界址线属性时,一宗地的所有界址线本宗指界人和指界日期是一样的,但就现状来说,如一宗地有4条界址线,本宗指界人和指界日期就要录入4遍,能否只录入一遍,其余界址线的本宗指界人和指界日期自动产生。<br/>&nbsp;&nbsp;&nbsp; 基于此目的,书写以下程序:<br/>版本信息:AutoCAD 2006、CASS7.1<br/>关键技术:<br/>&nbsp;&nbsp;&nbsp; 在CASS中,二维多段线是一个复杂实体,除了主实体之外还带有子实体(VERTEX),界址线的属性就存储在VERTEX中,关键是要获取子实体。<br/>&nbsp;<br/>1、把以下LISP代码复制到acad2006doc.lsp中:<br/>(defun getvers(handle / lst ver)<br/>(setq ver (handent handle))<br/>(while (and (setq ver (entnext ver)) (= "VERTEX" (cdr (assoc 0 (entget ver)))))(setq lst (cons (cdr (assoc 5 (entget ver))) lst)))<br/>lst<br/>)<br/>&nbsp;<br/>位置在<br/>;; Silent load.<br/>(princ)<br/>上。<br/>2、新建一个VLAX类,并把以下代码复制到其中。</p><p>' VLAX.CLS v2.0 (Last updated 8/1/2003)<br/>' Copyright 1999-2001 by Frank Oquendo<br/>'<br/>' 该程序由明经通道修改支持2004版本<br/>' <a href="http://www.mjtd.com">http://www.mjtd.com</a><br/>'<br/>' Permission to use, copy, modify, and distribute this software<br/>' for any purpose and without fee is hereby granted, provided<br/>' that the above copyright notice appears in all copies and<br/>' that both that copyright notice and the limited warranty and<br/>' restricted rights notice below appear in all supporting<br/>' documentation.<br/>'<br/>' FRANK OQUENDO (THE AUTHOR) PROVIDES THIS PROGRAM "AS IS" AND WITH<br/>' ALL FAULTS. THE AUTHOR SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTY<br/>' OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR USE.&nbsp; THE AUTHOR<br/>' DOES NOT WARRANT THAT THE OPERATION OF THE PROGRAM WILL BE<br/>' UNINTERRUPTED OR ERROR FREE.<br/>'<br/>' Use, duplication, or disclosure by the U.S. Government is subject to<br/>' restrictions set forth in FAR 52.227-19 (Commercial Computer<br/>' Software - Restricted Rights) and DFAR 252.227-7013(c)(1)(ii)<br/>' (Rights in Technical Data and Computer Software), as applicable.<br/>'<br/>' VLAX.cls allows developers to evaluate AutoLISP expressions from<br/>' Visual Basic or VBA<br/>'<br/>' Notes:<br/>' All code for this class module is publicly available througout various posts<br/>' at <a href="news://discussion.autodesk.com/autodesk.autocad.customization.vba">news://discussion.autodesk.com/autodesk.autocad.customization.vba</a>. I do not<br/>' claim copyright or authorship on code presented in these posts, only on this<br/>' compilation of that code. In addition, a great big "Thank you!" to Cyrille Fauvel<br/>' demonstrating the use of the VisualLISP ActiveX Module.<br/>'<br/>' Dependencies:<br/>' Use of this class module requires the following application:<br/>' 1. VisualLISP<br/>Private VL As Object<br/>Private VLF As Object<br/>Private Sub Class_Initialize()<br/>&nbsp;&nbsp;&nbsp;&nbsp; If Left(ThisDrawing.Application.Version, 2) = "15" Then<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Set VL = GetInterfaceObject("VL.Application.1")<br/>&nbsp;&nbsp;&nbsp;&nbsp; ElseIf Left(ThisDrawing.Application.Version, 2) = "16" Then<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Set VL = GetInterfaceObject("VL.Application.16")<br/>&nbsp;&nbsp;&nbsp;&nbsp; ElseIf Left(ThisDrawing.Application.Version, 2) = "17" Then<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Set VL = GetInterfaceObject("VL.Application.16")<br/>&nbsp;&nbsp;&nbsp;&nbsp; End If<br/>&nbsp;&nbsp;&nbsp;&nbsp; Set VLF = VL.ActiveDocument.Functions<br/>End Sub<br/>Private Sub Class_Terminate()<br/>&nbsp;&nbsp;&nbsp;&nbsp; Set VLF = Nothing<br/>&nbsp;&nbsp;&nbsp;&nbsp; Set VL = Nothing<br/>End Sub<br/>Public Function EvalLispexpression_r(ByVal lispStatement As String)<br/>&nbsp;&nbsp;&nbsp;&nbsp; Dim sym As Object, RET As Object, RetVal<br/>&nbsp;&nbsp;&nbsp; <br/>&nbsp;&nbsp;&nbsp;&nbsp; Set sym = VLF.Item("read").Funcall(lispStatement)<br/>&nbsp;&nbsp;&nbsp;&nbsp; On Error Resume Next<br/>&nbsp;&nbsp;&nbsp;&nbsp; RetVal = VLF.Item("eval").Funcall(sym)<br/>&nbsp;&nbsp;&nbsp;&nbsp; If Err Then<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; EvalLispExpression = ""<br/>&nbsp;&nbsp;&nbsp;&nbsp; Else<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; EvalLispExpression = RetVal<br/>&nbsp;&nbsp;&nbsp;&nbsp; End If<br/>End Function<br/>Public Sub SetLispSymbol(ByVal symbolName As String, ByVal Value)<br/>&nbsp;&nbsp;&nbsp;&nbsp; Dim sym As Object, RET, symvalue<br/>&nbsp;&nbsp;&nbsp; <br/>&nbsp;&nbsp;&nbsp;&nbsp; symvalue = Value<br/>&nbsp;&nbsp;&nbsp;&nbsp; Set sym = VLF.Item("read").Funcall(symbolName)<br/>&nbsp;&nbsp;&nbsp;&nbsp; RET = VLF.Item("set").Funcall(sym, symvalue)<br/>&nbsp;&nbsp;&nbsp;&nbsp; EvalLispExpression "(defun translate-variant (data) (cond ((= (type data) 'list) (mapcar 'translate-variant data)) ((= (type data) 'variant) (translate-variant (vlax-variant-value data))) ((= (type data) 'safearray) (mapcar 'translate-variant (vlax-safearray-&gt;list data))) (t data)))"<br/>&nbsp;&nbsp;&nbsp;&nbsp; EvalLispExpression "(setq " &amp; symbolName &amp; "(translate-variant " &amp; symbolName &amp; "))"<br/>&nbsp;&nbsp;&nbsp;&nbsp; EvalLispExpression "(setq translate-variant nil)"<br/>End Sub<br/>Public Function GetLispSymbol(ByVal symbolName As String)<br/>&nbsp;&nbsp;&nbsp;&nbsp; Dim sym As Object, RET, symvalue<br/>&nbsp;&nbsp;&nbsp; <br/>&nbsp;&nbsp;&nbsp;&nbsp; symvalue = Value<br/>&nbsp;&nbsp;&nbsp;&nbsp; Set sym = VLF.Item("read").Funcall(symbolName)<br/>&nbsp;&nbsp;&nbsp;&nbsp; GetLispSymbol = VLF.Item("eval").Funcall(sym)<br/>End Function<br/>Public Function GetLispList(ByVal symbolName As String) As Variant<br/>&nbsp;&nbsp;&nbsp; Dim sym As Object, list As Object<br/>&nbsp;&nbsp;&nbsp; Dim Count, elements(), i As Long<br/>&nbsp;&nbsp; <br/>&nbsp;&nbsp;&nbsp; Set sym = VLF.Item("Read").Funcall(symbolName)<br/>&nbsp;&nbsp;&nbsp; Set list = VLF.Item("Eval").Funcall(sym)<br/>&nbsp;&nbsp; <br/>&nbsp;&nbsp;&nbsp; Count = VLF.Item("length").Funcall(list)<br/>&nbsp;&nbsp; <br/>&nbsp;&nbsp;&nbsp; ReDim elements(0 To Count - 1) As Variant<br/>&nbsp;&nbsp; <br/>&nbsp;&nbsp;&nbsp; For i = 0 To Count - 1<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; elements(i) = VLF.Item("nth").Funcall(i, list)<br/>&nbsp;&nbsp;&nbsp; Next<br/>&nbsp;&nbsp; <br/>&nbsp;&nbsp;&nbsp; GetLispList = elements<br/>&nbsp;&nbsp; <br/>End Function<br/>Public Sub NullifySymbol(ParamArray symbolName())<br/>&nbsp;&nbsp;&nbsp;&nbsp; Dim i As Integer<br/>&nbsp;&nbsp;&nbsp; <br/>&nbsp;&nbsp;&nbsp;&nbsp; For i = LBound(symbolName) To UBound(symbolName)<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; EvalLispExpression "(setq " &amp; CStr(symbolName(i)) &amp; " nil)"<br/>&nbsp;&nbsp;&nbsp;&nbsp; Next<br/>End Sub</p><p><br/>3、新建一个函数(获取子实体)</p><p><br/>Function GetVertexs(Ent As AcadEntity) As Variant<br/>&nbsp;&nbsp;&nbsp; Dim n As Integer<br/>&nbsp;&nbsp;&nbsp; Dim oVertexs() As AcadObject<br/>&nbsp;&nbsp;&nbsp; Dim sName As String<br/>&nbsp;&nbsp;&nbsp; sName = UCase(Ent.ObjectName)<br/>&nbsp;&nbsp; <br/>&nbsp;&nbsp;&nbsp; If sName = "ACDB2DPOLYLINE" Or sName = "ACDB3DPOLYLINE" Then<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; n = (UBound(Ent.Coordinates) + 1) / 3<br/>&nbsp;&nbsp;&nbsp; End If<br/>&nbsp;&nbsp; <br/>&nbsp;&nbsp;&nbsp; If n = 0 Then Exit Function<br/>&nbsp;&nbsp; <br/>&nbsp;&nbsp;&nbsp; ReDim oVertexs(n - 1)<br/>&nbsp;&nbsp; <br/>&nbsp;&nbsp;&nbsp; Dim oVlax As New VLAX<br/>&nbsp;&nbsp;&nbsp; lst = oVlax.GetLispList("(GetVers """ &amp; Ent.Handle &amp; """)")<br/>&nbsp;&nbsp; <br/>&nbsp;&nbsp;&nbsp; For i = 1 To n<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Set oVertexs(i - 1) = ThisDrawing.HandleToObject(lst(n - i))<br/>&nbsp;&nbsp;&nbsp; Next i<br/>&nbsp;&nbsp; <br/>&nbsp;&nbsp;&nbsp; GetVertexs = oVertexs<br/>&nbsp;&nbsp; <br/>End Function</p><p>&nbsp;</p><p>4、新建一个过程(获取扩展属性)</p><p>Sub test4()<br/>&nbsp;&nbsp;&nbsp; On Error Resume Next<br/>&nbsp;&nbsp; <br/>&nbsp;&nbsp;&nbsp; Dim obj As AcadEntity, pnt, oVers<br/>&nbsp;&nbsp;&nbsp; Dim xt, xd<br/>&nbsp;&nbsp; <br/>&nbsp;&nbsp;&nbsp; ThisDrawing.Utility.GetEntity obj, pnt, "请选择界址线所在的宗地:"<br/>&nbsp;&nbsp; <br/>&nbsp;&nbsp;&nbsp; oVers = GetVertexs(obj)<br/>&nbsp;&nbsp;&nbsp; If oVers &lt;&gt; vbEmpty Then<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; For i = 0 To UBound(oVers)<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; s = ""<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; oVers(i).GetXData "", xt, xd<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; For j = 0 To UBound(xd)<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; s = s &amp; vbCrLf &amp; xd(j)<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Next j<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; If Err Then<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Err.Clear<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; MsgBox "空值"<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Else<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; MsgBox s<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; End If<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Next i<br/>&nbsp;&nbsp;&nbsp; Else<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; MsgBox "错误选择"<br/>&nbsp;&nbsp;&nbsp; End If<br/>End Sub</p><p>&nbsp;</p><p>注意:新建一个Public WithEvents PLine as AcadPolyline(即给polyline加入一个事件)。</p><p>This event will be triggered whenever the object is modified. Modification includes whenever the value of a property is set, even if the new value is equal to the current value.</p><p>When coding in VBA, you must provide an event handler for all objects enabled for the Modified event. If you do not provide a handler, VBA may terminate unexpectedly.</p><p>No events will be fired while a modal dialog is being displayed.</p><p>然后把获取扩展属性的代码放在Modified内部即可达到目的。</p>

ljq 发表于 2010-5-4 03:03:00

<p>这是老版本的2维线呀,采用这种方法,cass就没有进步的可能了。</p>

CAD学习开发 发表于 2010-5-4 12:25:00

是啊,在大比例尺制图软件方面cass还有些市场。在中小比例尺方面cass很难进入啊!
页: [1]
查看完整版本: 如何获取VERTEX子实体所附带的扩展属性