babyred 发表于 2007-5-24 13:45:00

[求助]如何能获得NURBS实体的DXF组值

<p><shapetype id="_x0000_t75" stroked="f" filled="f" path="m@4@5l@4@11@9@11@9@5xe" opreferrelative="t" ospt="75" coordsize="21600,21600">&nbsp;</shapetype><img src="file:///D:/未命名.bmp" border="0" alt=""/></p><p>这是Nurbs曲线实体段的组码和说明,想提取次数,节点值,权值和控制点值</p><p>但是以前没用过CAD的VBA</p><p>哪位高手能举例说明一下怎么提取么?</p><p>比如</p><p>刚看来得</p><p class="MsoNormal" style="BACKGROUND: white; MARGIN: 24pt 0cm 12pt; WORD-BREAK: break-all; mso-pagination: widow-orphan; mso-outline-level: 1;">Dim objSel As AcadEntity</p><p><span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: Tahoma; mso-font-kerning: 0pt;"><span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: Tahoma; mso-font-kerning: 0pt;"><p class="MsoNormal" style="BACKGROUND: white; MARGIN: 24pt 0cm 12pt; WORD-BREAK: break-all; mso-pagination: widow-orphan; mso-outline-level: 1;"><span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: Tahoma; mso-font-kerning: 0pt;">If objSel.ObjectName &lt;&gt; "AcDbSpline" Then‘<span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 宋体; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA; mso-ascii-font-family: Tahoma; mso-hansi-font-family: Tahoma; mso-bidi-font-family: Tahoma;">选择的不是 AcDbSpline,.....</span></p><p class="MsoNormal" style="BACKGROUND: white; MARGIN: 24pt 0cm 12pt; WORD-BREAK: break-all; mso-pagination: widow-orphan; mso-outline-level: 1;"><span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: Tahoma; mso-fareast-font-family: 宋体; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA;">我想判断如果组码值为71,把值赋给k</span></p><p class="MsoNormal" style="BACKGROUND: white; MARGIN: 24pt 0cm 12pt; WORD-BREAK: break-all; mso-pagination: widow-orphan; mso-outline-level: 1;"><span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: Tahoma; mso-fareast-font-family: 宋体; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA;">如果组码值 为10,把值付给一个数组x</span></p><p class="MsoNormal" style="BACKGROUND: white; MARGIN: 24pt 0cm 12pt; WORD-BREAK: break-all; mso-pagination: widow-orphan; mso-outline-level: 1;"><span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: Tahoma; mso-fareast-font-family: 宋体; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA;">一些关键字不知用什么 啊</span></p><p class="MsoNormal" style="BACKGROUND: white; MARGIN: 24pt 0cm 12pt; WORD-BREAK: break-all; mso-pagination: widow-orphan; mso-outline-level: 1;">&nbsp;</p><p class="MsoNormal" style="BACKGROUND: white; MARGIN: 24pt 0cm 12pt; WORD-BREAK: break-all; mso-pagination: widow-orphan; mso-outline-level: 1;">&nbsp;</p><p></p></span><p></p></span></p></span>

babyred 发表于 2007-5-29 17:14:00

没人知道么?

laoliu09 发表于 2007-5-30 00:32:00

<p>你判断组码为了甚么呢?VBA里好像只能判断对象的属性,判断组码好像无从下手,你想实现甚么呢?不一定非要判断组码的吧?</p>

babyred 发表于 2007-5-30 15:36:00

<p>我想将样条曲线的阶次,控制顶点坐标,权值以及节点值提取出来,用于二次开发啊</p><p>不能实现么?</p>

babyred 发表于 2007-5-30 15:41:00

