////[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Reliability", "CA2000:Dispose objects before losing scope")] private void CreateViewAndSheet(RoomConversionCandidate candidate) { // Create Sheet var sheet = ViewSheet.Create(doc, TitleBlockId); sheet.Name = candidate.DestinationSheetName; sheet.SheetNumber = candidate.DestinationSheetNumber; // Get Centre before placing any views var sheetCentre = CentreOfSheet(sheet, doc); if (CreatePlan) { // Create plan of room var plan = ViewPlan.Create(doc, GetFloorPlanViewFamilyTypeId(doc), candidate.Room.Level.Id); plan.CropBoxActive = true; plan.ViewTemplateId = ElementId.InvalidElementId; plan.Scale = Scale; var originalBoundingBox = candidate.Room.get_BoundingBox(plan); // Put them on sheets plan.CropBox = CreateOffsetBoundingBox(50000, originalBoundingBox); plan.Name = candidate.DestinationViewName; // Shrink the bounding box now that it is placed var vp = Viewport.Create(doc, sheet.Id, plan.Id, sheetCentre); // Shrink the bounding box now that it is placed plan.CropBox = CreateOffsetBoundingBox(CropRegionEdgeOffset, originalBoundingBox); // FIXME - To set an empty view title - so far this seems to work with the standard revit template... vp.ChangeTypeId(vp.GetValidTypes().Last()); // FIXME Apply a view template // NOTE This could cause trouble with view scales plan.ViewTemplateId = ViewTemplateId; } if (CreateRCP) { // Create rcp of room var rcp = ViewPlan.Create(doc, GetRCPViewFamilyTypeId(doc), candidate.Room.Level.Id); rcp.CropBoxActive = true; rcp.ViewTemplateId = ElementId.InvalidElementId; rcp.Scale = Scale; var originalBoundingBox = candidate.Room.get_BoundingBox(rcp); // Put them on sheets rcp.CropBox = CreateOffsetBoundingBox(50000, originalBoundingBox); rcp.Name = candidate.DestinationViewName; // Shrink the bounding box now that it is placed var vp = Viewport.Create(doc, sheet.Id, rcp.Id, sheetCentre); // Shrink the bounding box now that it is placed rcp.CropBox = CreateOffsetBoundingBox(CropRegionEdgeOffset, originalBoundingBox); // FIXME - To set an empty view title - so far this seems to work with the standard revit template... vp.ChangeTypeId(vp.GetValidTypes().Last()); // FIXME Apply a view template // NOTE This could cause trouble with view scales rcp.ViewTemplateId = ViewTemplateId; } if (CreateAreaPlan) { // Create plan of room var plan = ViewPlan.CreateAreaPlan(doc, AreaPlanTypeId, candidate.Room.Level.Id); //// var plan = ViewPlan.Create(doc, GetAreaPlanViewFamilyTypeId(doc), candidate.Room.Level.Id); plan.CropBoxActive = true; plan.ViewTemplateId = ElementId.InvalidElementId; plan.Scale = Scale; var originalBoundingBox = candidate.Room.get_BoundingBox(plan); // Put them on sheets plan.CropBox = CreateOffsetBoundingBox(50000, originalBoundingBox); plan.Name = candidate.DestinationViewName; // Shrink the bounding box now that it is placed var vp = Viewport.Create(doc, sheet.Id, plan.Id, sheetCentre); // Shrink the bounding box now that it is placed plan.CropBox = CreateOffsetBoundingBox(CropRegionEdgeOffset, originalBoundingBox); // FIXME - To set an empty view title - so far this seems to work with the standard revit template... vp.ChangeTypeId(vp.GetValidTypes().Last()); // FIXME Apply a view template // NOTE This could cause trouble with view scales plan.ViewTemplateId = ViewTemplateId; SCaddinsApp.WindowManager.ShowMessageBox("test"); } }
/// <summary> /// Get common informations for batch creation /// </summary> private void PreCreate() { try { Autodesk.Revit.Creation.Application appCreation = m_cmdData.Application.Application.Create; //Try to get Level named "Level 1" which will be used in most creations m_level = (from elem in new FilteredElementCollector(m_doc).OfClass(typeof(Level)).ToElements() let level = elem as Level where level != null && "Level 1" == level.Name select level).First(); //If ViewPlan "Level 1" does not exist, try to create one. if (null != m_level) { ElementId AreaSchemeId = new FilteredElementCollector(m_doc).OfClass(typeof(AreaScheme)).FirstOrDefault(a => a.Name == "Rentable").Id; try { m_viewPlan = ViewPlan.CreateAreaPlan(m_doc, AreaSchemeId, m_level.Id); m_viewPlan.Name = "Level 1"; } catch { } } if (null == m_level && null == m_viewPlan) { return; } //List of Curve is used to store Area's boundary lines List <Curve> curves = new List <Curve>(); Autodesk.Revit.DB.XYZ pt1 = new Autodesk.Revit.DB.XYZ(-4, 95, 0); Autodesk.Revit.DB.XYZ pt2 = new Autodesk.Revit.DB.XYZ(-106, 95, 0); Line line = Line.CreateBound(pt1, pt2); curves.Add(line); pt1 = new Autodesk.Revit.DB.XYZ(-4, 105, 0); pt2 = new Autodesk.Revit.DB.XYZ(-106, 105, 0); line = Line.CreateBound(pt1, pt2); curves.Add(line); for (int i = 0; i < 11; i++) { pt1 = new Autodesk.Revit.DB.XYZ(-5 - i * 10, 94, 0); pt2 = new Autodesk.Revit.DB.XYZ(-5 - i * 10, 106, 0); line = Line.CreateBound(pt1, pt2); if (null != line) { curves.Add(line); } } // Create Area Boundary Line for Area // It is necessary if need to create closed region for Area // But for Room, it is not necessary. Autodesk.Revit.DB.XYZ origin = new Autodesk.Revit.DB.XYZ(0, 0, 0); Autodesk.Revit.DB.XYZ norm = new Autodesk.Revit.DB.XYZ(0, 0, 1); Plane plane = appCreation.NewPlane(norm, origin); if (null != plane) { SketchPlane sketchPlane = SketchPlane.Create(m_doc, plane); if (null != sketchPlane) { foreach (Curve curve in curves) { m_doc.Create.NewAreaBoundaryLine(sketchPlane, curve, m_viewPlan); } } } //Create enclosed region using Walls for Room pt1 = new Autodesk.Revit.DB.XYZ(5, -5, 0); pt2 = new Autodesk.Revit.DB.XYZ(55, -5, 0); line = Line.CreateBound(pt1, pt2); Wall.Create(m_doc, line, m_level.Id, true); pt1 = new Autodesk.Revit.DB.XYZ(5, 5, 0); pt2 = new Autodesk.Revit.DB.XYZ(55, 5, 0); line = Line.CreateBound(pt1, pt2); Wall.Create(m_doc, line, m_level.Id, true); for (int i = 0; i < 6; i++) { pt1 = new Autodesk.Revit.DB.XYZ(5 + i * 10, -5, 0); pt2 = new Autodesk.Revit.DB.XYZ(5 + i * 10, 5, 0); line = Line.CreateBound(pt1, pt2); Wall.Create(m_doc, line, m_level.Id, true); } } catch (Exception) { } }
private bool DuplicatePlanView(ModelInfo sModel, ModelInfo rModel, PlanViewInfo planInfo, ViewFamilyType vFamilyType, out PlanViewInfo createdPlanInfo) { bool duplicated = false; createdPlanInfo = null; try { Document sourceDoc = sModel.ModelDoc; Document recipientDoc = rModel.ModelDoc; using (Transaction trans = new Transaction(recipientDoc)) { trans.Start("Create Plan View"); try { ViewPlan createdView = null; ElementId levelId = GetLinkedItem(sModel, rModel, MapType.Level, planInfo.LevelId); if (levelId != ElementId.InvalidElementId) { if (planInfo.PlanViewType == ViewType.AreaPlan) { ElementId areaSchemeId = GetLinkedItem(sModel, rModel, MapType.AreaScheme, planInfo.AreaSchemeId); if (areaSchemeId != ElementId.InvalidElementId) { createdView = ViewPlan.CreateAreaPlan(recipientDoc, areaSchemeId, levelId); } else { MissingItem missingItem = new MissingItem(planInfo.ViewName, "Area Scheme", ""); missingItems.Add(missingItem); } } else { createdView = ViewPlan.Create(recipientDoc, vFamilyType.Id, levelId); } if (null != createdView) { if (CanHaveViewName(rModel, planInfo.ViewName)) { createdView.Name = planInfo.ViewName; } createdView.CropBoxActive = planInfo.IsCropBoxOn; createdView.CropBox = planInfo.CropBox; createdView.DisplayStyle = planInfo.Display; foreach (string paramName in planInfo.ViewParameters.Keys) { Parameter sourceParam = planInfo.ViewParameters[paramName]; Parameter recipientParam = createdView.LookupParameter(paramName); if (parametersToSkip.Contains(sourceParam.Id.IntegerValue)) { continue; } if (null != recipientParam && sourceParam.HasValue) { if (!recipientParam.IsReadOnly) { switch (sourceParam.StorageType) { case StorageType.Double: try { recipientParam.Set(sourceParam.AsDouble()); } catch { } break; case StorageType.ElementId: /*try { recipientParam.Set(sourceParam.AsElementId()); } * catch { }*/ break; case StorageType.Integer: try { recipientParam.Set(sourceParam.AsInteger()); } catch { } break; case StorageType.String: try { recipientParam.Set(sourceParam.AsString()); } catch { } break; } } } } if (planInfo.ViewTemplateId != ElementId.InvalidElementId) { ElementId templateId = GetLinkedItem(sModel, rModel, MapType.ViewTemplate, planInfo.ViewTemplateId); if (templateId != ElementId.InvalidElementId && createdView.IsValidViewTemplate(templateId)) { createdView.ViewTemplateId = templateId; } else { MissingItem missingItem = new MissingItem(planInfo.ViewName, "View Template", ""); missingItems.Add(missingItem); } } if (planInfo.ScopeBoxId != ElementId.InvalidElementId) { ElementId scopeboxId = GetLinkedItem(sModel, rModel, MapType.ScopeBox, planInfo.ScopeBoxId); if (scopeboxId != ElementId.InvalidElementId) { Parameter param = createdView.get_Parameter(BuiltInParameter.VIEWER_VOLUME_OF_INTEREST_CROP); if (null != param) { param.Set(scopeboxId); } } else { MissingItem missingItem = new MissingItem(planInfo.ViewName, "Scope Box", ""); missingItems.Add(missingItem); } } if (planInfo.PhaseId != ElementId.InvalidElementId) { ElementId phaseId = GetLinkedItem(sModel, rModel, MapType.Phase, planInfo.PhaseId); if (phaseId != ElementId.InvalidElementId) { Parameter param = createdView.get_Parameter(BuiltInParameter.VIEW_PHASE); if (null != param) { param.Set(phaseId); } } else { MissingItem missingItem = new MissingItem(planInfo.ViewName, "Phase", ""); missingItems.Add(missingItem); } } if (viewConfig.ApplyWorksetVisibility && planInfo.WorksetVisibilities.Count > 0) { bool worksetFound = true; foreach (WorksetId wsId in planInfo.WorksetVisibilities.Keys) { WorksetVisibility wsVisibility = planInfo.WorksetVisibilities[wsId]; WorksetId worksetId = GetLinkedWorkset(sModel, rModel, wsId); if (worksetId != WorksetId.InvalidWorksetId) { createdView.SetWorksetVisibility(worksetId, wsVisibility); } else { worksetFound = false; } } if (!worksetFound) { MissingItem missingItem = new MissingItem(planInfo.ViewName, "Workset", ""); missingItems.Add(missingItem); } } createdPlanInfo = new PlanViewInfo(createdView); createdPlanInfo.LinkedViewId = planInfo.ViewId; createdPlanInfo.Linked = true; duplicated = true; } } else { MissingItem missingItem = new MissingItem(planInfo.ViewName, "Level", planInfo.LevelName); missingItems.Add(missingItem); } trans.Commit(); } catch (Exception ex) { trans.RollBack(); string message = ex.Message; } } } catch (Exception ex) { MessageBox.Show(planInfo.ViewName + ": Failed to duplicate a plan view.\n" + ex.Message, "Duplicate Plan View", MessageBoxButton.OK, MessageBoxImage.Warning); } return(duplicated); }