Get Face’s parametric center

<?xml encoding=”UTF-8″>By Adam Nagy

Each face has an evaluator that can be used to check the min and max parametric values on it. If you calculate the middle of that, then you can get to the center of the Face

Here is a VBA sample that places a WorkPoint at the calculated center of the currently selected Face of the PartDocument.

Sub GetFaceCenter()
Dim d As PartDocument
Set d = ThisApplication.ActiveDocument
Dim f As Face
Set f = d.SelectSet(1)
Dim s As SurfaceEvaluator
Set s = f.Evaluator
Dim b As Box2d
Set b = s.ParamRangeRect
' Get center parameter
Dim p(1) As Double
p(0) = b.MinPoint.x + (b.MaxPoint.x - b.MinPoint.x) / 2
p(1) = b.MinPoint.y + (b.MaxPoint.y - b.MinPoint.y) / 2
' Convert param to point
Dim pt(2) As Double
Call s.GetPointAtParam(p, pt)
' Add a workpoint
Dim t As TransientGeometry
Set t = ThisApplication.TransientGeometry
Dim wpt As Point
Set wpt = t.CreatePoint(pt(0), pt(1), pt(2))
Call d.ComponentDefinition.WorkPoints.AddFixed(wpt)
End Sub

This is what I got for the various faces in one of the sample part documents:

Facecenter

 


Comments

Leave a Reply

Discover more from Autodesk Developer Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading