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: 

How to confirm the orientation of a sketch plane

16 REPLIES 16
SOLVED
Reply
Message 1 of 17
rogmitch
965 Views, 16 Replies

How to confirm the orientation of a sketch plane

If I edit a sketch on the XY origin plane and view it face on with the  Y axis vertical how can I confirm whether the X axis is pointing to the 'right' or 'left' of the screen. 

 

I have tried various combinations of NaturalAxisDirection, AxisIsX and Camera.UpVector and have yet to find a solution.

 

I am sure this must be easier than it appears to me.

 

Any help appreciated.

 

Roger Mitchell

16 REPLIES 16
Message 2 of 17
Stakin
in reply to: rogmitch

oy=Unitvector(0,1,0)

oz=Unitvector(0,0,1)

 

ox=Cross(oy,oz)

 

Message 3 of 17
rogmitch
in reply to: Stakin

Thanks Stakin but I'm still not getting it.  I get the how the cross product gives the X axis vector  but doesn't the cross product just rotate as one rotates the view giving the same result in either orientation?   Don't I need to cross product with a fixed vector that doesn't rotate with the view?

 

Or am I totally misunderstanding what you  propose?

 

 

Message 4 of 17
Stakin
in reply to: rogmitch

sorry,maybe i misunderstand your mean for my poor english,In my understanding, your problem can be solved in the following ways。

(1)if you create a new sketch,you can assign the direction of the sketchplane X direction as you want。



 

PlanarSketches.AddWithOrientation Method
Parent Object: PlanarSketches

Description
Method that creates a new sketch based on the input planar entity and orientation information.

Syntax
PlanarSketches.AddWithOrientation( PlanarEntity As Object, AxisEntity As Object, NaturalAxisDirection As Boolean, AxisIsX As Boolean, Origin As Object, [UseFaceEdges] As Boolean ) As PlanarSketch​

 

(2)if you do not create a new sketch,just edit an exist one,you should get  the sketchplane Axis, and you can compare it with the OX(1,0,0) to determine it's direction。

 

PlanarSketch.AxisEntity Property
Parent Object: PlanarSketch

Description
Gets and sets the object that defines the X or Y axis of the sketch plane. The AxisIsX property defines whether it is the X or Y axis, and the NaturalAxisDirection property defines the direction of the axis.

Syntax
PlanarSketch.AxisEntity() As Object

 

 

 

Message 5 of 17
rogmitch
in reply to: Stakin

Thanks  Stakin for the additional information.   Unfortunately  as one rotates the sketchplane such that the normal flips from pointing out of the screen to pointing into the screen the properties of the sketch  e.g. naturalAxisDirection etc also rotate so I was not able to find a solution using your suggestions.

 

In the end I have a  working a solution by looking at the ViewOrientationType of the camera.

I can check the view name and tell if I am looking at the 'front' or 'back' of the sketch plane.

ViewName = oPart.Views.Item(1).Camera.ViewOrientationType

 

Once again thanks for your suggestions.

Message 6 of 17
Stakin
in reply to: rogmitch

I'm glad to hear that the problem has been solved。😊

Message 7 of 17
Stakin
in reply to: rogmitch

you can get the sketchplane XAxis, and you can compare it with the OX(1,0,0) to determine sketch naturalAxisdirection。

Dim oXdir As UnitVector
oXdir=osketch.AxisEntityGeometry.Direction()
Dim oangle As double
oangle=oXdir.Angleto(ThisApplication.TransientGeometry.CreateUnitVector(1,0,0))
If round(oangle/3.14159*180,1)=180 then
osketch.NaturalAxisDirection=0
end if

 

Message 8 of 17
rogmitch
in reply to: Stakin

Thanks Stakin for having another go but I still do not find this works.  I ran you code in VBA.  

Public Sub TestAxisDirection()
    Dim oXdir As UnitVector
    Dim oSketch As PlanarSketch
    Set oSketch = ThisApplication.ActiveEditObject
    Set oXdir = oSketch.AxisEntityGeometry.Direction()
    Dim oangle As Double
    oangle = oXdir.AngleTo(ThisApplication.TransientGeometry.CreateUnitVector(1, 0, 0))
    If Round(oangle / 3.14159 * 180, 1) = 180 Then
        oSketch.NaturalAxisDirection = 0 
    End If
      MsgBox oangle & "   " & oSketch.NaturalAxisDirection
