Hello everybody,
I am trying to create an axis normal to surface thru a point. The following code
works when I pick planar face and any point. But I does not work when I pick swept surface
and any point. It fails. Any suggestions will help.
Please find the attached ipt and code
'Code Start--------
Sub AxisNormal2Surface()
Dim oPDoc As PartDocument
Set oPDoc = ThisApplication.ActiveDocument
Dim oCompDef As PartComponentDefinition
Set oCompDef = oPDoc.ComponentDefinition
'reference to 3d sketch
Dim oSketch3d As Sketch3D
Set oSketch3d = oCompDef.Sketches3D.Add
' Set a reference to the transient geometry collection.
Dim oTransGeom As TransientGeometry
Set oTransGeom = ThisApplication.TransientGeometry
Dim oFace As Object
Set oFace = ThisApplication.CommandManager.Pick(kPartFaceFilter, "Pick Face")
Dim oPoint As Object
Set oPoint = ThisApplication.CommandManager.Pick(kAllPointEntities, "Pick Point")
Dim oAxis As WorkAxis
Set oAxis = oCompDef.WorkAxes.AddByNormalToSurface(oFace, oPoint)
End Sub
'Code End-------
SORRY!!PLEASE IGNORE PREVIOUS POST THAT DOES NOT REALLY EXPLAIN THE PROBLEM
Apologise to post something quick last night
But the real problem can be simulated in a better way
as follows.
I have a 3dsketch and a point at the curvy surface
without api I can add an axis normal to the surface with that point
But for some reason I am not able to get a normal from the a code
I get an axis normal to planar face and point. but I can not get a
normal to curvy/wavy surface at a point
Please note : I tried using all the different filters available.
Public Sub AxisNormal2Surface()
'Check to make sure a 3d sketch is open.
If Not TypeOf ThisApplication.ActiveEditObject Is Sketch3D Then
MsgBox "A 3d sketch must be active."
Exit Sub
End If
' Set a reference to the active sketch.
Dim oPartDoc As PartDocument
'Set oDoc = ThisApplication.ActiveEditDocument
Set oPartDoc = ThisApplication.ActiveDocument
Dim oCompdef As PartComponentDefinition
Set oCompdef = oPartDoc.ComponentDefinition
' Set a reference to the active sketch.
'Dim oSketch As Sketch3D
'Set oSketch = oCompdef.Sketches3D.Add
'oSketch.Name = "L"
'oSketch.Edit
' Set a reference to the transient geometry collection.
Dim oTransGeom As TransientGeometry
Set oTransGeom = ThisApplication.TransientGeometry
' Call the pick method of the clsSelect object and set
' the filter to pick any edge.
Dim oFace As Object
Set oFace = ThisApplication.CommandManager.Pick(kPartFaceFilter, "pick face")
Dim oSketchPoint As Object
Set oSketchPoint = ThisApplication.CommandManager.Pick(kAllPointEntities, "pick face")
Dim oAxisNormal As WorkAxis
Set oAxisNormal = oCompdef.WorkAxes.AddByNormalToSurface(oFace, oSketchPoint)
'oSketch.ExitEdit
End Sub
Looks like it should work, so it seems to be an issue with the behavior of AddByNormalToSurface 😞
Only workaround I see at the moment would be to use another creation method, like AddFixed for example but it would be dependent on the surface and the sketchpoint.
You can get the normal to a face using the code below:
Private Function GetFaceNormalAtPoint( _ face As face, _ point As point) As UnitVector Dim evaluator As SurfaceEvaluator Set evaluator = face.evaluator Dim points(2) As Double points(0) = points.X points(1) = points.Y points(2) = points.Z Dim guessParams(1) As Double Dim maxDev(1) As Double Dim params(1) As Double Dim sol(1) As SolutionNatureEnum Call evaluator.GetParamAtPoint( _ points, _ guessParams, _ maxDev, _ params, _ sol) Dim normal(2) As Double Call evaluator.GetNormal(params, normal) Set GetFaceNormalAtPoint = _ ThisApplication.TransientGeometry.CreateUnitVector( _ normal(0), _ normal(1), _ normal(2)) End Function
Regards,
Philippe.