Message 1 of 2
Define correctly the USC on Polyline (Rectangle)
Not applicable
04-16-2021
12:32 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi,
I currently try to set a custom USC over a layout created thanks to a polyline Object :
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:
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