cad to revit units

cad to revit units

Anonymous
Not applicable
766 Views
6 Replies
Message 1 of 7

cad to revit units

Anonymous
Not applicable

Hi,

 

While looping the lines of a linked cad file in revit I am creating the lines in revit. I then get the length of the line and modify a parameter with this length. Now what I need to know is in what units do I pass the value. As far as I know Revit api takes this in feet. So do I have to first get the units of the linked cad file ; convert it into feet and then pass the value.

 

Thanks & Regards

Sanjay Pandey

0 Likes
767 Views
6 Replies
Replies (6)
Message 2 of 7

jeremytammik
Autodesk
Autodesk

Yes.

 

http://thebuildingcoder.typepad.com/blog/units/

 

Cheers,

 

Jeremy



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

0 Likes
Message 3 of 7

Anonymous
Not applicable

 

Well I am on right path

But How do read the units of the linked file. I can read the units of the revit doc but facing problem in getting the linked cad unit.

 

code to retreive revit unit:

 

 UnitType unitType = UnitType.UT_Length;
Units projectUnit = Command.doc.GetUnits();
Autodesk.Revit.DB.FormatOptions formatOption = projectUnit.GetFormatOptions(unitType);
DisplayUnitType dut = formatOption.DisplayUnits;

 

Thanks & Regards

Sanjay Pandey

 

0 Likes
Message 4 of 7

jeremytammik
Autodesk
Autodesk

I would assume that the only authority that can inform you about the source CAD unit is the source CAD system.

 

Are you talking about DWG?

 

If so, you can either query it using the AutoCAD.NET on a system with AutoCAD installed, or you can use the Forge Design Automation API to query it online.

 

If you are talking about text-based DXF, you can presumably extract that information by parsing the text contents.

 

I hope this helps and makes sense.

 

Cheers,

 

Jeremy

 



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

0 Likes
Message 5 of 7

FAIR59
Advisor
Advisor

you can query Revit for these parameters:

 

CADLinkType dwgLink;

// import Units

Parameter UnitParam = dwgLink.get_Parameter(BuiltInParameter.IMPORT_DISPLAY_UNITS);

// import Scale

Parameter ScaleParam = dwgLink.get_Parameter(BuiltInParameter.IMPORT_SCALE);

ImportInstance dwgInstance;

// instance Scale

Parameter Instance_ScaleParam = dwgInstance.get_Parameter(BuiltInParameter.IMPORT_INSTANCE_SCALE);

Message 6 of 7

Anonymous
Not applicable

Hi,

 

Thanks for the solution.

 

However I found the solution this way:

foreach (GeometryObject geometryObj in Command.dwg.get_Geometry(new Options()))
{
if (geometryObj is GeometryInstance) /
{
GeometryInstance dwgInstance = geometryObj as GeometryInstance;
Parameter pm = dwgInstance.Symbol.LookupParameter("Import Units");
cadunit = pm.AsInteger();
}
}

But Yes Kudos to you.

 

Thanks & Regards

Sanjay Pandey

 

0 Likes
Message 7 of 7

jeremytammik
Autodesk
Autodesk

Dear Sanjay,

 

Great that you found a solution.

 

Thanks to Fair59 for his as well.

 

Please be aware that it is best and safest to avoid using the display name to access parameter values, since they can be duplicated.

 

Better, safer and more efficient as well to use built-in parameter enums to retrieve them instead, like Fair59 shows.

 

Cheers,

 

Jeremy



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

0 Likes