Determine whether sketch is facing toward/away from origin, Solidworks
Determine whether sketch is facing toward/away from origin, Solidworks
(OP)
I am working i a macro and need to be able to determine within the macro whether or not a sketch is facing toward or away from the origin. I would then use this information in an if statement later.
In my macro a sketch is created (gear tooth profile) and then within the same macro another sketch is created to define the path of a swept cut. The path would change depending on whether the first sketch was facing toward the origin or away.
Can anyone help me out?
Thanks!
In my macro a sketch is created (gear tooth profile) and then within the same macro another sketch is created to define the path of a swept cut. The path would change depending on whether the first sketch was facing toward the origin or away.
Can anyone help me out?
Thanks!






RE: Determine whether sketch is facing toward/away from origin, Solidworks
A guess...
Chris
SolidWorks/PDMWorks 08 3.1
AutoCAD 08
ctopher's home (updated Aug 5, 2008)
ctopher's blog
SolidWorks Legion
RE: Determine whether sketch is facing toward/away from origin, Solidworks
-handleman, CSWP (The new, easy test)
RE: Determine whether sketch is facing toward/away from origin, Solidworks
Really, when i create my swept cut path i just want to ensure that it is going through the part.
Referencing the attached screen shot, if i started my gear tooth sketch on the opposite of the part, my swept path would have still gone to the left rather than intersecting the part.
RE: Determine whether sketch is facing toward/away from origin, Solidworks
To get the plane or face on which the sketch resides, use Sketch::GetReferenceEntity. This will be either a plane or a planar face. The method for dealing with each is slightly different. Do you have any experience with vector algebra and transformation matrices? I sure hope so...
If the sketch resides on a plane, you will need to use RefPlane::Transform to get the MathTransform object for the plane. This MathTransform is a 3D transformation matrix that basically gives the data for the plane. From this you can create the normal vector MathVector object).
If the sketch resides on a planar face, then the normal vector (MathVector) can be had directly from Face2::Normal.
Now that you have a normal vector to the face or plane (vector length is unimportant) you need to get a vector from your plane/face to the origin. This can be created from the point data gotten from ModelDoc2::ClosestDistance. If you have a plane, the vector gotten through ClosestDistance will be either pointing in exactly the same direction as the normal vector or in exactly the opposite. If you have a planar face, the vector may or may not be directly normal to the face, because the origin may be outside the boundary of the normal projection of the planar face. However, this doesn't matter. All you care about is the angle between the two vectors. If the angle is greater than 90 degrees, your plane normal points away from the origin. If it's less than 90 degrees, the normal points toward the origin. Take the dot product of the two vectors using MathVector::Dot. If the dot product is a negative number then the angle is greater than 90 degrees and the sketch normal points away from the origin. If the dot product is positive then the angle is less than 90 degrees and the normal points toward the origin.
-handleman, CSWP (The new, easy test)
RE: Determine whether sketch is facing toward/away from origin, Solidworks
Regardless, thanks for your assist. You've been a great resource.
RE: Determine whether sketch is facing toward/away from origin, Solidworks
-handleman, CSWP (The new, easy test)