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
Solved! Go to Solution.
Solved by Stakin. Go to Solution.
Solved by rogmitch. Go to Solution.
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?
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
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.
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
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.
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.
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 🙂
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 .
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.
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.
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
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.
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.
Can't find what you're looking for? Ask the community or share your knowledge.