Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.
Anonymous
2523 Views, 3 Replies

Measuring Area of a Surface Body

I have a group of surface bodies that I need to calculate the surface area of, and I am having trouble figuring out how to do it. The iProperties->Physical measurement for area shows as 0.000 mm^2, which is I assume because there are no solid bodies (just surfaces). My surfaces are complex and I haven't had much success thickening the surfaces (I can get it to work but it takes a huge amount of time that I'd rather not spend doing this).

 

What I am hoping to do is use a combination of the measure area tool and looping through all the faces of the model in order to measure the area, but I'm not sure how to do either of these things using the Inventor API.

 

Does anyone have any suggestions on how to do this? 

 

Thanks in advance!

Anonymous
in reply to: Anonymous

So I was able to figure it out reasonable successfully, and figured I'd share the code for anybody interested. The code cycles through all the faces of each surface, then runs the Measure Area command. I couldn't figure out how to read the value from the text box that pops up (and Application.MeasureTools doesn't have a GetArea function) so I need to copy the area into an input box manually. This then uses a mass/ sq.m density to calculate the mass of the surface and plug it into the Mass property of the part.

 

If anyone has suggestions on how to copy the area from the text box (or use another code snippet to measure the area) into a variable, that would be great!

 

Sub SurfaceMeasurement()

'Check all referenced docs
Dim oDoc As Inventor.Document
Dim oSurfaceBodies As WorkSurface
Dim oFace As Face
Dim oControlDef As ControlDefinition
Dim faceCollection As ObjectCollection
Dim area As Double
Dim density As Double
Dim mass As Double

mass = 0

Set oDoc = ThisApplication.ActiveDocument
oDoc.SelectSet.Clear

Set faceCollection = ThisApplication.TransientObjects.CreateObjectCollection(Null)

'set surface bodies visibility
For Each oSurfaceBodies In oDoc.ComponentDefinition.WorkSurfaces
'oSurfaceBodies.Visible = wfBoolean
For Each oFace In oSurfaceBodies.SurfaceBodies.Item(1).Faces
faceCollection.Add oFace
' oDoc.SelectSet.Select oFace
Next
oDoc.SelectSet.SelectMultiple faceCollection
Set oControlDef = ThisApplication.CommandManager.ControlDefinitions.Item("AppMeasureAreaCmd")
oControlDef.Execute
area = InputBox("Please enter the area (mm^2): ", "Area")
density = InputBox("Please enter the mass per m^2: ", "Density")
mass = mass + area * density * 0.000001
Next
MsgBox "The mass is " & CStr(mass) & " kg."


oDoc.ComponentDefinition.MassProperties.mass = mass

End Sub

nmunro
in reply to: Anonymous

You can obtain this information directly from the API. The attached part file has an included macro (Areas) that obtains the raw surface area for each face (in each surface body - only one body in this simple part). The code works for parts that are solids or surfaces.

 

The code is just the basics to show the information, you would have to handle units conversions (UnitsOfMeasure object in the Inventor API) and writing the information to a suitable place or otherwise using the data.

 

Neil

 

        


https://c3mcad.com

Anonymous
in reply to: nmunro

Thanks for the assistance. The Evaluator function allows reading of the face areas without having to type it in like my first attempt was!

 

I've copied the code if anyone wants to look at it. It uses the area to determine and assign a mass based on the surface area density that you assign through an input box.

 

Sub SurfaceMeasurement()

'Check all referenced docs
Dim oDoc As Inventor.Document
Dim oSurfaceBodies As WorkSurface
Dim oSurfaceBody As SurfaceBody
Dim oFace As Face
Dim density As Double
Dim mass As Double
Dim allArea As Double

mass = 0
allArea = 0
tcount = 0
Set oDoc = ThisApplication.ActiveDocument
oDoc.SelectSet.Clear

'set surface bodies visibility
For Each oSurfaceBodies In oDoc.ComponentDefinition.WorkSurfaces
For Each oSurfaceBody In oSurfaceBodies.SurfaceBodies

For Each oFace In oSurfaceBody.Faces

allArea = allArea + oFace.Evaluator.area * 100

Next

Next
Next

density = InputBox("Please enter the mass per m^2: ", "Density", 2.477)
mass = allArea * density * 0.000001
MsgBox "The mass is " & CStr(mass) & " kg."

oDoc.ComponentDefinition.MassProperties.mass = mass


End Sub