Inventor Customization

Reply
Mentor
Posts: 199
Registered: ‎07-28-2007
Message 1 of 3 (306 Views)
Accepted Solution

Change Mass Of Virtual Part

306 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

Valued Contributor
nttoan8187
Posts: 92
Registered: ‎06-29-2010
Message 2 of 3 (300 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
Posts: 199
Registered: ‎07-28-2007
Message 3 of 3 (285 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.

 

 

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Announcements
Are you interested in helping shape the Autodesk Community?
We’re looking at a few different ways to improve the “All Forums” landing page and need your feedback! If interested, please take a few minutes to fill out the following Usability Study. Thank you for your time!

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Ask the Community


Inventor Exchange Apps

Created by the community for the community, Autodesk Exchange Apps for Autodesk Inventor helps you achieve greater speed, accuracy, and automation from concept to manufacturing.

Connect with Inventor

Twitter

Facebook

Blogs

Pinterest

Youtube