Revit secondary development knowledge sharing (two) View related knowledge sharing

The knowledge points shared today are rather miscellaneous, and they are also knowledge that is often used in study and work.
Switching views
Code switching views, it should be noted that switching views does not need to open a transaction.

List<ViewPlan> allView = new FilteredElementCollector(doc).OfClass(typeof(ViewPlan)).Cast<ViewPlan>().ToList();
uidoc.ActiveView = allView[0];

When refreshing the interface
generally needs to process the components in this view after switching, Revit will often freeze at this time, which will cause us to start the following operations without entering this view, so we often do not get what we think The desired result. We need to add a function to refresh Revit here.

doc.Regenerate();

Get the current view

View nowView = doc.ActiveView;

Get the normal vector of the current view

We generally use the cross product when calculating the direction. We often need to require a vector perpendicular to the current plane, that is, the normal vector;

XYZ normal = doc.ActiveView.ViewDirection;

New 3D view

 ViewFamilyType viewtype = new FilteredElementCollector(doc).OfClass(typeof(ViewFamilyType)).Cast<ViewFamilyType>().FirstOrDefault(x => ViewFamily.ThreeDimensional == x.ViewFamily);
View3D nwView3D = View3D.CreateIsometric(doc, viewtype.Id);
nwView3D.Name = "新的三维视图";

Adjust the level of detail and visual style of the
view as the view object

//详细程度
         view.get_Parameter(BuiltInParameter.VIEW_DETAIL_LEVEL).Set((int)ViewDetailLevel.Fine);
//视觉样式
           view.get_Parameter(BuiltInParameter.MODEL_GRAPHICS_STYLE).Set((int)DisplayStyle.FlatColors);

Component highlighting
In the plan view, highlighting the component elementIds is the set of ElementIds that need to be displayed.

 uidoc.Selection.SetElementIds(elementIds);

Isolation component

//隔离图元并且展示出来 elementId为需要隔离和展示出来的构件ID
doc.ActiveView.IsolateElementTemporary(elementId);
uidoc.ShowElements(elementId);

This time the knowledge sharing is over. I hope this trivial knowledge can help you. Thank you for watching. If you have any questions, you can directly contact the blogger.

Guess you like

Origin blog.csdn.net/Oneal5354/article/details/107945239