Revit API Forum
Welcome to Autodesk’s Revit API Forums. Share your knowledge, ask questions, and explore popular Revit API topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

how to zoom elements in linked document using revit api?

6 REPLIES 6
SOLVED
Reply
Message 1 of 7
prasannamurumkar
2019 Views, 6 Replies

how to zoom elements in linked document using revit api?

hello all

able to zoom element element in activedoc by this:

UIApp.ActiveUIDocument.ShowElements(element);

 

can anyone suggest how to do same with linked element?

Got element inlinked doc and their position also.

 

Just wanted to zoom.

 

it is also ok if only can zoom to that specific area.

6 REPLIES 6
Message 2 of 7

  • Get the transformation T from the linked document to the host document
  • Determine the bounding box B of the desired element E in the linked document
  • Zoom to T * B in the host document

  



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

Message 3 of 7

Below code is working fine for zooming element in linked doc.

api used is ZoomAndCenterRectangle.

 

 

 

 

 

ElementId oEid = new ElementId(intElementId);
// selectionIds.Add(oEid);
// UIApp.ActiveUIDocument.ShowElements(oEid);

// UIApp.ActiveUIDocument.get

 


Element element = revitME.GetElement(oEid);

LocationPoint lc = element.Location as LocationPoint;
Transform transform1 = RvtLinkm.GetTransform();

XYZ newLocation2 = transform1.OfPoint(lc.Point);

 

 

BoundingBoxXYZ boundingBoxGeyer = element.get_BoundingBox(RevitDoc.ActiveView);
UIView uiView = null;
IList<UIView> uiviews = UIApp.ActiveUIDocument.GetOpenUIViews();
Autodesk.Revit.DB.View view = RevitDoc.ActiveView;
foreach (UIView uv in uiviews)
{
if (uv.ViewId.Equals(view.Id))
{
uiView = uv;
break;
}
}
uiView.ZoomAndCenterRectangle(new XYZ(newLocation2.X - 4, newLocation2.Y - 4, newLocation2.Z - 4), new XYZ(newLocation2.X+4, newLocation2.Y+4, newLocation2.Z+4));

Message 4 of 7

Thank you for sharing your solution.

 

It leaves some question open, though.

 

Here is my cleanup:

 

    void ZoomToLinkedElement( 
      UIDocument uidoc,
      RevitLinkInstance link,
      ElementId id )
    {
      Document doc = uidoc.Document;
      View view = doc.ActiveView;

      // Determine active UIView to use

      UIView uiView = uidoc
        .GetOpenUIViews()
        .FirstOrDefault<UIView>( uv 
          => uv.ViewId.Equals( view.Id ) );

      Element e = doc.GetElement( id );
      LocationPoint lp = e.Location as LocationPoint;
      Transform transform1 = link.GetTransform();
      XYZ newLocation2 = transform1.OfPoint( lp.Point );
      BoundingBoxXYZ bb = e.get_BoundingBox( doc.ActiveView );

      uiView.ZoomAndCenterRectangle( 
        new XYZ( newLocation2.X - 4, newLocation2.Y - 4, newLocation2.Z - 4 ), 
        new XYZ( newLocation2.X + 4, newLocation2.Y + 4, newLocation2.Z + 4 ) );
    }

  

Questions:

 

  • Have I got the active document, view and link right? I was confused by your code...
  • Why transform the element location? Isn't the element location already given in the project space?
  • Did you ever make use of the bounding box, or can that be deleted?

 

Thank you for clarifying!

 

 



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

Message 5 of 7

You use the active UI doc, the link instance, revitME and RevitDoc.

 

Which is which?

 

And what document does the element id belong to?  

  



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

Message 6 of 7

 

hi,

Actually just wanted to show how 

 

ZoomAndCenterRectangle

 

 api used.

Answers to questions

1.yes got the active document,linked document.

2.location got is not correct as element used is from linked document so transform is applied to get its right position in active document.

3.bounding box can  delete as it is used for other purpose (Not for this ZoomAnd CentreRectangle api)

Message 7 of 7

revitMe is linked Document of mechanical equipment.

revit Doc is active Document.

element id belong to revitMe.(linked document)

rvtlink instancc is revit link document instance got from below:

RevitLinkInstance RvtLink = null;

 

FilteredElementCollector oRevitLinksM = new FilteredElementCollector(revitDocument).OfCategory(BuiltInCategory.OST_RvtLinks).WhereElementIsNotElementType();

foreach (Element element in oRevitLinks.ToElements())
{
if (element.Name.ToString().Contains("ME"))
{
RvtLinkm = element as RevitLinkInstance;
}
}

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

Post to forums  

Autodesk Customer Advisory Groups


Rail Community