Importinstance Location

Importinstance Location

mike
Enthusiast Enthusiast
1,291 Views
2 Replies
Message 1 of 3

Importinstance Location

mike
Enthusiast
Enthusiast

I'm working in Python trying to determine the insertion point of a dwg link.  I can get the Location but it is neither LocationPoint nor LocationCurve.  How can I get the XYZpoint that represents the dwg origin?

0 Likes
1,292 Views
2 Replies
Replies (2)
Message 2 of 3

RPTHOMAS108
Mentor
Mentor

If you use ImportantInstance.GetTransform then that will tell you the origin and basis xyz as it relates to the internal co-ordinate system of Revit.

 

There are two problems with this, as far as I can tell:

 

1) The coordinate system is curtailed compared to the original DWG file, so I believe it is not a reflection of 0,0,0 in the dwg file (is probably centre of visible content brought in).

2) If you insert it on a section view the basis xyz will tell you it's the same as when you insert it on a plan i.e. identity. So the basis does not tell you what it should and I'm unsure how Revit knows it's direction (probably it is just not exposed to API).

 

I think (1) above just relates to how Revit works compared with AutoCAD. In AutoCAD you place the content in relation to the world in Revit you place the world in relation to the content (content is within a much more limited co-ordinate system with relative offsets that relate it to a larger system). So DWG is curtailed to fit this.

Message 3 of 3

JimJia
Alumni
Alumni

Hi mike,

 

You can use importinstance.GetTransform() to get the transform, then you can use Transform.OfPoint to transform the origin to the actual point.

 

Here is C# code 

 

public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            Document doc = commandData.Application.ActiveUIDocument.Document;

            Reference r = commandData.Application.ActiveUIDocument.Selection.PickObject(Autodesk.Revit.UI.Selection.ObjectType.Element);

            Element e = doc.GetElement(r.ElementId);

            if(e is ImportInstance)
            {
                ImportInstance instance = e as ImportInstance;

                XYZ Loc = instance.GetTransform().OfPoint(instance.GetTransform().Origin);
            }


            return Result.Succeeded;
        }

Jim Jia
Autodesk Forge Evangelist
https://forge.autodesk.com
Developer Technical Services
Autodesk Developer Network
Email: [email protected]
0 Likes