Message 1 of 5

Not applicable
09-09-2015
09:30 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello,
I have a to assign a set of elements from its current level, to its correct level. The element, in fact, does not move, it is just a level reassign.
I have the code to calculate the correct offset, but the problem is that as soon I change the parameter value, an exception occurs as the element cannot stay connected.
What I want is replicate the behaviour of the Revit UI, that is, the new parameter values (level and offset) are not applied until I hit the apply button (or lose the focuse).
The code looks something like this (for this I used hard coded values for level id and offest):
public void ChangeLevel() { Document doc = this.ActiveUIDocument.Document; Reference pickedRef = null; Selection sel = this.ActiveUIDocument.Selection; pickedRef = sel.PickObject(ObjectType.Element, "Please select an element"); Element e = doc.GetElement(pickedRef); Transaction ts = new Transaction(doc,"Parameter rename"); ElementId levelId = new ElementId(768996); try { ts.Start(); Parameter p1 = null; Parameter p2 = null; //p = e.GetParameters("Comments").First(); p1 = e.get_Parameter(BuiltInParameter.FAMILY_LEVEL_PARAM); p2 = e.get_Parameter(BuiltInParameter.INSTANCE_FREE_HOST_OFFSET_PARAM); if(p1!=null && p2!=null) { if( !p1.Set(levelId) || !p2.Set(-1061.403423) ) { TaskDialog.Show("Error setting value","I could not set the parameter value");
ts.RollBack(); }
else
{ ts.Commit();
} } else { TaskDialog.Show("Error setting value","The parameter does not exist in this element"); } } catch(Exception ex) { TaskDialog.Show("Error",ex.Message); ts.RollBack(); } }
Does anyone know how is the right way to do this?
Solved! Go to Solution.