Message 1 of 3

Not applicable
10-09-2019
02:04 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi All,
This is my first post and my first code in Macro, I have been googling and looking in online RevitAPI docs to solve my issue but no success. The code works but with issue that i want to resolve:
1. it doesn't allow me to generate 3d if i don't pickbox from lower-left to upper right of the Planview so i just catch it as exception(maybe because of the behavior of the pickedbox). i wonder if there is another way to do what i intended to do.
2. if there's any way to generate new 3d and replace the previously created one and use it's view settings to the new one.
thanks in advance
here is my code(sorry if its not looking good)
note: credits to rushfort tools for this idea
public void PickBox() { UIDocument uiDoc = Application.ActiveUIDocument; Document doc = uiDoc.Document; //get Activeview plan properties View activeView = doc.ActiveView; try { PickedBox pick = uiDoc.Selection.PickBox(PickBoxStyle.Directional); BoundingBoxXYZ pickBox = new BoundingBoxXYZ(); pickBox.Min = pick.Min; pickBox.Max = pick.Max; if (activeView is ViewPlan ) { using (Transaction trans = new Transaction(doc,"PikBox")) { trans.Start(); View3D threeD = null; //get active view view range ViewPlan plan = activeView as ViewPlan; PlanViewRange vRange = plan.GetViewRange(); //get top and bottom level Level bottomlvl = doc.GetElement(vRange.GetLevelId(PlanViewPlane.BottomClipPlane)) as Level; Level toplvl = doc.GetElement(vRange.GetLevelId(PlanViewPlane.TopClipPlane)) as Level; //get offset from level double bottomOffset = vRange.GetOffset(PlanViewPlane.BottomClipPlane); double topOffset = vRange.GetOffset(PlanViewPlane.TopClipPlane); //getviewfamilytype ViewFamilyType vType = new FilteredElementCollector(doc).OfClass(typeof(ViewFamilyType)) .WhereElementIsElementType() .Cast<ViewFamilyType>() .First(x => x.ViewFamily == ViewFamily.ThreeDimensional); if(pickBox != null) { //create3d threeD = View3D.CreateIsometric(doc, vType.Id); if(!threeD.IsSectionBoxActive) { threeD.IsSectionBoxActive = true; } //get section box of new 3dview and set the sectionbox using pickbox Min and Max X,Y values //then use the view activeview viewrange offset for Min and Max Z values BoundingBoxXYZ section = threeD.GetSectionBox(); XYZ min = null; XYZ max = null; if(toplvl != doc.GetElement(PlanViewRange.LevelAbove) && bottomlvl != doc.GetElement(PlanViewRange.LevelBelow)) { min = section.Min = new XYZ(pickBox.Min.X, pickBox.Min.Y, bottomlvl.ProjectElevation + bottomOffset); max = section.Max = new XYZ(pickBox.Max.X, pickBox.Max.Y, toplvl.ProjectElevation + topOffset); } else if (toplvl == doc.GetElement(PlanViewRange.LevelAbove) || toplvl == doc.GetElement(PlanViewRange.Unlimited)) { min = section.Min = new XYZ(pickBox.Min.X, pickBox.Min.Y, bottomlvl.ProjectElevation + bottomOffset); max = section.Max = new XYZ(pickBox.Max.X, pickBox.Max.Y, bottomlvl.ProjectElevation + 10); } else if (bottomlvl == doc.GetElement(PlanViewRange.LevelBelow) || bottomlvl == doc.GetElement(PlanViewRange.Unlimited)) { min = section.Min = new XYZ(pickBox.Min.X, pickBox.Min.Y, toplvl.ProjectElevation - 10); max = section.Max = new XYZ(pickBox.Max.X, pickBox.Max.Y, toplvl.ProjectElevation + topOffset); } //create new bbox and use new generated min and max values BoundingBoxXYZ new_bbox = new BoundingBoxXYZ(); new_bbox.Min = min; new_bbox.Max= max; //set the new section box of 3d from new bbox threeD.SetSectionBox(new_bbox); //hide scope box Categories categories = doc.Settings.Categories; Category scopeBox = categories.get_Item(BuiltInCategory.OST_VolumeOfInterest); ElementId cat = scopeBox.Id; threeD.SetCategoryHidden(cat, true); //set graphic settings threeD.get_Parameter( BuiltInParameter.VIEW_DETAIL_LEVEL ).Set( 3 ); threeD.get_Parameter( BuiltInParameter.MODEL_GRAPHICS_STYLE ).Set( 3 ); //hide importcategory if(!threeD.AreImportCategoriesHidden) { threeD.AreImportCategoriesHidden = true; } } else { throw new Exception("draw from LOWER LEFT to UPPER LEFT"); } trans.Commit(); uiDoc.ActiveView = threeD; }//end of transaction } else { TaskDialog.Show("Error", "View is not Plan View"); }//end of first condition } catch (Exception) { TaskDialog.Show("Error", "draw from LOWER LEFT to UPPER RIGHT"); }//pick exception }
Solved! Go to Solution.