I'm trying to determine what my base units are in any drawing that i'm in (In modelspace). Essentially i want to either just read out the current base unit, or simply determine metric or imperial...or even both. I've been browsing through the forums and i've found a few examples, but nothing too detailed. Here is what i have so far, i have a feeling i'm on the write track. Is it possible to read out the value of "PlotPaperUnits"?
public class UNITS
public void UNITSCOMMAND()
Document doc = Autodesk.AutoCAD.ApplicationServices.Application.D
Database db = doc.Database;
Editor ed = doc.Editor;
using (DocumentLock acLckDoc1 = doc.LockDocument())
using (Transaction tr = db.TransactionManager.StartTransaction())
BlockTable bt = (BlockTable)tr.GetObject(doc.Database.BlockTableId
BlockTableRecord btr = (BlockTableRecord)tr.GetObject(bt[BlockTableRecord
Layout lay = tr.GetObject(btr.LayoutId, OpenMode.ForRead) as Layout;
PlotPaperUnit unit = lay.PlotPaperUnits;
the systemvariable for a drawing's units is MEASUREMENT. INSUNIT determines at what unit an object is inserted, and if set to zero, is replaced by the INSUNITDEFSOURCE and INSUNITDEFTARGET, which determines how the incoming object's units are converted to the drawing's units respectively.
you should be able to read all of these with the getsystemvariable() method.
Thanks for the help. Do you by chance have an example of this in action. I've been looking up these system variables and I cant seem to find much documentation on them.
Do you by chance have an example of this in action. I've been looking up these system variables and I cant seem to find much documentation on them.
Have a look here :http://www.theswamp.org/index.php?topic=7918.msg10
class keyThumper<T> : Lazy<T>; another Swamper
I do not endorse the social media app links below
Thanks for the link. I was playing around with the code below and have created two if loops to deal with metric and imperial, however no matter what, all drawings always seem to be in imperial? Is this not measuring the current drawing units?
if (db.Measurement == MeasurementValue.Metric)
ed.writemessage("This drawing is metric);
if (db.Measurement == MeasurementValue.English)
ed.writemessage("This drawing is imperial);
The measurement variable gets the units used for the setup of the drawing - which linetypes to use and what type of units are expected.
Then you have LUNITS which deal with the defining what the units we draw in are expected to be. Decimal units can be decimal inches, decimal feet, decimal meters, and/or decimal millimeters just as an example.
Thus, when you say is not measuing current units, I guess we are not understanding what it is you are truly looking for - the setup units type or the drawing units type?
So essentially what i'm trying to figure out is what units the current drawing is set to so that i may create lines/polylines etc using those units. So if i open a metric drawing, I want my code to realize this and create my pre-defined set of layers as metric, not imperial. I think what i'm looking for is drawing units then.
Hope that clears things up
Or, if i know whether the drawing is imperial or metric, is there some sort of flag that i could set so that all other commands i write could query this flag and adjust appropriately?
You can look in help but Autocad uses drawing units. I will not repeat what help says but seems like sometimes people think INSUNITS is the drawing units.
However you want to decideto go at it just look at the Database Properties