• Industries
  • Products
  • Buy
  • Services & Support
  • Communities
  • Discussion Groups

    .NET

    Reply
    Distinguished Contributor
    vince1327
    Posts: 117
    Registered: ‎11-02-2011

    Determine Current Units (Metric or Imperial)

    499 Views, 8 Replies
    03-22-2012 08:59 AM

    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;

     

    }
    }
    }

    }

    Please use plain text.
    Valued Contributor
    FFlix
    Posts: 90
    Registered: ‎11-15-2011

    Re: Determine Current Units (Metric or Imperial)

    03-22-2012 12:08 PM in reply to: vince1327

    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

    Please use plain text.
    Distinguished Contributor
    vince1327
    Posts: 117
    Registered: ‎11-02-2011

    Re: Determine Current Units (Metric or Imperial)

    03-23-2012 06:13 AM in reply to: FFlix

    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

    Please use plain text.
    Valued Mentor
    KerryBrown
    Posts: 259
    Registered: ‎11-29-2008

    Re: Determine Current Units (Metric or Imperial)

    03-23-2012 03:09 PM in reply to: vince1327

    vince1327 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

     

    //-------------------------------------------------------

    class keyThumper<T> : Lazy<T>;      another  Swamper


    I do not endorse the social media app links below:smileyembarrassed:

    Please use plain text.
    Distinguished Contributor
    vince1327
    Posts: 117
    Registered: ‎11-02-2011

    Re: Determine Current Units (Metric or Imperial)

    03-27-2012 06:03 AM in reply to: KerryBrown

    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);

    }

    Please use plain text.
    Distinguished Contributor
    Posts: 147
    Registered: ‎08-15-2007

    Re: Determine Current Units (Metric or Imperial)

    03-27-2012 06:11 AM in reply to: vince1327

    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?

     

     

    Josh Modglin
    Advanced Technologies Solutions Logo
    Please use plain text.
    Distinguished Contributor
    vince1327
    Posts: 117
    Registered: ‎11-02-2011

    Re: Determine Current Units (Metric or Imperial)

    03-27-2012 06:20 AM in reply to: joshuamodglin

    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

    Please use plain text.
    Distinguished Contributor
    vince1327
    Posts: 117
    Registered: ‎11-02-2011

    Re: Determine Current Units (Metric or Imperial)

    03-27-2012 06:28 AM in reply to: joshuamodglin

    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

    Please use plain text.
    Mentor
    Posts: 247
    Registered: ‎05-12-2009

    Re: Determine Current Units (Metric or Imperial)

    03-27-2012 10:03 AM in reply to: vince1327

    MEASUREINIT

    MEASUREMENT

    LUNITS

    INSUNITS

     

    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

    You can also find your answers @ TheSwamp
    Please use plain text.