Determine block rotation angle

Determine block rotation angle

Anonymous
Not applicable
390 Views
0 Replies
Message 1 of 1

Determine block rotation angle

Anonymous
Not applicable

Hallo, we have the following situation: We have a Profile e.g. a square-frame that is extruded in Z direction. We want to do workings like a keyhole on this Profile. Then we want to pass (export) the information's regarding the keyhole to another System. The keyhole is an inventor block, which we put on a Sketch and extrude it. The keyhole block can be rotated on the Sketch.

 

Our Problem is to determine the Rotation angle of the block in the Sketch relative to the Profile. (Help...)

 

We found out that X/Y-axis of the Sketch can differ if the sketch is made directly on one plane of the Profile, or if we use a workplane parallel to a Profile-plane, or even with an angle to one Profile-plane.  All this causes that the sketch can be rotated and also be upside down. Then the Rotation of the block can be done positive (e.g. 12°)  or "negative" (e.g. -12° or 348°).

 

I've attached a Code snippet (that does not work in every case) and a screenshot.

 

I'm gateful for any Support.

 

        private double DetermineAngle(Inventor.PlanarSketch oSketch, SketchBlock oSketchBlock)
        {
            Vector resultVector = null;
            TransientGeometry tg = oSketch.Application.TransientGeometry;

            Point2d origin2d = tg.CreatePoint2d(0, 0);
            Point2d xPoint2d = tg.CreatePoint2d(1, 0);

            origin2d.TransformBy(oSketchBlock.Transformation);
            xPoint2d.TransformBy(oSketchBlock.Transformation);

            Point sketchOriginTransf = tg.CreatePoint(origin2d.X, origin2d.Y, 0.0);
            Point sketchXPointTransf = tg.CreatePoint(xPoint2d.X, xPoint2d.Y, 0.0);

            sketchOriginTransf.TransformBy(oSketch.SketchToModelTransform);
            sketchXPointTransf.TransformBy(oSketch.SketchToModelTransform);

            Vector minus_zAxis3d = oSketch.Application.TransientGeometry.CreateVector(0, 0, -1);

            resultVector = tg.CreateVector(sketchXPointTransf.X - sketchOriginTransf.X, sketchXPointTransf.Y - sketchOriginTransf.Y, sketchXPointTransf.Z - sketchOriginTransf.Z);

            return resultVector.AngleTo(minus_zAxis3d); // This angle is wrong. It always returns the smallest angle.
        }
0 Likes
391 Views
0 Replies
Replies (0)