Hey Everyone,
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"?
namespace UNITTEST
{
public class UNITS
{
[Autodesk.AutoCAD.Runtime.CommandMethod("UNITS")]
public void UNITSCOMMAND()
{
Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
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, OpenMode.ForRead, true);
BlockTableRecord btr = (BlockTableRecord)tr.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForRead);
Layout lay = tr.GetObject(btr.LayoutId, OpenMode.ForRead) as Layout;
PlotPaperUnit unit = lay.PlotPaperUnits;
}
}
}
}
hi vince
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.
felix
Hey FFlix,
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.
Cheers
Vince
@Anonymous wrote:
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.msg100511#msg100511
// Called Kerry in my other life.
Everything will work just as you expect it to, unless your expectations are incorrect.
class keyThumper<T> : Lazy<T>; another Swamper
Hey,
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?
Cheers
Vince
if (db.Measurement == MeasurementValue.Metric)
{
ed.writemessage("This drawing is metric);
}
if (db.Measurement == MeasurementValue.English)
{
ed.writemessage("This drawing is imperial);
}
Vince,
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?
Hey,
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
Cheers
Vince
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?
Cheers
Vince
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
Database.Measurement Property
Database.Lunits Property
Database.Insunits Property
Can't find what you're looking for? Ask the community or share your knowledge.