How to get the area of a closed sketch in Inventor VBA

How to get the area of a closed sketch in Inventor VBA

Anonymous
Not applicable
938 Views
3 Replies
Message 1 of 4

How to get the area of a closed sketch in Inventor VBA

Anonymous
Not applicable
Hi

There is a closed sketch from a flat surface contour, how to get the area of this 2D sketch in Inventor VBA?

Thanks.
0 Likes
939 Views
3 Replies
Replies (3)
Message 2 of 4

Anonymous
Not applicable
Presuming there is no voids inside the sketch this will show the last made
sketch's area in cm^

If there are more than one profile in the sketch you would have to loop
through each profile and somehow decide if it is excluded or not.

Public Sub SketchArea()

Dim oDoc As PartDocument
Set oDoc = ThisApplication.ActiveDocument

Dim oCompDef As ComponentDefinition
Set oCompDef = oDoc.ComponentDefinition

Dim oSketch As Sketch
Set oSketch = oCompDef.Sketches(oCompDef.Sketches.Count - 1)

Dim oProfile As Profile
Set oProfile = oSketch.Profiles(1)

Dim oArea As Double
oArea = oProfile.RegionProperties.Area

MsgBox "The area of the sketch is " & oArea & "cm^2"

End Sub


--
KWiKMcad
Kent Keller
"allenliuyy" wrote in message news:6325084@discussion.autodesk.com...
Hi

There is a closed sketch from a flat surface contour, how to get the area of
this 2D sketch in Inventor VBA?

Thanks.
0 Likes
Message 3 of 4

Anonymous
Not applicable
Thank you, Kent. It works.

If there are 5 sketches called "sketch1", "sketch2", ...."sketch5" in one part, how to get all these sketches area one by one. I tried the similar way, but I could not figure it out. Thanks again.
0 Likes
Message 4 of 4

Anonymous
Not applicable
Try something along the lines of

For each oSketch in oCompDef.sketches

"Process sketch

Next

--
KWiKMcad
Kent Keller
"allenliuyy" wrote in message news:6326033@discussion.autodesk.com...
Thank you, Kent. It works.

If there are 5 sketches called "sketch1", "sketch2", ...."sketch5" in one
part, how to get all these sketches area one by one. I tried the similar
way, but I could not figure it out. Thanks again.
0 Likes