lihengmin 发表于 2008-5-28 18:02:00

[求助]用VBA读实体的组码

<p>怎样用VBA读实体的组码?如下面的数据内读出“图元名: 43f47cc0”</p><p>((-1 . &lt;图元名: 43fd1a58&gt;) (0 . "INSERT") (5 . "33A8B") (102 . "{ACAD_REACTORS") (330 . &lt;图元名: 43fd1a30&gt;) (102 . }") (330 . &lt;图元名: 43f47cc0&gt;) (100 . "AcDbEntity") (67 . 0) (410 . "Model") (8 . "ZBTZ") (6 . "Continuous") (100 . "AcDbBlockReference") (2 . "gc429") (10 517405.0 4.08063e+006 0.0) (41 . 3.0) (42 . 3.0) (43 . 1.0) (50 . 0.0) (70 . 0) (71 . 0) (44 . 0.0) (45 . 0.0) (210 0.0 0.0 1.0))</p>

lihengmin 发表于 2008-5-29 12:04:00

求助<br/>怎么用VBA读取CAD实体的DXF组码?如编组的组码<br/>((-1 . &lt;图元名: 43fd1a48&gt;) (0 . "INSERT") (5 . "33A89") (102 . "{ACAD_REACTORS") (330 . &lt;图元名: 43fd1a30&gt;) (102 . "}") (330 . &lt;图元名: 43f47cc0&gt;) (100 . "AcDbEntity") (67 . 0) (410 . "Model") (8 . "ZBTZ") (6 . "Continuous") (100 . "AcDbBlockReference") (2 . "gc429") (10 517285.0 4.08063e+006 0.0) (41 . 3.0) (42 . 3.0) (43 . 1.0) (50 . 0.0) (70 . 0) (71 . 0) (44 . 0.0) (45 . 0.0) (210 0.0 0.0 1.0)) <br/>上面的数据内怎么读出(330 . &lt;图元名: 43f47cc0&gt;) <br/>

robbin840311 发表于 2008-5-29 12:50:00

明月,我也发帖了,没有人回啊

xxxtttxxx 发表于 2008-5-30 12:01:00

<p>如果cad对象参考中没有这个函数,那么估计是没有直接的办法了。</p><p>像我在另外一贴回的那样,可以试试:</p><p></p><p>没有试过读取组码。</p><p>而且感觉组码这个东西比较复杂,不同地方含义有不相同。</p><p>实体的祖码我不会,不过我觉得可以自己在帮助中查到实体组码,然后与其对应</p><p>的entitytype列表,vba查询到实体的entitytype,对应找到组码</p>

mccad 发表于 2008-5-30 12:22:00

<p>可能有两个方法:<br/>1.使用VLAX类。<br/>2.将图转成DXF,以处理文本的方法来处理。</p>

robbin840311 发表于 2008-5-30 14:01:00

<p>请问使用VLAX 怎么使用?VLAX类代码如下:</p><p>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(ByVal lispStatement As String)<br/>&nbsp;&nbsp;&nbsp;&nbsp; Dim sym As Object, RET As Object, RetVal<br/>&nbsp;&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;&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;&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;&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;&nbsp; <br/>&nbsp;&nbsp;&nbsp; Count = VLF.Item("length").Funcall(list)<br/>&nbsp;&nbsp;&nbsp; <br/>&nbsp;&nbsp;&nbsp; ReDim elements(0 To Count - 1) As Variant<br/>&nbsp;&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;&nbsp; <br/>&nbsp;&nbsp;&nbsp; GetLispList = elements<br/>&nbsp;&nbsp;&nbsp; <br/>End Function<br/>Public Sub NullifySymbol(ParamArray symbolName())<br/>&nbsp;&nbsp;&nbsp;&nbsp; Dim i As Integer<br/>&nbsp;&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>

lihengmin 发表于 2008-6-2 11:02:00

<p>麻烦您指教 使用VLAX类怎样读取,是上面的VLAX类吗?怎样调用</p><p>十分感谢</p>

robbin840311 发表于 2008-6-5 08:22:00

请版主回答啊

lihengmin 发表于 2008-6-5 22:53:00

帮帮忙吧

lihengmin 发表于 2008-7-15 16:49:00

<p>&nbsp;(assoc 331 (car (entsel)))</p><p>用此命令可得到&nbsp;“ (330 . &lt;图元名: 43fd1a30&gt;) ”,但有时得到前面330&nbsp; 有的实体得到后面的,是怎么搞的?</p>
页: [1] 2
查看完整版本: [求助]用VBA读实体的组码