Announcement

Collapse
No announcement yet.

Dynamic Model Update > RevitLinkType > SetElementWorkset

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Dynamic Model Update > RevitLinkType > SetElementWorkset

    Anyone tried this? Im trying to change the workset id of a revit link type after it has been added using DMU...

    The code work fine if I try this with Pipe just not RevitLinkType. It also works using pick command. Any ideas for workarounds to make this work?

    The code I'm using...

    Code:
                var updater = new Updater(_app.ActiveAddInId);
                UpdaterRegistry.RegisterUpdater(updater);
    
                var filter = new ElementCategoryFilter(BuiltInCategory.OST_RvtLinks);
    
                UpdaterRegistry.AddTrigger(updater.GetUpdaterId(), filter,
                                           Element.GetChangeTypeElementAddition());


    Code:
     public void Execute(UpdaterData data)
            {
                Document doc = data.GetDocument();
    
                foreach (ElementId addedElemId in data.GetAddedElementIds())
                {
                    if (doc.get_Element(addedElemId) is RevitLinkType)
                    {
                        var link = doc.get_Element(addedElemId) as RevitLinkType;
    
                        var frm = new frmSelectRVTLinkType(link.Name);
                        if (frm.ShowDialog() == DialogResult.OK)
                        {
                            Utils.SetWorksetVisibility(frm.LT.GetWorkset(), WorksetVisibility.Visible, false);
                            Utils.SetElementWorkset(link, frm.LT.GetWorkset(), false);
                        }
                    }
                }
            }


    Code:
    public static void SetElementWorkset(Element element, Workset workset, bool useTrans)
            {
                if (element == null || workset == null) return;
    
                Transaction trans = null;
    
                if (useTrans)
                {
                    trans = new Transaction(Document);
                    trans.Start("SetElementWorkset");
                }
              
    
                var param = element.get_Parameter("Workset");
    
                if (param == null) return;
                if (param.AsInteger() == workset.Id.IntegerValue) return;
    
                param.Set(workset.Id.IntegerValue);
    
                if (useTrans)
                {
                    trans.Commit();
                }
               
            }

Related Topics

Collapse

Working...
X