Inventor Customization

Reply
Mentor
matt_jlt
Posts: 216
Registered: ‎07-28-2007
Message 1 of 3 (327 Views)
Accepted Solution

Change Mass Of Virtual Part

327 Views, 2 Replies
06-16-2011 11:13 PM

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

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

Valued Contributor
nttoan8187
Posts: 92
Registered: ‎06-29-2010
Message 2 of 3 (321 Views)

Re: Change Mass Of Virtual Part

06-17-2011 12:19 AM 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
Mentor
matt_jlt
Posts: 216
Registered: ‎07-28-2007
Message 3 of 3 (306 Views)

Re: Change Mass Of Virtual Part

06-19-2011 05:00 PM 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.

 

 

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.
Need installation help?

Start with some of our most frequented solutions or visit the Installation and Licensing Forum to get help installing your software.