End Sub

 

Place a sketch on the XY plane with the  positive X axis pointing towards the right of the screen.  Run and you get the output:  0, True as expected.

Rotate the view 180 degrees with the ViewCube (X axis is ow pointing to the left) and the results are the same.

I am missing something?

 

It is weird that something so simple is so difficult to code.  Even my 'solution' doesn't work that well as Camera.ViewOrientationType is dependent upon the rotation of the axes about the axis orthogonal to the sketch plane.

Message 9 of 17
Stakin
in reply to: rogmitch

I don't know why you want to determine the left and right orientation of the x-axis.However, I am not sure that the parameters of the sketch can be modified in the editing state. Generally , it can not.

I think by the code,it cannot determine the left and right orientation of the x-axis ,it just make the sketch's x-axis to align with the model space X-axis。

At this time,you edit the sketch,the positive X coordinates in the sketch represent the right in the overall coordinates and the negative X coordinates represent the left.

Message 10 of 17
rogmitch
in reply to: Stakin

I wrote code to quickly sketch compressed o-rings into various shaped o-ring grooves on my sketches.  These are generally for multibody parts.  The o-ring sketch is created having picked a particular corner of an o-ring groove sketch.  To complicate matters the orientation of the groove can vary as can the orientation of the sketch plane.

   

Unless I can confirm the orientation of the sketch plane I cannot work out the position required for the centre of the o-ring  relative to my picked corner and my o-ring sketch can end up missing the groove! 

 

For example, if an o-ring sketch is placed correctly with the sketch plane normal pointing outward it will miss the groove if I rotate the plane so the normal faces inward.  This is easy to compensate for provided I know the direction of the sketch normal relative to the screen. 

 

I had no idea it would be this difficult  🙂

 

 

 

Message 11 of 17
Stakin
in reply to: rogmitch

That is to say, just know the corresponding relationship between the x-axis in the sketch space and the x-axis in the model space. the up  code can help you。beacuse this computer don't have inventor so the up code just snippet .

 

Another way ,in model space you create the point (ThisApplication.TransientGeometry.CreatePoint())at the Oring center,Use the (PlanarSketch.ModelToSketchSpaceModelCoordinate As Point )  As Point2d)as the Oring sketch center, regardless of the orientation of the sketch.
Message 12 of 17
rogmitch
in reply to: Stakin

Thanks for the additional information.  I will take a look at your suggestion later today and hopefully get something working.  I will let you know.

Message 13 of 17
Stakin
in reply to: Stakin

Addition,according to your original plan, you should select another edge of the O-ring to determine the sketch orientation of the O-ring,regardless of the x-axis orientation of the sketch

The method I mentioned in the last post is that you must know the spatial position of the O-ring, so that the compressed O-ring can be generated directly regardless of the o-groove.
If the locating dimension of O-ring is missing, the point and line referring to O-ring groove must be used.

Message 14 of 17
rogmitch
in reply to: Stakin

I have to agree- my thoughts were heading in that direction as well.  It means I need to pick the correct edges in the correct sequence but it would instantly remove a lot the variables related to the orientation of the sketch plane.  

 

I will progress the code along those lines.

 

Thanks

 

 

 

Message 15 of 17
Stakin
in reply to: rogmitch

I hope the problem can be solved as soon as possible. Look forward to your good news.

I don't know the specific situation of this task, but I think you'd better select the point and line of O-ring groove only once, and determine the rest according to the relative position relationship between O-rings. If you have to select.

 

Message 16 of 17
rogmitch
in reply to: Stakin

Picking one corner and the opposite edge of the groove proved to be the answer.  The sketched o-ring now hits the groove independent of the sketch orientation or sketch plane every time.  The code needs tidying up but is also  significantly shorter.  

 

Many thanks for your help.

 

 

Message 17 of 17
Stakin
in reply to: Stakin

Con~~~

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

Post to forums  

Technology Administrators


Autodesk Design & Make Report