Getting the surface area of a face (like the measure tool) in Code

Getting the surface area of a face (like the measure tool) in Code

NachoShaw
Advisor Advisor
746 Views
2 Replies
Message 1 of 3

Getting the surface area of a face (like the measure tool) in Code

NachoShaw
Advisor
Advisor

Hi

 

i need to be able to get the surface area of a part. i can get it using the measure tool and selecting the 'Measure Area' command but can i get the value i need via code only?

 

area.JPG

 

i actually need to iterate all faces on a part to find the largest one. 

 

Does anyboby have any ideas or can help?

 

 

 

Thanks

 

 

Nigel

 

Nacho
Automation & Design Engineer

Inventor automation Programmer (C#, VB.Net / iLogic)
Furniture, Sheet Metal, Structural, Metal fab, Tradeshow, Fabrication, CNC

EESignature


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.


0 Likes
747 Views
2 Replies
Replies (2)
Message 2 of 3

nmunro
Collaborator
Collaborator

 

Something like so (VB.NET). Covers parts with multiple solid bodies.

 

Dim doc As PartDocument = Nothing

Dim bodies As SurfaceBodies = Nothing

Dim faces As Faces = Nothing

Dim maxArea AsDouble = 0.0

Dim faceArea AsDouble = 0.0

Dim bigFace As Face = Nothing

 

doc = <get a reference to part document>

bodies = doc.ComponentDefinition.SurfaceBodies

For Each body As SurfaceBody In bodies

    For Each bodyFace As Face In body.Faces

        faceArea = bodyFace.Evaluator.Area

        If faceArea > maxArea Then

            bigFace = bodyFace

            maxArea = faceArea

        End If

    Next

Next

        


https://c3mcad.com

Message 3 of 3

NachoShaw
Advisor
Advisor
Hi

Thanks for that. I had managed to muster up a routine and I had found the evaluator.area about 2 hours ago. I made a variable to store the area on a condition that it could only be stored if the value was higher than the previously stored area. That way I would filter the highest (largest) face. Your code looks smaller than mine 🙂

I added in a small routine to highlight the largest face at the end but I'm struggling with making it a selected face 🙂


Thanks for the code





Nigel

Nacho
Automation & Design Engineer

Inventor automation Programmer (C#, VB.Net / iLogic)
Furniture, Sheet Metal, Structural, Metal fab, Tradeshow, Fabrication, CNC

EESignature


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.


0 Likes