Inventor API: Get the Volume of Surfacebody in MultiSolid IPT File

Inventor API: Get the Volume of Surfacebody in MultiSolid IPT File

Khoa_NguyenDang
Advocate Advocate
1,214 Views
5 Replies
Message 1 of 6

Inventor API: Get the Volume of Surfacebody in MultiSolid IPT File

Khoa_NguyenDang
Advocate
Advocate

Hi all guys, does anybody had got the Volume property of the Surfacebody (Solid) in the Multisolid IPT File 

Like in the picture

Please help me in this case if you have a solution 

Thank you so much 


 
Updating Media

 

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

CGBenner
Community Manager
Community Manager
Accepted solution

@Khoa_NguyenDang 

 

Your image did not fully load.

Did you find a post helpful? Then feel free to give likes to these posts!
Did your question get successfully answered? Then just click on the 'Accept solution' button.  Thanks and Enjoy!


Chris Benner
Community Manager

Message 3 of 6

J-Camper
Advisor
Advisor
Accepted solution

@Khoa_NguyenDang 

 

This will display the volume of each Solidbody in a part document:

Sub Main
	If ThisApplication.ActiveDocumentType <> kPartDocumentObject Then MessageBox.Show("This rule is designed to only work in part documents.", "Wrong Document Type") : Exit Sub
	Dim pDef As PartComponentDefinition = ThisApplication.ActiveDocument.ComponentDefinition
	
	If pDef.SurfaceBodies.Count < 1 Then MessageBox.Show("No Solids Exist", "Termination") : Exit Sub

	For Each sb As SurfaceBody In pDef.SurfaceBodies
		MessageBox.Show("Internal Calculation [cm^3]: " & Round(sb.Volume(0.0001), 5) & vbCrLf & _
						"Converted Calculation [in^3]: " & Round((sb.Volume(0.0001)/(2.54^3)), 5)	, "Volume for " & sb.Name & ":")
	Next
	
End Sub

 

Let me know if you have any questions.

0 Likes
Message 4 of 6

Khoa_NguyenDang
Advocate
Advocate

@CGBenner thank for you remind

I attach the picture here 

Khoa_NguyenDang_0-1608089712699.png

If you have the solution, please help me for this 

0 Likes
Message 5 of 6

Khoa_NguyenDang
Advocate
Advocate

@J-Camper 

Thank for you help, i see you use the below code to get the volume, so when is the Round method you use, I use C# so do you have a sample code in C# 

Round(sb.Volume(0.0001), 5)

 Thank and wait for your reply

0 Likes
Message 6 of 6

J-Camper
Advisor
Advisor
Accepted solution

@Khoa_NguyenDang 

 

I'm not familiar enough with C# to tell you how to round a variable, but Round(###, 5) rounds a number to 5 decimal places.   You can take Round(..., 5) out and just use:

sb.Volume(0.0001)

It will just have roughly 10 decimal places, but I'm not sure if that will let you use it in C#

0 Likes