Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Axis - Normal to Surface thru a point

2 REPLIES 2
Reply
Message 1 of 3
Ktelang
576 Views, 2 Replies

Axis - Normal to Surface thru a point

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-------

------------------------------------------------------------------------------
Config :: Intel (R) Xeon (R) CPU E31245 @ 3.30 GHz, 16.0 GB, 64bit win7
Inventor 2013 and Vault Basic 2013
-----------------------------------------------------------------------------
2 REPLIES 2
Message 2 of 3
Ktelang
in reply to: Ktelang

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

 

 

 

------------------------------------------------------------------------------
Config :: Intel (R) Xeon (R) CPU E31245 @ 3.30 GHz, 16.0 GB, 64bit win7
Inventor 2013 and Vault Basic 2013
-----------------------------------------------------------------------------
Message 3 of 3
philippe.leefsma
in reply to: Ktelang

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.

 



Philippe Leefsma
Developer Technical Services
Autodesk Developer Network

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report