.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

AutoCAD BlockReference with Attribute Reference - Rotate Attribute Reference to TOP View

2 REPLIES 2
Reply
Message 1 of 3
rberghLJ4SA
268 Views, 2 Replies

AutoCAD BlockReference with Attribute Reference - Rotate Attribute Reference to TOP View

Hi, 

 

I am looking for some help, we have a block reference that has been placed on a UCS. I'd like to rotate the Attribute Reference to the top view for printing purposes.

 

The Block Reference looks like this

block reference Normal: {(-0.447489037915538,0.774278908692316,-0.447488248448676)}

block reference Rotation: 3.1415916339744827

block reference BlockTransform: {((2.07792693857256,0.537401292332017,-1.07397369099729,139.455483961257),(1.20092449302597,-0.929846906863022,1.85826938086156,127.146580516264),(2.18839580212737E-06,-2.14629554833372,-1.07397179627682,-50),(0,0,0 ,one))}

block reference Position: {(139.455483961257,127.146580516264,-50)}

 

 

The Attribute Reference looks like this

Attribute Reference Normal: {(-0.447489037915538,0.774278908692316,-0.447488248448676)}

Attribute Reference Rotation: 3.1415916339744827

Attribute Reference Position: {(140.xxx-xxxxxxxx,127.319427379831,-51.2288381400736)}

 

How do I go about transforming the Attribute reference so viewable from the top 

2 REPLIES 2
Message 2 of 3
rberghLJ4SA
in reply to: rberghLJ4SA

 

 

if (br.AttributeCollection != null && br.AttributeCollection.Count != 0)
            {
                foreach (ObjectId id in br.AttributeCollection)
                {
                    DBObject obj = acTrans.GetObject(id, OpenMode.ForRead);

                    AttributeReference ar = obj as AttributeReference;

                    if (ar != null && ar.Normal == new Vector3d(0, 0, 1))
                    {
                        ar.UpgradeOpen();

                        Matrix3d brMat = br.BlockTransform;

                        //Keep current position
                        Point3d pos = new Point3d(ar.Position.X, ar.Position.Y, ar.Position.Z);
                        Vector3d targetNormal = new Vector3d(0, 0, 1);

                        //Set new normal and put back the position.
                        ar.Normal = targetNormal;
                        ar.Position = pos;

                        //Get projection matrix
                        Plane targetPlane = new Plane(new Point3d(0, 0, 0), targetNormal);
                        Matrix3d mat = Matrix3d.Projection(targetPlane, targetNormal);

                        //Compute the rotation on WCS.
                        //We do this by taking the XAxis of blockTransform and projecting that onto WCS.
                        //Then get the angle on plane of that new projected vector.
                        Vector3d vec = brMat.CoordinateSystem3d.Xaxis;
                        Vector3d vecTrans = vec.TransformBy(mat);
                        Plane worldPlane = new Plane(Point3d.Origin, Vector3d.ZAxis);
                        double angleOnPlane = vecTrans.AngleOnPlane(worldPlane);
                        //double angleOnPlaneDeg = angleOnPlane * 57.2958;
                        ar.Rotation = originalRotsAR[count] + angleOnPlane;

                       

                        count++;
                    }
                }
            }

 

 

I 've tried this but then the text moves away from the block but it is on the correct plane facing up

Message 3 of 3
rberghLJ4SA
in reply to: rberghLJ4SA

afterafterbeforebefore

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

Post to forums  

AutoCAD Inside the Factory


Autodesk Design & Make Report