UCS
User coordinate system (UCS): The working coordinate system. The user specifies a UCS to make drawing tasks easier. All points passed to AutoCAD commands, including those returned from AutoLISP routines and external functions, are points in the current UCS (unless the user precedes them with an * at the Command prompt). If you want your application to send coordinates in the WCS, OCS, or DCS to AutoCAD commands, you must first convert them to the UCS by calling the translating them and then transforming the Point3d or Point 2d object with the TransformBy method that represents the coordinate value.
OCS
Object coordinate system (also known as Entity coordinate system or ECS): Point values specified by certain methods and properties for the Polyline2d and Polyline objects are expressed in this coordinate system, relative to the object. These points are usually converted into the WCS, current UCS, or current DCS, according to the intended use of the object. Conversely, points in WCS, UCS, or DCS must be translated into an OCS before they are written to the database by means of the same properties.
When converting coordinates to or from the OCS you must consider the normal of the OCS.
DCS
Display coordinate system: The coordinate system where objects are transformed before they are displayed. The origin of the DCS is the point stored in the AutoCAD system variable TARGET, and its Z axis is the viewing direction. In other words, a viewport is always a plan view of its DCS. These coordinates can be used to determine where something will be displayed to the user.
PSDCS
Paper space DCS: This coordinate system can be transformed only to or from the DCS of a Model space viewport. This is essentially a 2D transformation, where the X and Y coordinates are always scaled. Therefore, it can be used to find the scale factor between the two coordinate systems. The PSDCS can be transformed only into a Model space viewport.
So am I correct that ucs only counts when one is in model space? And the equivalent for paper space is dcs? And what the heck is psdcs for?
private List<ObjectId> lisFindObjIdOfCircle()
{
Document doc = acApp.DocumentManager.MdiActiveDocument;
Editor ed = doc.Editor;
List<ObjectId> lisObjectIdFound = new List<ObjectId>();
try
{
var option = new PromptSelectionOptions(); option.MessageForAdding = "\nselect Rectangle/Borders Cover Gambar";
var psr = ed.GetSelection(option, new SelectionFilter(new[] { new TypedValue(0, "LWPOLYLINE,Polyline") }));
SelectionSet acSSet = psr.Value;
if (psr.Status == PromptStatus.OK)
{
foreach (SelectedObject recID in acSSet)
{
lisObjectIdFound.Add(recID.ObjectId);
}
}
}
catch (System.Exception ex)
{
ed.WriteMessage("\nError in getting ObjectId of all circles on the drawing. " +
"Error message is: " + ex.Message);
}
return (lisObjectIdFound);
}
[CommandMethod("zv", CommandFlags.UsePickSet | CommandFlags.Redraw)]
public void testview()
{
var doc = acApp.DocumentManager.MdiActiveDocument;
Database db = HostApplicationServices.WorkingDatabase;
var ed = doc.Editor;
List<ObjectId> lisCircleObjId = new List<ObjectId>();
lisCircleObjId = this.lisFindObjIdOfCircle();
using (Transaction trans = db.TransactionManager.StartTransaction())
{
using (var layoutDictionary = (DBDictionary)trans.GetObject(db.LayoutDictionaryId, OpenMode.ForRead))
{
using (var mylock = doc.LockDocument())
{
foreach (var layoutEntry in layoutDictionary)
{
if (layoutEntry.Key == "Model") continue;
using (var layout = (Layout)trans.GetObject(layoutEntry.Value, OpenMode.ForWrite))
{
var n = 0;
var extSelObj = new Extents3d();
// ObjectId layoutId = LayoutManager.Current.CreateLayout(layout.LayoutName); // membuat layout
LayoutManager.Current.CurrentLayout = layout.LayoutName;
Entity entObj = (Entity)trans.GetObject(lisCircleObjId[n], OpenMode.ForRead);
ObjectId idcover = entObj.ObjectId;
extSelObj.AddExtents(entObj.GeometricExtents);
bool isPaperspace = true;
foreach (ObjectId viewportId in layout.GetViewports())
{
if (isPaperspace)
{
isPaperspace = false;
continue;
}
using (var viewport = (Viewport)trans.GetObject(viewportId, OpenMode.ForWrite))
{
if (viewport.Locked == true) viewport.Locked = false;
viewport.On = true;
ed.Command("._MSPACE");
// buat extend dari objectID
var pl = trans.GetObject(entObj.ObjectId, OpenMode.ForRead) as Polyline;
var ext = new Extents3d();
ext = pl.GeometricExtents;
var mn = ext.MinPoint;
var mx = ext.MaxPoint;
dynamic appAcad = acApp.AcadApplication;
//appAcad.ZoomWindow(mn.ToArray(), mx.ToArray());
ObjectId[] newIds = new ObjectId[0];
ed.SetImpliedSelection(newIds);
appAcad.ZoomWindow(extSelObj.MinPoint.ToArray(), extSelObj.MaxPoint.ToArray());
ed.SetImpliedSelection(new ObjectId[] { idcover });
// ed.SetImpliedSelection(new ObjectId[] { myRec });
ed.Command("._PSPACE", "");
doc.Editor.SwitchToPaperSpace();
dynamic acadApp = acApp.AcadApplication;
acadApp.ZoomExtents();
ed.WriteMessage("\n viewlocked : " + viewport.Locked.ToString());
break;
}
n += 1;
ed.Regen();
}
}
}
}
}
trans.Commit();
}
}