private void ListInfo(Element elem, Document doc) { var message = string.Empty; message += "Element Id: " + elem.Id; // The workset the element belongs to WorksetId worksetId = elem.WorksetId; message += "\nWorkset Id : " + worksetId.ToString(); // Model Updates Status of the element ModelUpdatesStatus updateStatus = WorksharingUtils.GetModelUpdatesStatus(doc, elem.Id); message += "\nUpdate status : " + updateStatus.ToString(); // Checkout Status of the element CheckoutStatus checkoutStatus = WorksharingUtils.GetCheckoutStatus(doc, elem.Id); message += "\nCheckout status : " + checkoutStatus.ToString(); // Getting WorksharingTooltipInfo of a given element Id WorksharingTooltipInfo tooltipInfo = WorksharingUtils.GetWorksharingTooltipInfo(doc, elem.Id); message += "\nCreator : " + tooltipInfo.Creator; message += "\nCurrent Owner : " + tooltipInfo.Owner; message += "\nLast Changed by : " + tooltipInfo.LastChangedBy; SCaddinsApp.WindowManager.ShowMessageBox("Additional Element Information", message); }
/// <summary> /// Changes the workset of an element. /// </summary> /// <param name="element">Dynamo Elements.</param> /// <param name="workset">A revit workset</param> /// <returns name="element">The element that was changed. Returns null if the change was unsuccessfull.</returns> public static dynamoElement SetElementWorkset(dynamoElement element, Workset workset) { //Get Revit Document object revitDoc doc = DocumentManager.Instance.CurrentDBDocument; Autodesk.Revit.DB.Element unwrapped = element.InternalElement; WorksetId wId = unwrapped.WorksetId; Autodesk.Revit.DB.Parameter wsParam = unwrapped.get_Parameter(BuiltInParameter.ELEM_PARTITION_PARAM); if (wsParam == null) { return(null); } if (doc.IsModifiable) { wsParam.Set(workset.internalId.IntegerValue); } else { using (Autodesk.Revit.DB.Transaction tx = new Autodesk.Revit.DB.Transaction(doc)) { tx.Start("Change Element's Workset"); wsParam.Set(workset.internalId.IntegerValue); tx.Commit(); } } return(unwrapped.ToDSType(true));; }
/// <summary> /// Retrieves the workset with the given name. /// </summary> /// <param name="worksetId">The workset ID</param> /// <returns name="workset">Returns a workset. Returns null if workset does not exist.</returns> public static Workset GetByWorksetId(WorksetId worksetId) { //Get Revit Document object revitDoc doc = DocumentManager.Instance.CurrentDBDocument; return(new Workset(doc, doc.GetWorksetTable().GetWorkset(worksetId))); }
public void BeWorkset(string _wsName, ExternalCommandData commandData) { UIApplication _uiapp = commandData.Application; UIDocument _uidoc = _uiapp.ActiveUIDocument; Autodesk.Revit.ApplicationServices.Application _app = _uiapp.Application; Autodesk.Revit.DB.Document _doc = _uidoc.Document; WorksetTable wst = _doc.GetWorksetTable(); WorksetId wsID = FamilyUtils.WhatIsThisWorkSetIDByName(_wsName, _doc); if (wsID != null) { using (Transaction trans = new Transaction(_doc, "WillChangeWorkset")) { trans.Start(); wst.SetActiveWorksetId(wsID); trans.Commit(); } } else { System.Windows.MessageBox.Show("Sorry but there is no workset " + _wsName + " to switch to.", "Smells So Bad It Has A Chain On It", System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Exclamation); } }
public static Workset GetActiveWorkset(Document doc) { WorksetTable table = doc.GetWorksetTable(); WorksetId activeId = table.GetActiveWorksetId(); Workset workset = table.GetWorkset(activeId); return(workset); }
/// <summary> /// Retrieves an element's workset. /// </summary> /// <param name="element">A Revit element.</param> /// <returns name="workset">A Revit workset.</returns> public static Workset GetElementWorkset(dynamoElement element) { //Get Revit Document object revitDoc doc = DocumentManager.Instance.CurrentDBDocument; WorksetId wid = element.InternalElement.WorksetId; Workset workset = GetByWorksetId(wid); return(workset); }
private WorksetId GetLinkedWorkset(ModelInfo sModel, ModelInfo rModel, WorksetId sourceWorksetId) { WorksetId linkedWorksetId = WorksetId.InvalidWorksetId; var mapItems = from map in viewConfig.MapItems where map.MapItemType == MapType.Workset && map.SourceModelId == sModel.ModelId && map.RecipientModelId == rModel.ModelId && map.SourceItemId == sourceWorksetId.IntegerValue select map; if (mapItems.Count() > 0) { linkedWorksetId = new WorksetId(mapItems.First().RecipientItemId); } return(linkedWorksetId); }
public static bool SetWorksetName(int WorksetId, string Name) { var doc = DocumentManager.Instance.CurrentDBDocument; if (doc.IsWorkshared) { try { WorksetId id = null; FilteredWorksetCollector worksets = new FilteredWorksetCollector(doc).OfKind(WorksetKind.UserWorkset); foreach (Autodesk.Revit.DB.Workset w in worksets) { if (w.Id.IntegerValue == WorksetId) { id = w.Id; break; } } if (id != null) { using (Autodesk.Revit.DB.Transaction t = new Autodesk.Revit.DB.Transaction(doc, "Dynamo_SetProjectNumber")) { t.Start(); WorksetTable.RenameWorkset(doc, id, Name); t.Commit(); return(true); } } else { throw new Exception("Workset is not available in this document."); } } catch (Exception ex) { throw new Exception(ex.ToString()); } } else { throw new Exception("The current file is not workshared."); } }
// Returns the workset name for the workset id thiswid public static string WhatWorksetNameIsThis(WorksetId thiswid, Document doc) { if (thiswid == null) { return(String.Empty); } // Find all user worksets FilteredWorksetCollector worksets = new FilteredWorksetCollector(doc) .OfKind(WorksetKind.UserWorkset); foreach (Workset ws in worksets) { if (thiswid == ws.Id) { return(ws.Name.ToString()); } } return(String.Empty); }
public void Create3DModelLine(XYZ p, XYZ q, string line_style, WorksetId id) { try { if (p.IsAlmostEqualTo(q)) { debugger.show(err: "Expected two different points."); return; } Line line = Line.CreateBound(p, q); if (null == line) { debugger.show(err: "Geometry line creation failed."); return; } ModelCurve model_line_curve = null; model_line_curve = Info.DOC.Create.NewModelCurve(line, NewSketchPlanePassLine(line)); Parameter workset_param = model_line_curve.get_Parameter(BuiltInParameter.ELEM_PARTITION_PARAM); workset_param.Set(Workset_Id.IntegerValue); // set linestyle ICollection <ElementId> styles = model_line_curve.GetLineStyleIds(); foreach (ElementId eid in styles) { Element e = Info.DOC.GetElement(eid); if (e.Name == line_style) { model_line_curve.LineStyle = e; break; } } } catch (Exception ex) { debugger.show(err: ex.ToString()); } }
private static bool SetValue_Integer(this Parameter parameter, object value) { if (parameter == null || value == null) { return(false); } if (value is int) { //Check if parameter is Workset parameter -> If Workset parameter then change only if Workset with Id exists if (parameter.Id.IntegerValue == (int)BuiltInParameter.ELEM_PARTITION_PARAM) { WorksetTable worksetTable = parameter.Element?.Document?.GetWorksetTable(); if (worksetTable == null) { return(false); } WorksetId worksetId = new WorksetId((int)value); if (WorksetId.InvalidWorksetId == worksetId) { return(false); } //TODO: Double check if workset is valid! Workset workset = worksetTable.GetWorkset(worksetId); if (workset == null || workset.Kind != WorksetKind.UserWorkset) { return(false); } } parameter.Set((int)value); return(true); } else if (value is string) { string value_Temp = (string)value; int @int; if (int.TryParse(value_Temp, out @int)) { parameter.Set(@int); return(true); } //YesNo Type parameter if (parameter.Definition.ParameterType == Autodesk.Revit.DB.ParameterType.YesNo) { value_Temp = value_Temp.ToUpper().Trim(); if (value_Temp.Equals("Y") || value_Temp.Equals("YES") || value_Temp.Equals("+") || value_Temp.Equals("TRUE")) { parameter.Set(1); return(true); } if (value_Temp.Equals("N") || value_Temp.Equals("NO") || value_Temp.Equals("-") || value_Temp.Equals("FALSE")) { parameter.Set(0); return(true); } return(false); } } else if (value is bool) { if ((bool)value) { parameter.Set(1); } else { parameter.Set(0); } return(true); } else if (value is IntegerId) { parameter.Set(((IntegerId)value).Id); return(true); } return(false); }
public static void SetWorksetId(this Parameter parameter, WorksetId worksetId) => parameter.Set(worksetId.IntegerValue);
internal static void Assign(Document doc, WorksetId worksetId, string workset, Category cat, string category, ProgressBar progressBar, Label label, out string message) { List <Element> elements = recursiveElements(doc, cat); int converted = 0; int failed = 0; if (elements.Count() == 0) { message = "No elements of that Category were found."; return; } progressBar.Minimum = 0; progressBar.Maximum = elements.Count; using (Transaction t = new Transaction(doc, tName)) { FailureHandlingOptions foptions = t.GetFailureHandlingOptions(); FailureHandler fhandler = new FailureHandler(); foptions.SetFailuresPreprocessor(fhandler); foptions.SetClearAfterRollback(true); t.SetFailureHandlingOptions(foptions); t.Start(); foreach (Element el in elements) { if (el.WorksetId.IntegerValue != worksetId.IntegerValue) //only convert if they are not in that workset { if (el.get_Parameter(BuiltInParameter.ELEM_PARTITION_PARAM).IsReadOnly) { failed++; progressBar.Value++; label.Text = String.Format("Completed {0} of {1}", progressBar.Value.ToString(), progressBar.Maximum.ToString()); label.Refresh(); continue; } try { el.get_Parameter(BuiltInParameter.ELEM_PARTITION_PARAM).Set(worksetId.IntegerValue); converted++; } catch { } } progressBar.Value++; label.Text = String.Format("Completed {0} of {1}", progressBar.Value.ToString(), progressBar.Maximum.ToString()); label.Refresh(); } t.Commit(); } if (failed == 0) { message = String.Format("{0} elements of {1} Category have been assinged to {2} Workset.", converted.ToString(), category, workset); } else { message = String.Format("{0} elements of {1} Category have been assinged to {2} Workset.{3}{4}{5} elements were read-only and failed to be reasigned.", converted.ToString(), category, workset, Environment.NewLine, Environment.NewLine, failed.ToString()); } }
/// <summary> /// Create model lines in a 3D view /// </summary> public static void DrawModelLines(ModelInfo info, ExternalEvent ev, InsertModelLine iml, WorksetId workset_id, XYZ[] pts = null) { if (pts == null || !pts.Any()) { throw new Exception("No points were provided for drawing."); } if (pts.Count() % 2 != 0) { throw new Exception("Odd number of points feed to the display model lines."); } iml.Info = info; iml.Line_Points = pts; iml.Workset_Id = workset_id; ev.Raise(); }
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); }
private bool DuplicateCameraView(ModelInfo sModel, ModelInfo rModel, CameraViewInfo cameraInfo, ViewFamilyType vFamilyType, out CameraViewInfo createdViewInfo) { bool duplicated = false; createdViewInfo = null; try { Document sourceDoc = sModel.ModelDoc; Document recipientDoc = rModel.ModelDoc; using (Transaction trans = new Transaction(recipientDoc)) { trans.Start("Create Camera View"); try { View3D createdView = View3D.CreatePerspective(recipientDoc, vFamilyType.Id); if (CanHaveViewName(rModel, cameraInfo.ViewName)) { createdView.Name = cameraInfo.ViewName; } createdView.SetOrientation(cameraInfo.Orientation); createdView.CropBoxActive = cameraInfo.IsCropBoxOn; createdView.CropBox = cameraInfo.CropBox; createdView.IsSectionBoxActive = cameraInfo.IsSectionBoxOn; createdView.SetSectionBox(cameraInfo.SectionBox); createdView.DisplayStyle = cameraInfo.Display; //createdView.SetRenderingSettings(cameraInfo.Rendering); foreach (string paramName in cameraInfo.ViewParameters.Keys) { Parameter sourceParam = cameraInfo.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 (cameraInfo.ViewTemplateId != ElementId.InvalidElementId) { ElementId templateId = GetLinkedItem(sModel, rModel, MapType.ViewTemplate, cameraInfo.ViewTemplateId); if (templateId != ElementId.InvalidElementId && createdView.IsValidViewTemplate(templateId)) { createdView.ViewTemplateId = templateId; } else { MissingItem missingItem = new MissingItem(cameraInfo.ViewName, "View Template", ""); missingItems.Add(missingItem); } } if (cameraInfo.PhaseId != ElementId.InvalidElementId) { ElementId phaseId = GetLinkedItem(sModel, rModel, MapType.Phase, cameraInfo.PhaseId); if (phaseId != ElementId.InvalidElementId) { Parameter param = createdView.get_Parameter(BuiltInParameter.VIEW_PHASE); if (null != param) { param.Set(phaseId); } } else { MissingItem missingItem = new MissingItem(cameraInfo.ViewName, "Phase", ""); missingItems.Add(missingItem); } } if (viewConfig.ApplyWorksetVisibility && cameraInfo.WorksetVisibilities.Count > 0) { bool worksetFound = true; foreach (WorksetId wsId in cameraInfo.WorksetVisibilities.Keys) { WorksetVisibility wsVisibility = cameraInfo.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(cameraInfo.ViewName, "Workset", ""); missingItems.Add(missingItem); } } createdViewInfo = new CameraViewInfo(createdView); createdViewInfo.LinkedViewId = cameraInfo.ViewId; createdViewInfo.Linked = true; duplicated = true; trans.Commit(); } catch (Exception ex) { trans.RollBack(); string message = ex.Message; } } } catch (Exception ex) { MessageBox.Show("Failed to duplicate camera views.\n" + ex.Message, "Duplicate Camera Views", MessageBoxButton.OK, MessageBoxImage.Warning); } return(duplicated); }