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

try this:

Dim doc As PartDocument = ThisDoc.Document
Dim face As Face = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kPartFaceFilter, "")
Dim camera As Camera = ThisApplication.ActiveView.Camera

'get the midpoint param from selected surface
Dim paramRangeRect As Box2d = face.Evaluator.ParamRangeRect
Dim params(1) As Double
params(0) = (paramRangeRect.MaxPoint.X + paramRangeRect.MinPoint.X) / 2
params(1) = (paramRangeRect.MaxPoint.Y + paramRangeRect.MinPoint.Y) / 2

'get point on surface at param
Dim points(2) As Double
face.Evaluator.GetPointAtParam(params, points)
Dim target As Point = ThisApplication.TransientGeometry.CreatePoint(points(0), points(1), points(2))

' next line is only for debug to show what the camera target is 
doc.ComponentDefinition.WorkPoints.AddFixed(target)
camera.Target = target

'get the normal of the surface at target point
'translate target point with normal-vector to eye point
Dim normals(2) As Double
face.Evaluator.GetNormal(params, normals)
Dim normal As Vector = ThisApplication.TransientGeometry.CreateVector(normals(0), normals(1), normals(2))
Dim eye As Point = target
eye.TranslateBy(normal)

' next line is only for debug to show what the camera eye is 
doc.ComponentDefinition.WorkPoints.AddFixed(eye)
camera.Eye = eye

'you might want to set also the upvector to rotate the view to something more sensible.
'but i dont know how....
'camera.UpVector = ???

camera.ApplyWithoutTransition()

' i tryed to soom to selected surface with the camera but did not manage
' therefor this hack
doc.SelectSet.Clear()
doc.SelectSet.Select(face)
ThisApplication.CommandManager.ControlDefinitions.Item("AppZoomSelectCmd").Execute()

Jelte de Jong
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.

EESignature


Blog: hjalte.nl - github.com