<p class="body" style="MARGIN: auto 0cm;">这个功能VB可以实现,VBA不可以么?</p><p class="body" style="MARGIN: auto 0cm;">以下是一个简单的 Visual Basic 6 程序样例,它读取 DXF 文件,并且从给定段的给定对象中提取特定代码和值。</p><pre><font face="宋体">' ReadDXF 从 DXF 文件中提取指定的代码/值对。</font></pre><pre><font face="宋体">' 此函数需要四个字符串参数、一个有效的 DXF</font></pre><pre><font face="宋体">' 文件名、一个 DXF 段名、该段中对象的</font></pre><pre><font face="宋体">' 名称以及由逗号分隔的代码列表。</font></pre><pre><font face="宋体">'</font></pre><pre><font face="宋体">Function ReadDXF( _</font></pre><pre><font face="宋体"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ByVal dxfFile As String, ByVal strSection As String, _</font></span></pre><pre><font face="宋体"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ByVal strObject As String, ByVal strCodeList As String)</font></span></pre><pre><font face="宋体"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp; Dim tmpCode, lastObj As String</font></span></pre><pre><font face="宋体"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp; Open dxfFile For Input As #1</font></span></pre><pre><font face="宋体"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp; ' </span>获取第一个代码/值对</font></pre><pre><font face="宋体"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp; codes = ReadCodes</font></span></pre><pre><font face="宋体"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp; ' </span>遍历整个文件,直到“EOF”行</font></pre><pre><font face="宋体"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp; While codes(1) &lt;&gt; "EOF"</font></span></pre><pre><font face="宋体"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ' </span>如果组码为“<chmetcnv wst="on" tcsc="0" numbertype="1" negative="False" hasspace="False" sourcevalue="0" unitname="”">0”</chmetcnv>,并且值为“SECTION”,则</font></pre><pre><font face="宋体"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; If codes(0) = "0" And codes(1) = "SECTION" Then</font></span></pre><pre><font face="宋体"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ' </span>这必须是一个新的段,以便获取下一个</font></pre><pre><font face="宋体"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ' </span>代码/值对。</font></pre><pre><font face="宋体"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; codes = ReadCodes()</font></span></pre><pre><font face="宋体"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ' </span>如果此段是要获取的段,则</font></pre><pre><font face="宋体"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; If codes(1) = strSection Then</font></span></pre><pre><font face="宋体"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ' </span>获取下一个代码/值对,并</font></pre><pre><font face="宋体"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; codes = ReadCodes</font></span></pre><pre><font face="宋体"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ' </span>遍历此段,直到“ENDSEC”</font></pre><pre><font face="宋体"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; While codes(1) &lt;&gt; "ENDSEC"</font></span></pre><pre><font face="宋体"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ' </span>在某段中,所有的“<chmetcnv wst="on" tcsc="0" numbertype="1" negative="False" hasspace="False" sourcevalue="0" unitname="”">0”</chmetcnv>代码都表示</font></pre><pre><font face="宋体"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ' </span>对象。 如果找到了“<chmetcnv wst="on" tcsc="0" numbertype="1" negative="False" hasspace="False" sourcevalue="0" unitname="”">0”</chmetcnv>代码,则存储</font></pre><pre><font face="宋体"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ' </span>对象名称,供以后使用。</font></pre><pre><font face="宋体"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; If codes(0) = "0" Then lastObj = codes(1)</font></span></pre><pre><font face="宋体"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ' </span>如果此对象是用户所需的对象,</font></pre><pre><font face="宋体"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; If lastObj = strObject Then</font></span></pre><pre><font face="宋体"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ' </span>则在代码前后加上逗号</font></pre><pre><font face="宋体"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; tmpCode = "," &amp; codes(0) &amp; ","</font></span></pre><pre><font face="宋体"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ' </span>如果此代码位于代码列表中,</font></pre><pre><font face="宋体"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; If InStr(strCodeList, tmpCode) Then</font></span></pre><pre><font face="宋体"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ' </span>则附加返回值。</font></pre><pre><font face="宋体"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ReadDXF = ReadDXF &amp; _</font></span></pre><pre><font face="宋体"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; codes(0) &amp; "=" &amp; codes(1) &amp; vbCrLf</font></span></pre><pre><font face="宋体"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; End If</font></span></pre><pre><font face="宋体"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; End If</font></span></pre><pre><font face="宋体"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;' </span>读取其他代码/值对</font></pre><pre><font face="宋体"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; codes = ReadCodes</font></span></pre><pre><font face="宋体"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Wend</font></span></pre><pre><font face="宋体"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; End If</font></span></pre><pre><font face="宋体"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>否则</font></pre><pre><font face="宋体"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; codes = ReadCodes</font></span></pre><pre><font face="宋体"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; End If</font></span></pre><pre><font face="宋体"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp; Wend</font></span></pre><pre><font face="宋体"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp; Close #1</font></span></pre><pre><font face="宋体">End Function</font></pre><pre><font face="宋体">' ReadCodes 从打开的文件中读取两行,并返回一个包含两个项目</font></pre><pre><font face="宋体">' 的数组、一个组码及其组码值。 只要一次读取 DXF 文件中的两行代码,
                        </font></pre><pre><font face="宋体">' 所有程序应该都能够顺利运行。 但为了使代码
                        </font></pre><pre><font face="宋体">' 更可靠,应该添加一些进行错误检查和其他</font></pre><pre><font face="宋体">' 检查的代码。</font></pre><pre><font face="宋体">'</font></pre><pre><font face="宋体">Function ReadCodes() As Variant</font></pre><pre><font face="宋体"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp; Dim codeStr, valStr As String</font></span></pre><pre><font face="宋体"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp; Line Input #1, codeStr</font></span></pre><pre><font face="宋体"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp; Line Input #1, codeStr</font></span></pre><pre><font face="宋体"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp; ' </span>修剪代码中的前导空格和后续空格</font></pre><pre><font face="宋体"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp; ReadCodes = Array(Trim(codeStr), valStr)</font></span></pre><pre><font face="宋体">End Function</font></pre><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt;"><p><font face="Times New Roman">&nbsp;</font></p></p>

laoliu09 发表于 2007-5-31 00:24:00

<p>如果是读取dxf文件的话,VB和VBA都一样的,但想直接从图形中判断组码,应该就不行了,看看其他高手有妙招没有!</p>
页: [1]
查看完整版本: [求助]如何能获得NURBS实体的DXF组值