百思论坛
                                                                  -工程科技交流平台

百思论坛 » 三维CAD软件 » Inventor » 关于inventor 开发的问题,大家帮帮我啊,在线等啊!


2008-4-13 17:32 ecomes
关于inventor 开发的问题,大家帮帮我啊,在线等啊!

<font size="4">这几天遇到这个问题,搞了几天都没有搞出来,希望各位帮帮我啊!给我几个API函数也好啊!</font><br /><font size="4"></font><br /><font size="4">功能描述:装配体中包括多个零件和子装配,这些统称为部件。现在我想获得鼠标选中的部件对象。例如:在一个装配体中有10个零部件,我用鼠标选择第1个零件,那么就得到第一个零件的对象,可以通过这个对象得到这个零件的名称,路径等等!</font><br /><font size="4">&nbsp; </font><br /><font size="4">谢谢</font><br />

2008-4-14 14:14 number050083021
大家帮帮忙!提供写思路也好啊?

2008-4-15 07:40 kingchenly

2008-4-16 01:49 驰宇
Sub GetName()<br />&nbsp; &nbsp; Dim oDoc As AssemblyDocument<br />&nbsp; &nbsp; Set oDoc = ThisApplication.ActiveDocument<br />&nbsp; &nbsp; &nbsp; &nbsp; <br />&nbsp; &nbsp; Dim oOccr As ComponentOccurrence<br />&nbsp; &nbsp; Set oOccr = oDoc.SelectSet.Item(1)<br />&nbsp; &nbsp; <br />&nbsp; &nbsp; Debug.Print oOccr.Name<br />&nbsp; &nbsp; Debug.Print oOccr.ReferencedDocumentDescriptor.DisplayName<br />&nbsp; &nbsp; Debug.Print oOccr.ReferencedDocumentDescriptor.FullDocumentName<br />&nbsp; &nbsp; &nbsp; &nbsp; <br />End Sub<br />我大概写了一段,使用方法为在总装配里面选零部件,然后运行这段vba,在debug窗口就会打出相应部件的名字和路径。具体细节楼主可以润色润色,比如做成插件,做些界面和容错什么的。

2008-4-16 04:11 quanzi20
哈哈解决了! <br />CComPtr&lt;Document&gt; partDoc; <br />long docType; <br />partDoc= m_pApplication-&gt;ActiveDocument; <br />docType=partDoc-&gt;DocumentType; <br />if(docType==kAssemblyDocumentObject) <br />{ <br />CComPtr&lt;IDispatch&gt; pDispatch; <br />CComPtr&lt;SelectSet&gt; pSelSet; <br />CComPtr&lt;ComponentOccurrence&gt; oComp ; <br />pSelSet=partDoc-&gt;SelectSet; <br />pDispatch=pSelSet-&gt;GetItem(1); <br />pDispatch-&gt;QueryInterface(__uuidof(oComp),reinterpret_cast&lt;void**&gt;(&oComp)); <br />oComp-&gt;Visible=FALSE; <br />m_list1.AddString(oComp-&gt;Name);<br />}<br />但是我使用了一个强制转化(红色的地方),不然类型就不对,VC和VBA有很大的区别,VBA的类型转化很多都是自动的,<br />不知道那位还有什么方法,不使用强制转化?

2008-4-16 18:53 arbalest
VC我不懂,呵呵。另等高人...

2008-4-17 03:47 hap
选定某零部件,右件菜单“特性”,之后的结果搂主看看是否够您用的了?

页: [1]