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

Line.Angle givng a different reading to AutoCAD lines properties

2 REPLIES 2
SOLVED
Reply
Message 1 of 3
Anonymous
487 Views, 2 Replies

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

Line.Angle givng a different reading to AutoCAD lines properties

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

 

2 REPLIES 2
Message 2 of 3
_gile
in reply to: Anonymous

_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

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

Message 3 of 3
Anonymous
in reply to: _gile

Anonymous
Not applicable

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

0 Likes

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

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