社区
Inventor 产品技术应用讨论区
欢迎访问欧特克Inventor论坛!分享知识,发帖提问,浏览Inventor热帖
取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 

部件环境下子零件依据属性种类字符分类另存零件

31 条回复31
已解决
回复
1 条消息(共 32 条)
442780782
2796 次查看, 31 条回复

部件环境下子零件依据属性种类字符分类另存零件

在Autodesk inventor 2016 部件环境下,运行VB代码提示如图所示代码报错.png

31 条回复31
21 条消息(共 32 条)

使用得软件版本 AIP 2016
22 条消息(共 32 条)

AIP 2016

23 条消息(共 32 条)

我在2016版本上测试了,能够正常导出,没有发现问题

24 条消息(共 32 条)

我在2016版本中测试能够正常导出,没有发现问题。可以试试其他简单的装配或者上传一个导出异常的文件吗


If my post answers your question, please click the "Accept as Solution" button. This helps everyone find answers more quickly!
如果我的回帖解决了您的问题,请点击 "接受为解决方案" 按钮. 这可以帮助其他人更快的找到解决方案!


王 承之
Autodesk AGN [Inventor 俱乐部] Leader
Inventor Club | Bilibili


AGN L    EESignature

25 条消息(共 32 条)

好的,我再测试个简单模型。

26 条消息(共 32 条)

System.InvalidCastException: Unable to cast COM object of type 'System.__ComObject' to interface type 'Inventor.PartDocument'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{29F0D463-C114-11D2-B77F-0060B0F159EF}' failed due to the following error: 不支持此接口 (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)). 在 LmiRuleScript.Main() 在 Autodesk.iLogic.Exec.AppDomExec.ExecRuleInAssembly(Assembly assem) 在 iLogic.RuleEvalContainer.ExecRuleEval(String execRule)

上述为报错详细信息

27 条消息(共 32 条)

王老师,还是提示如下错误。帮忙分析下,谢谢!
System.InvalidCastException: 无法将类型为“System.__ComObject”的 COM 对象强制转换为接口类型“Inventor.PartDocument”。此操作失败的原因是对 IID 为“{29F0D463-C114-11D2-B77F-0060B0F159EF}”的接口的 COM 组件调用 QueryInterface 因以下错误而失败: 不支持此接口 (异常来自 HRESULT:0x80004002 (E_NOINTERFACE))。
在 LmiRuleScript.Main()
在 Autodesk.iLogic.Exec.AppDomExec.ExecRuleInAssembly(Assembly assem)
在 iLogic.RuleEvalContainer.ExecRuleEval(String execRule)

28 条消息(共 32 条)

用这段

'[ STP转换器设定
	Dim oSTEPTranslator As TranslatorAddIn = ThisApplication.ApplicationAddIns.ItemById("{90AF7F40-0C01-11D5-8E83-0010B541CD80}") 
	Dim oContext As TranslationContext = ThisApplication.TransientObjects.CreateTranslationContext
	Dim oOptions As NameValueMap = ThisApplication.TransientObjects.CreateNameValueMap
	']
	
	' 获取当前正在编辑的部件文档对象
 Dim assyDoc As AssemblyDocument = ThisApplication.ActiveDocument
   
    ' 获取当前部件文档所在的项目文件路径
    Dim 工作路径 As String = ThisDoc.WorkspacePath()   
 
 ' 遍历所有子部件对象
    Dim part As ComponentOccurrence	
    For Each part In assyDoc.ComponentDefinition.Occurrences
        ' 获取子部件的部件文档对象
        Dim partDoc  = part.Definition.Document      
        ' 获取零件属性字符串值		 
     	 Dim 类别 = partDoc.PropertySets.Item("Inventor Document Summary Information").Item("Category").Value
		 Dim 代号 = partDoc.PropertySets.Item("Design Tracking Properties").Item("Part Number").Value
		 Dim 描述 = partDoc.PropertySets.Item("Design Tracking Properties").Item("Description").Value      	 
        ' 如果类别的值为"机加件"或"钣金件"或"铝型材&亚克力",则进行导出操作
       If 类别 = "机加件" Or 类别 = "钣金件" Or 类别 = "铝型材&亚克力" Then
			'构建文件名           
			Dim 新文件名 = 工作路径 & "\PDF\" & 类别 & "\" & 代号 & "-" & 描述 & ".stp"
			'执行导出
			If oSTEPTranslator.HasSaveCopyAsOptions(ThisApplication.ActiveDocument, oContext, oOptions) Then
   		 		oOptions.Value("ApplicationProtocolType") = 3
				oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism
   			 Dim oData As DataMedium = ThisApplication.TransientObjects.CreateDataMedium
    			oData.FileName = 新文件名
				oSTEPTranslator.SaveCopyAs(partDoc, oContext, oOptions, oData)
		End If
        End If
		    Next

MsgBox ("完成导出。",,"iLogic")


If my post answers your question, please click the "Accept as Solution" button. This helps everyone find answers more quickly!
如果我的回帖解决了您的问题,请点击 "接受为解决方案" 按钮. 这可以帮助其他人更快的找到解决方案!


王 承之
Autodesk AGN [Inventor 俱乐部] Leader
Inventor Club | Bilibili


AGN L    EESignature

29 条消息(共 32 条)

王老师!目前上述代码可实现子零件分类导出stp,是否可以遍历子子零件属性,分类另存零件。

30 条消息(共 32 条)

可以的,得找个时间写一下


If my post answers your question, please click the "Accept as Solution" button. This helps everyone find answers more quickly!
如果我的回帖解决了您的问题,请点击 "接受为解决方案" 按钮. 这可以帮助其他人更快的找到解决方案!


王 承之
Autodesk AGN [Inventor 俱乐部] Leader
Inventor Club | Bilibili


AGN L    EESignature

31 条消息(共 32 条)

好的。感谢!

32 条消息(共 32 条)

本贴盖楼太高了,你可以先把本贴结束掉,另外再开一贴


If my post answers your question, please click the "Accept as Solution" button. This helps everyone find answers more quickly!
如果我的回帖解决了您的问题,请点击 "接受为解决方案" 按钮. 这可以帮助其他人更快的找到解决方案!


王 承之
Autodesk AGN [Inventor 俱乐部] Leader
Inventor Club | Bilibili


AGN L    EESignature

找不到想要的内容?向社区提问或分享您的知识。

到论坛发帖  

”