Picking up the solid volume by name

Picking up the solid volume by name

manu.marjanen
Advocate Advocate
756 Views
5 Replies
Message 1 of 6

Picking up the solid volume by name

manu.marjanen
Advocate
Advocate

How do i get only "solid3" volume, by using iLogic?

manumarjanen_0-1642142483026.png

 

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

Michael.Navara
Advisor
Advisor

You can read volume of all individual bodies, or one body accessed by its index (order) or its name

 

Dim part As PartDocument = ThisDoc.Document

'Get volume of individual bodies
Dim precisionPercent As Double = 0.01
For Each oBody As SurfaceBody In part.ComponentDefinition.SurfaceBodies
    Logger.Debug(String.Format("{0}{2}{1}", oBody.Name, oBody.Volume(precisionPercent), vbTab))
Next

'Get volume for individual body by its name
Dim bodyName As String = part.ComponentDefinition.SurfaceBodies(1).Name

Dim bodyByName As SurfaceBody = part.ComponentDefinition.SurfaceBodies.OfType(Of SurfaceBody).FirstOrDefault(Function(b) b.Name = bodyName)
If bodyByName Is Nothing Then
    Logger.Warn("Body not found")
Else
    Logger.Info(bodyByName.Volume(precisionPercent))
End If
0 Likes
Message 3 of 6

manu.marjanen
Advocate
Advocate



 

 

0 Likes
Message 4 of 6

manu.marjanen
Advocate
Advocate

Can the "solid3" volume data be transferred to the parameter table?

 

manumarjanen_0-1642153265941.png

 

0 Likes
Message 5 of 6

Michael.Navara
Advisor
Advisor
Accepted solution
Dim part As PartDocument = ThisDoc.Document

'Get volume of individual bodies
Dim precisionPercent As Double = 0.01
Dim bodyName As String = "Solid3"
Dim solidVolume As Double = 0

'Get volume for individual body by its name
Dim bodyByName As SurfaceBody = part.ComponentDefinition.SurfaceBodies.OfType(Of SurfaceBody).FirstOrDefault(Function(b) b.Name = bodyName)
If bodyByName Is Nothing Then
    Logger.Warn("Body not found")
Else
	solidVolume = bodyByName.Volume(precisionPercent)
    Logger.Info(solidVolume)
End If
solidVolume *= 1000 'Convert [cm3] to [dm3]([l])
Parameter("Solid3_Volume") = solidVolume
0 Likes
Message 6 of 6

cookie
Contributor
Contributor

Great routine @Michael.Navara , works a treat.

 

Now to work out how to run the routine whenever a change occurs on the part

0 Likes