- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Accessing component definition of Weldment
I am running a for loop through AllReferencedDocuments in an assembly. Trying to access the component definition of any weldment assemblies using this line:
Dim wcd As WeldmentComponentDefinition = oRefDoc.ComponentDefinition
But I receive an error saying this:
Member not found. (Exception from HRESULT: 0x80020003 (DISP_E_MEMBERNOTFOUND))
I can write a rule inside the weldment assembly and access it from there:
Dim oAssDoc As AssemblyDocument
oAssDoc = ThisApplication.ActiveDocument
Dim wcd As WeldmentComponentDefinition
wcd = oAssDoc.ComponentDefinition
But I need to access the component definition of any weldment assemblies from my top level rule, how do I do it?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Is there a good reason you need to use the specific WeldmentComponentDefinition instead of the generic ComponentDefinition?
From my messing around with this, it appears to work just fine.... I'm assuming refdoc probably isn't actually a weldmentcomponentdefinition like you expect it to be.
Sub Main() Dim oCD As ComponentDefinition For Each oSubDoc in ThisDoc.Document.AllReferencedDocuments If oSubDoc.DocumentType = kAssemblyDocumentObject 'AssemblyDocument If oSubDoc.ComponentDefinition.Type = ObjectTypeEnum.kWeldmentComponentDefinitionObject Dim oWCD As WeldmentComponentDefinition = oSubDoc.ComponentDefinition oCD = oWCD MsgBox(oWCD.Document.FullFileName) Goto Continue1 Else Dim oACD As AssemblyComponentDefinition = oSubDoc.ComponentDefinition oCD = oACD End If Else 'Part Doc If oSubDoc.ComponentDefinition.Type = ObjectTypeEnum.kSheetMetalComponentDefinitionObject Dim oSCD As SheetMetalComponentDefinition = oSubDoc.ComponentDefinition oCD = oSCD Else Dim oPCD As PartComponentDefinition = oSubDoc.ComponentDefinition oCD = oPCD End If End If Next Continue1: MsgBox(oCD.Document.FullFileName) End Sub 'kVirtualComponentDefinitionObject - 100675072 'kWeldmentComponentDefinitionObject - 100673280 'kAssemblyComponentDefinitionObject - 100663808 'kPartComponentDefinitionObject - 83886592 'kSheetMetalComponentDefinitionObject - 150995200
--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.
Inventor 2018.2.3, Build 227 | Excel 2013+ VBA
ERP/CAD Communication | Custom Scripting
Machine Design | Process Optimization
iLogic/Inventor API: Autodesk Online Help | API Shortcut In Google Chrome | iLogic API Documentation
Vb.Net/VBA Programming: MSDN | Stackoverflow | Excel Object Model
Inventor API/VBA/Vb.Net Learning Resources: Forum Thread
Sample Solutions:Debugging in iLogic ( and Batch PDF Export Sample ) | API HasSaveCopyAs Issues |
BOM Export & Column Reorder | Reorient Skewed Part | Add Internal Profile Dogbones |
Run iLogic From VBA | Batch File Renaming| Continuous Pick/Rename Objects
Local Help: %PUBLIC%\Documents\Autodesk\Inventor 2018\Local Help
Ideas: Dockable/Customizable Property Browser | Section Line API/Thread Feature in Assembly/PartsList API Static Cells | Fourth BOM Type
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I get the same error with the code you just sent, traced it to this line:
Sub Main() Dim oCD As ComponentDefinition For Each oSubDoc in ThisDoc.Document.AllReferencedDocuments If oSubDoc.DocumentType = kAssemblyDocumentObject 'AssemblyDocument If oSubDoc.ComponentDefinition.Type = ObjectTypeEnum.kWeldmentComponentDefinitionObject ' 'Dim oWCD As WeldmentComponentDefinition = oSubDoc.ComponentDefinition ' 'oCD = oWCD ' 'MsgBox(oWCD.Document.FullFileName) ' 'Goto Continue1 ' Else ' Dim oACD As AssemblyComponentDefinition = oSubDoc.ComponentDefinition ' oCD = oACD ' End If ' Else 'Part Doc ' If oSubDoc.ComponentDefinition.Type = ObjectTypeEnum.kSheetMetalComponentDefinitionObject ' Dim oSCD As SheetMetalComponentDefinition = oSubDoc.ComponentDefinition ' oCD = oSCD ' Else ' Dim oPCD As PartComponentDefinition = oSubDoc.ComponentDefinition ' oCD = oPCD End If End If Next 'Continue1: 'MsgBox(oCD.Document.FullFileName) End Sub
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Ok. So is there anything special about the document it is failing on, or is it definitely failing for every document?
--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.
Inventor 2018.2.3, Build 227 | Excel 2013+ VBA
ERP/CAD Communication | Custom Scripting
Machine Design | Process Optimization
iLogic/Inventor API: Autodesk Online Help | API Shortcut In Google Chrome | iLogic API Documentation
Vb.Net/VBA Programming: MSDN | Stackoverflow | Excel Object Model
Inventor API/VBA/Vb.Net Learning Resources: Forum Thread
Sample Solutions:Debugging in iLogic ( and Batch PDF Export Sample ) | API HasSaveCopyAs Issues |
BOM Export & Column Reorder | Reorient Skewed Part | Add Internal Profile Dogbones |
Run iLogic From VBA | Batch File Renaming| Continuous Pick/Rename Objects
Local Help: %PUBLIC%\Documents\Autodesk\Inventor 2018\Local Help
Ideas: Dockable/Customizable Property Browser | Section Line API/Thread Feature in Assembly/PartsList API Static Cells | Fourth BOM Type
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Just tried creating a new blank weldment from scratch and it worked for that. Not sure what's wrong with the original, I converted it to a weldment from a standard assembly.
In the one that's giving me issues I can access the component definition from this rule inside it, so I don't know why it doesn't like it from my other rule.
Dim oAssDoc As AssemblyDocument oAssDoc = ThisApplication.ActiveDocument Dim wcd As WeldmentComponentDefinition wcd = oAssDoc.ComponentDefinition Dim oEachWeldB As WeldBead WeldCount = wcd.Welds.WeldBeads.Count MsgBox(WeldCount)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I saved a copy of the problem assembly, replaced the original with the copy in my assembly, ran the rule and it works fine on that. Swapped the copy back to the original, ran the rule and it fails. Both files are identical apart from their filename.
![]()
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I'm curious how it works if you try it just typed as ComponentDefinition
Dim oAssDoc As AssemblyDocument oAssDoc = ThisApplication.ActiveDocument Dim wcd As ComponentDefinition wcd = oAssDoc.ComponentDefinition Dim oEachWeldB As WeldBead WeldCount = wcd.Welds.WeldBeads.Count MsgBox(WeldCount)
--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.
Inventor 2018.2.3, Build 227 | Excel 2013+ VBA
ERP/CAD Communication | Custom Scripting
Machine Design | Process Optimization
iLogic/Inventor API: Autodesk Online Help | API Shortcut In Google Chrome | iLogic API Documentation
Vb.Net/VBA Programming: MSDN | Stackoverflow | Excel Object Model
Inventor API/VBA/Vb.Net Learning Resources: Forum Thread
Sample Solutions:Debugging in iLogic ( and Batch PDF Export Sample ) | API HasSaveCopyAs Issues |
BOM Export & Column Reorder | Reorient Skewed Part | Add Internal Profile Dogbones |
Run iLogic From VBA | Batch File Renaming| Continuous Pick/Rename Objects
Local Help: %PUBLIC%\Documents\Autodesk\Inventor 2018\Local Help
Ideas: Dockable/Customizable Property Browser | Section Line API/Thread Feature in Assembly/PartsList API Static Cells | Fourth BOM Type