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: 

ipt: how to get mass of one solid (not iPropety mass of all solids in part)

4 REPLIES 4
SOLVED
Reply
Message 1 of 5
eljoseppo
1803 Views, 4 Replies

ipt: how to get mass of one solid (not iPropety mass of all solids in part)

Hi, simple question:

how to get in iLogic a mass od one solid? I have a ipt file with two solids, I need mass just one of them. The drawing will explain everything.

 

Z-Elevator.png

 

 

Now I'm using this code, which was OK before I add a "CUT" feature.

'====================
Masa=Measure.Area("FIELD") 
mass=Val(Masa)/1000000 'cm3->m3
density=0.83
mass = mass * density * width 
Masa=CStr(mass) ' mass of one pocket
'=====================

I'm also attaching tha part. Please move End of part to the end of history, it was to big to post here.

The parameters names are in Polish, don't be afraid 😉 Masa = mass

 

 

 

4 REPLIES 4
Message 2 of 5

SurfaceBody.Volume Property returns volume in base units that allows you estimate desired mass of this solid body.


Vladimir Ananyev
Developer Technical Services
Autodesk Developer Network

Message 3 of 5

Thanks for advice,

how I get to this SurfaceBody?

 

I've tried

Masa=oDoc.ComponentDefinition.Document.ComponentDefinitions.Item(1).SufraceBodies.Item(2).ComponentDefinition.MassProperties.Area

 But with no result..

Message 4 of 5

The following sample prints the volume of the first two surface bodies in the active part.   You should play a little to find appropriate RelErr value (see Inventor API help).

Private Sub Test()

  Dim oDoc As PartDocument
  Set oDoc = ThisApplication.ActiveDocument
  
  Dim oDef As PartComponentDefinition
  Set oDef = oDoc.ComponentDefinition
  
  Dim RelErr As Double
  RelErr = 0.01
  
  Dim oBody As SurfaceBody
  Dim V1 As Double, V2 As Double

  Set oBody = oDef.SurfaceBodies.Item(1)
  V1 = oBody.Volume(RelErr)
  Debug.Print V1
  
  Set oBody = oDef.SurfaceBodies.Item(2)
  V2 = oBody.Volume(RelErr)
  Debug.Print V2

End Sub

The simplest way to get density (g/mm^3) :

     Dim Density1 As Double
     Density1 = oDef.material.Density

 

Cheers,


Vladimir Ananyev
Developer Technical Services
Autodesk Developer Network

Message 5 of 5

 

Just posting this code to this old thread for reference:

 

'define the document as a component definition
Dim oCompDef as ComponentDefinition
oCompDef = ThisDoc.Document.ComponentDefinition

'define the solidbody
Dim oBody As SurfaceBody

'define the solid body name to look for
Dim body As String
sBody = "Solid1"

Dim oVolume As Double
Dim oDensity As Double
oDensity = oCompDef.Material.Density

oConversion = 0.00220462 'gram to lbs

'get mass of named solid body
i = 1
For Each SurfaceBody In oCompDef.SurfaceBodies
	oBody = oCompDef.SurfaceBodies.Item(i)
	If sBody = oBody.Name Then
		oVolume = oBody.Volume(0.001) ' (g/mm^3)
		oMass = Round(oVolume * oDensity * oConversion,2)
		MessageBox.Show("Mass of " & oBody.Name & " = " & oMass & " lbmass", "iLogic")
	End If
i = i +1
Next

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

Post to forums  

Autodesk Design & Make Report