Dim As Document or As PartDocument ??

Dim As Document or As PartDocument ??

Anonymous
Not applicable
4,670 Views
4 Replies
Message 1 of 5

Dim As Document or As PartDocument ??

Anonymous
Not applicable

I'm having difficulties with accessing the Mass Properties of a part with this code.

 

Dim oDoc As Document = ThisApplication.ActiveDocument

Dim oMassProps As MassProperties
oMassProps = oDoc.ComponentDefinition.MassProperties

 

Which produces this error:

Member not found. (Exception from HRESULT: 0x80020003 (DISP_E_MEMBERNOTFOUND))

 

Changing the first line to this resolves the issue:

Dim oDoc As PartDocument = ThisApplication.ActiveDocument

 

However the code is part of a large loop which goes through all referenced documents of an assembly, so I can't use PartDocument as there are other document types also.

 

The strange thing is I have numerous part documents which don't produce the error. Its only this one, which I have attached for reference.

0 Likes
Accepted solutions (1)
4,671 Views
4 Replies
Replies (4)
Message 2 of 5

t_hascj
Autodesk
Autodesk

Hi Craig,

You need to use "as PartDocument" and "as AssemblyDocument". There is limitation for Inventor.Document object if you analyzing more types of document. The Document doesn't containts property ComponentDefinition.
Similar issue https://forums.autodesk.com/t5/inventor-customization/stuck-in-ilogic-with-isiassemblymember/m-p/742....


Thanks,
Jaroslav

0 Likes
Message 3 of 5

Anonymous
Not applicable

@t_hascj thank you

 

I guess I could work around the document type with a conditional statement, but just for my own understanding...

 

I've had no problems accessing the MassProperties of other documents of kPartDocumentObject type, do you know why this may be the case?

 

I'v attached a part where it functions without error.

0 Likes
Message 4 of 5

Anonymous
Not applicable

I thought it might be simple to use a conditional statement but now I'm not so sure. This is my structure:

 

Sub Main ()
' Get the active assembly.
Dim oAsmDoc As Document
oAsmDoc = ThisApplication.ActiveDocument

' Check for a non-part document
If oAsmDoc.DocumentType <> kAssemblyDocumentObject Then
      MsgBox ("The Active document must be an 'Assembly'!")
      Exit Sub
End If

 

' Get all of the referenced documents.
Dim oRefDocs As DocumentsEnumerator
oRefDocs = oAsmDoc.AllReferencedDocuments

 

Call OpTime(oAsmDoc)

 

' Iterate through the list of documents.
Dim oRefDoc As Document

 

' Iterate through all referenced documents beneath the active assembly (mixture of parts and assemblies)
For Each oRefDoc In oRefDocs

      Call OpTime(oRefDoc)

Next

End Sub

 

Sub OpTime (oDoc As Document)

 

oMassProps = oDoc.ComponentDefinition.MassProperties

 

End Sub

 

How could I define the highlighted part as a PartDocument or AssemblyDocument depending on the document type of referenced document?

 

 

0 Likes
Message 5 of 5

MechMachineMan
Advisor
Advisor
Accepted solution

Check out this blog:

 

http://adndevblog.typepad.com/manufacturing/2016/11/ilogic-activedocumentcomponentdefinition-throws-...

 


--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.

Justin K
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
0 Likes