Line.Angle givng a different reading to AutoCAD lines properties

Anonymous

Line.Angle givng a different reading to AutoCAD lines properties

Anonymous
Not applicable

I have copied in objects from another drawing into my drawing and then used the following code to look at line angles based on user selection.

 

[CommandMethod("AddPlObjEvent", CommandFlags.Session)]
        public void AddPlObjEvent()
        {
            var doc = app.DocumentManager.MdiActiveDocument;
            var ed = doc.Editor;
            Database db = doc.Database;

            Vector3d mat = ed.CurrentUserCoordinateSystem.Translation;

            using (var ads = doc.LockDocument())
            {
                var pPtRes = doc.Editor.GetEntity("Select an object");

                using (Transaction acTrans = db.TransactionManager.StartTransaction())
                {
                    // Open the Block table record for read
                    BlockTable acBlkTbl;
                    acBlkTbl = acTrans.GetObject(db.BlockTableId,
                                                    OpenMode.ForRead) as BlockTable;

                    // Open the Block table record Model space for write
                    BlockTableRecord acBlkTblRec;
                    acBlkTblRec = acTrans.GetObject(acBlkTbl[BlockTableRecord.ModelSpace],
                                                    OpenMode.ForWrite) as BlockTableRecord;

                    // Open the active viewport
                    ViewportTableRecord acVportTblRec;
                    acVportTblRec = acTrans.GetObject(doc.Editor.ActiveViewportId,
                                                        OpenMode.ForWrite) as ViewportTableRecord;

                    Line exampeLine = acTrans.GetObject(pPtRes.ObjectId, OpenMode.ForWrite) as Line;

                    ed.WriteMessage("\nLine Angle is:" + Place_Cables.Nearby_Cables.radToDeg(exampeLine.Angle));
                }
            }

        }

It returns the wrong angles; the image below shows the angles I expect and see in properties and then in the red box the angles my code returns. I think it has something to do with UCS to WCS but I am unsure on how to get  the copied objects ordinate system. If I draw a new line then I get the angles not in the red box. I would like to either:

-use the copied ordinate system to convert my new line angles to the copied objects ordinates

-convert all copied objects to my ordinate system.

 

New Bitmap Image.jpg

 

0 Likes
Reply
Accepted solutions (1)
499 Views
2 Replies
Replies (2)

_gile
Mentor
Mentor
Accepted solution

Hi,

 

Line.Angle always returns the angle in radians measured counterclockwise from WCS X axis.

if you want to reflect the current angular units and the ANGDIR and ANGBASE settings as does the property palette, just use the Converter.AngletoSring method.

ed.WriteMessage("\nLine Angle is: " + Converter.AngleToString(exampeLine.Angle));


Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes

Anonymous
Not applicable

I am not sure how the forums would get along without you gile

0 Likes