Get Item Weight From Partslist

Get Item Weight From Partslist

Anonymous
Not applicable
778 Views
4 Replies
Message 1 of 5

Get Item Weight From Partslist

Anonymous
Not applicable

Hi , I'm new with ilogic code. I'm recently working on a code to automatic sort the Partslist inside a IDW.

 

The Partslist doesn't have a mass column. but in order to sort it i need the weight for each row. so i write following code.

 

SyntaxEditor Code Snippet

On Error Resume Next 

Dim oDrawDoc As DrawingDocument
oDrawDoc = ThisApplication.ActiveDocument

Dim oPartsList1 As PartsList
oPartsList1 = oDrawDoc.ActiveSheet.PartsLists.Item(1)

Dim oRow As PartsListRow

Dim oAssyDoc As AssemblyDocument

Dim Mass As Double

For Each oRow In oPartsList1.PartsListRows

MessageBox.Show(oRow.ReferencedFiles.Item(1).DocumentType)

oAssyDoc = oRow.ReferencedFiles.Item(1)
oAssyDoc.ComponentDefinition.MassProperties.Accuracy = k_Medium
Mass = oAssyDoc.ComponentDefinition.MassProperties.Mass

MessageBox.Show(Mass)

Next

 

I can see the referenced file type 12290 (ipt) and 12291 (iam). but the weight is always 0.

 

can anyone help me with that ?

 

Thanks

 

 

 

 

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

bradeneuropeArthur
Mentor
Mentor
Declare this
Dim Mass As inventor.massproperties

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background


Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:
Drawing List!|
Toggle Drawing Sheet!|
Workplane Resize!|
Drawing View Locker!|
Multi Sheet to Mono Sheet!|
Drawing Weld Symbols!|
Drawing View Label Align!|
Open From Balloon!|
Model State Lock!
Posts and Ideas:
My Ideas|
Dimension Component!|
Partlist Export!|
Derive I-properties!|
Vault Prompts Via API!|
Vault Handbook/Manual!|
Drawing Toggle Sheets!|
Vault Defer Update!

! For administrative reasons, please mark a "Solution as solved" when the issue is solved !


 


EESignature

0 Likes
Message 3 of 5

Anonymous
Not applicable

@bradeneuropeArthur, thanks for your reply. 

 

I have tried to declare the mass, but it still not working.

 

I solved the problem by adding an column of Mass in the Partslist and deleted it afterwards.  

 

I checked the ReferencedFiles Property (it is a hidden one) under the PartsListRow using the Object Browser in VBA environment. 

and it is ReferencedFileDescriptors Type and only contain Application , Count, Item, ItemByName, Type. So there isn't Mass Property or anything else like the Normal Document file. 

 

Probably that's why my code doesn't work.

 

 2018-07-16 11_07_22-Microsoft Visual Basic for Applications - Default.ivb - [Object Browser].png

 

2018-07-16 11_09_11-Microsoft Visual Basic for Applications - Default.ivb - [Object Browser].png

 

0 Likes
Message 4 of 5

dgreatice
Collaborator
Collaborator
Accepted solution

Hi,

 

try this:

 

Public Sub GetMassFromPartList()
    Dim oApp As Application
    Dim oDD As DrawingDocument
    Dim oSht As Sheet
    Dim oPL As PartsList
    Dim oRow As PartsListRow
    Dim oDoc As Document
    Dim oPD As PartDocument
    Dim oAD As AssemblyDocument
    Dim oPCD As PartComponentDefinition
    Dim oACD As AssemblyComponentDefinition
   
    Set oApp = ThisApplication
    Set oDD = oApp.ActiveDocument
    Set oSht = oDD.ActiveSheet
    Set oPL = oSht.PartsLists.Item(1)
   
    For Each oRow In oPL.PartsListRows
        Set oReffDoc = oRow.ReferencedFiles.Item(1)
        Set oDoc = oReffDoc.ReferencedDocument
        If oDoc.DocumentType = kAssemblyDocumentObject Then
            Set oAD = oDoc
            Set oACD = oAD.ComponentDefinition
            MsgBox (Round(oACD.MassProperties.Mass, 2) & " Kg")
        ElseIf oDoc.DocumentType = kPartDocumentObject Then
            Set oPD = oDoc
            Set oPCD = oPD.ComponentDefinition
            MsgBox (Round(oPCD.MassProperties.Mass, 2) & " Kg")
        End If
    Next
   
   
End Sub

Please use the ACCEPT AS SOLUTION or KUDOS button if my Idea helped you to solve the problem.

Autodesk Inventor Professional Certified 2014
Message 5 of 5

Anonymous
Not applicable

Thanks @dgreatice, you are the best.

 

I was trying to do the same thing, but wasn't success. i thought it just stop at ReferencedFiles

 

Now i understand that the property chains are 

 

PartsListRows.Partslists.ReferencedFiles.Item.ReferencedDocument.ComponentDeinition.MassProperty.Mass

 

Thanks

 

 

0 Likes