Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Change Mass Of Virtual Part

3 REPLIES 3
SOLVED
Reply
Message 1 of 4
matt_jlt
928 Views, 3 Replies

Change Mass Of Virtual Part

I have a virtual part inside an assembly, I can change all of the normal properties but can't manage to work out how to get the mass to change. I can see the mass and volume properties but they dont seem to update etc. my code is as below.

 

Option Explicit

Sub Main()


Dim oADoc As AssemblyDocument
Dim oCompOcc As ComponentOccurrence
Dim oVCompDef As VirtualComponentDefinition
Dim oMassStr As String
Dim oPropPartNo As Property
Dim oPropDesc As Property
Dim oPropMass As Property

Set oADoc = ThisApplication.ActiveDocument
oMassStr = oADoc.ComponentDefinition.MassProperties.Mass

Debug.Print (oMassStr)
If oMassStr > 4000 Then
Debug.Print ("True")
Else
Debug.Print ("False")
End If

For Each oCompOcc In oADoc.ComponentDefinition.Occurrences
If oCompOcc.Definition.Type = "100675072" Then ' Check to see if Virtual Part (Don't want to use enumerator)
Set oVCompDef = oCompOcc.Definition
Set oPropPartNo = oVCompDef.PropertySets.Item("Design Tracking Properties").Item("Part Number")
Set oPropDesc = oVCompDef.PropertySets.Item("Design Tracking Properties").Item("Description")
Set oPropMass = oVCompDef.PropertySets.Item("Design Tracking Properties").Item("Mass")
oPropPartNo.Value = "1234"
oPropDesc.Value = "4567"
oPropMass.Value = 8000
End If
Next
oADoc.Update
End Sub

 

Any help is much appreciated. Thanks.

Matt

3 REPLIES 3
Message 2 of 4
nttoan8187
in reply to: matt_jlt

Hope this can help us, just need to change it a little for suitability with your need.

 

 

Public Sub GetPartMassProps()
    ' Set a reference to the part document.
    ' This assumes a part document is active.
    Dim oPartDoc As PartDocument
    Set oPartDoc = ThisApplication.ActiveDocument

    ' Set a reference to the mass properties object.
    Dim oMassProps As MassProperties
    Set oMassProps = oPartDoc.ComponentDefinition.MassProperties

    ' Set the accuracy to medium.
    oMassProps.Accuracy = k_Medium

 

    ' Set a reference to the mass properties object.
    Dim oMass As Double
    oMass = oMassProps.Mass

 

   Msgbox(oMass)

 

End Sub

Please mark this answer as Problem Solved if it solves your question.
-----------------------------------------------------------------------------------------
Toan
Inventor API
Message 3 of 4
matt_jlt
in reply to: nttoan8187

Thanks, you code helped. When i looked at it I realised i had gone too far into the part where I was looking for the mass properties (I was looking inside the virtual part's definition). I found the mass properties in the component occurence (from the assembly it is inside) and used your code slightly tweaked to be:

 

Dim oCompOcc As ComponentOccurrence

Dim oMassProps As MassProperties
Dim oMass As Double

 

Set oMassProps = oCompOcc.MassProperties

 

oMass = 458 ' New Mass Number I want to override with
oMassProps.Mass = oMass

 

Thanks again, Matt.

 

 

Message 4 of 4
chihchiap
in reply to: nttoan8187

改變Mass後,如何在回到自動計算Mass

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums