.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Determine Current Units (Metric or Imperial)

8 REPLIES 8
Reply
Message 1 of 9
vince1327
9586 Views, 8 Replies

Determine Current Units (Metric or Imperial)

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;

 

}
}
}

}

8 REPLIES 8
Message 2 of 9
adadnet
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

Message 3 of 9
vince1327
in reply to: adadnet

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

Message 4 of 9
kdub_nz
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

 

//

Everything will work just as you expect it to, unless your expectations are incorrect.

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

Message 5 of 9
vince1327
in reply to: kdub_nz

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

}

Message 6 of 9
joshuamodglin
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
Message 7 of 9
vince1327
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

Message 8 of 9
vince1327
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

Message 9 of 9
jeff
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

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost