Announcements
Due to scheduled maintenance, the Autodesk Community will be inaccessible from 10:00PM PDT on Oct 16th for approximately 1 hour. We appreciate your patience during this time.
.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Define correctly the USC on Polyline (Rectangle)

1 REPLY 1
Reply
Message 1 of 2
Anonymous
353 Views, 1 Reply

Define correctly the USC on Polyline (Rectangle)

Hi,

 

I currently try to set a custom USC over a layout created thanks to a polyline Object :

 

USC_Objectif.PNG

The current process is:

  • Create a custom Layout name and ask the user to validate or create another by himself
  • Ask the user to select the layout

 

var options = new PromptEntityOptions("\nSelect the layout: ");
options.AddAllowedClass(typeof(Polyline), true​



 

  • And then I get the ObjectId of the polyline to set the new USC thanks to this command:

 

 

        [CommandMethod("DOCCMD")]
        public void DocumentCmd()
        {   
            Document doc = Application.DocumentManager.MdiActiveDocument;
            Database db = doc.Database;
            var ed = AcAp.DocumentManager.MdiActiveDocument.Editor;

            
            string nameUcs;
            ObjectId ids;
            Point2d pt1;
            Point2d pt2;
           
            ids = LA_Layout_Helper.polylineId;

            // Change the current USC to the usc's selected obect
            ed.Command("_ucs", "_object", ids);


            // Save the new USC with the layout name
            nameUcs = "UCS_" + LA_Layout_Helper.nameLayout;
            ed.Command("_.UCS", "_name", "_sa", nameUcs, "");
            
            


            using (var tr = db.TransactionManager.StartTransaction())
            {
                var pline = (Polyline)tr.GetObject(ids, OpenMode.ForRead);
                pt1 = pline.GetPoint2dAt(0);
                pt2 = pline.GetPoint2dAt(2);


                // Initialize the new SCU
                UcsTableRecord ucsRecord;

                // Open the UCS table for read
                var ucsTable = (UcsTable)tr.GetObject(db.UcsTableId, OpenMode.ForRead);


                // Check to see if the table record exists
                if (ucsTable.Has(nameUcs))
                {
                    ucsRecord = tr.GetObject(ucsTable[nameUcs], OpenMode.ForWrite) as UcsTableRecord;
                }
                else
                {
                    ucsRecord = new UcsTableRecord();
                    ucsRecord.Name = nameUcs;

                    // Open the UCSTable for write
                    ucsTable.UpgradeOpen();

                    // Add the new UCS table record
                    ucsTable.Add(ucsRecord);
                    tr.AddNewlyCreatedDBObject(ucsRecord, true);
                }

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

                // Display the UCS Icon at the origin of the current viewport
                acVportTblRec.IconAtOrigin = true;
                acVportTblRec.IconEnabled = true;

                // Set the UCS current
                acVportTblRec.SetUcs(ucsRecord.ObjectId);
                doc.Editor.UpdateTiledViewportsFromDatabase();
                

                // Display the name of the current UCS
                UcsTableRecord uscTblRecActive;
                uscTblRecActive = tr.GetObject(acVportTblRec.UcsName, OpenMode.ForRead) as UcsTableRecord;
               
                ed.WriteMessage("\nThe current UCS is: " + uscTblRecActive.Name);

                Matrix3d newMatrix = new Matrix3d();
                newMatrix = Matrix3d.AlignCoordinateSystem(Point3d.Origin, 
                                                           Vector3d.XAxis,
                                                           Vector3d.YAxis, 
                                                           Vector3d.ZAxis,
                                                           acVportTblRec.Ucs.Origin,
                                                           acVportTblRec.Ucs.Xaxis,
                                                           acVportTblRec.Ucs.Yaxis,
                                                           acVportTblRec.Ucs.Zaxis);               

                tr.Commit();
            }

            Vector3d Xucs = db.Ucsxdir;
            View_Helper.CreateViewFrom2Points(doc, "Vue_" + LA_Layout_Helper.nameLayout, new Point3d(pt1.X, pt1.Y, 0), new Point3d(pt2.X, pt2.Y, 0));

            Vector3d Xwcs = db.Ucsxdir;
            LA_Layout_Helper.angleLayout = Xucs.GetAngleTo(Xwcs);
            
        }

 

 

 

The issue here is the new USC is not well placed:

USC_issue.PNG

I think that the USC was placed on the first point of the polyline. Do you know a way to fix this issue ?

 

I already tried :

 

 

ed.Command("_.UCS", "_ob");

 

 

This command do the job but I cannot check if the user has selected the right layout or even select any object. If he push the touch "enter" that will skip this command for example.

 

Thanks for your help, and your understanding (I French so excuse me if I did some mistake)

Alexis

1 REPLY 1
Message 2 of 2
_gile
in reply to: Anonymous

Hi,
You should specify the criteria according to which you think UCS is "correct".

 

Salut,
Tu devrais spécifier les critères selon lesquelles tu estimes que SCU est "correct".

 

_gile_0-1618585425196.png

 



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

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