Inventor API Volume using VB.NET

Inventor API Volume using VB.NET

ivanrips
Participant Participant
1,244 Views
5 Replies
Message 1 of 6

Inventor API Volume using VB.NET

ivanrips
Participant
Participant

Hi;

How can I show the Volume in the form when run my *.exe

I am using VB.net

 

I try this:

 

Dim Part1 As Inventor.MassProperties
Part1 = partDoc.ComponentDefinition.MassProperties
txtvolume.Text = Part1.Volume

 

Regards

0 Likes
Accepted solutions (1)
1,245 Views
5 Replies
Replies (5)
Message 2 of 6

ekinsb
Alumni
Alumni
Accepted solution

It seems like the code you have should work.  You didn't say what wasn't working; if you're not getting any value or the value you're getting is wrong.  When Inventor returns values they're always based on internal units, which for lengths is centimeters which means the volume will be in centimeters cubed.  You can use the UnitsOfMeasure object to convert this into whatever the current default length unit is.  The code to do that is below.

 

Dim massProps As MassProperties
massProps = partDoc.ComponentDefinition.MassProperties
    
Dim uom As UnitsOfMeasure
uom = partDoc.UnitsOfMeasure
    
Dim defaultLength As String
defaultLength = uom.GetStringFromType(uom.LengthUnits)
txtvolume.Text = uom.GetStringFromValue(massProps.Volume, defaultLength & "^3")

Brian Ekins
Inventor and Fusion 360 API Expert
Mod the Machine blog
Message 3 of 6

ivanrips
Participant
Participant

 Thank you very much !!! now it works correctly
One question more, if my geometry is a cube, How Can I obtain in a textbox the area of two surfaces using vb.net?

Regards

 

0 Likes
Message 4 of 6

ivanrips
Participant
Participant

How Can I update the volume when I modify the geometry?

 

My first volume is correct but after I change the geometry in my form and the volume of geometry no update.

 

Thank you very much in advance

0 Likes
Message 5 of 6

Jef_E
Collaborator
Collaborator

You should add an event to your application.

 

PartEvents.OnSurfaceBodyChanged Event

PartEvents.OnSurfaceBodyChanged Event

Parent Object: PartEvents

Description

The OnSurfaceBodyChanged event notifies the client when the surface and solid geometry of a part geometrically changes.

Syntax

PartEvents.OnSurfaceBodyChanged( Context As NameValueMap, BeforeOrAfter As EventTimingEnum, HandlingCode As HandlingCodeEnum )

Parameters

Name Description
Context Input object that can be used to determine the context of why the event fired. Additional information is provided through this argument to help in understanding the context of the notification. Name = "Undo". Value = A Boolean indicating if the change occurred as the result of an undo operation. This context value is only provided in the case where the change does occur because of an undo operation, so the value will always be True.
BeforeOrAfter Input indicating when the event is being fired. Notification is only sent after the surface body has changed, so this value is always kAfter.
HandlingCode  

Remarks

If there are multiple surface bodies within a part, (solid and/or work surfaces), this notification is sent if any of them change.

Version

Introduced in Inventor version 4



Please kudo if this post was helpfull
Please accept as solution if your problem was solved

Inventor 2014 SP2
0 Likes
Message 6 of 6

ivanrips
Participant
Participant

hi;
Thank you very much
I try:
PartEvents.OnSurfaceBodyChanged Event
but appears: error PartEvents is not declared


I change to:

Dim partEvents As Inventor.PartEvents
partEvents =

 

but I have not success, I using vb.net.

 

Thanks