Change pipe level and offset

Change pipe level and offset

Anonymous
Not applicable
2,579 Views
4 Replies
Message 1 of 5

Change pipe level and offset

Anonymous
Not applicable

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?

0 Likes
Accepted solutions (1)
2,580 Views
4 Replies
Replies (4)
Message 2 of 5

Aaron.Lu
Autodesk
Autodesk
Dear,

I see different built in parameter should be used:
What about changing the built in parameters to 2 different ones:

p1 = e.get_Parameter(BuiltInParameter.RBS_START_LEVEL_PARAM);
p2 = e.get_Parameter(BuiltInParameter.RBS_OFFSET_PARAM);

Note: you can use RevitLookup to see the correct enum of the related parameter.


Aaron Lu
Developer Technical Services
Autodesk Developer Network
0 Likes
Message 3 of 5

Anonymous
Not applicable

My partner Frantxo and I have prepared a test suite for this issue.

 

In the attached zip, you will find a revit file, with a few pipes, and a fitting, outlined in red. In the example, we want to change this fitting to Level 2, and update the offset to -1500 to keep the current global position.

 

From the Revit UI, if you try to change any of those parameters, it will give you a warning. You must change both parameters at once, before apply.

 

Also enclosed is a C# macro, that tries to do the same thing, changing both parameters in a single transaction, but it fails as if you were changing only one of the parameters instead of both at the same time.

 

Download the file from here: https://dl.dropboxusercontent.com/u/63451502/pipes-sample.zip

0 Likes
Message 4 of 5

Aaron.Lu
Autodesk
Autodesk
Accepted solution
Ok, the problem is in this line:

bool bp2 = p2.Set(-1500);

the number -1500 mm is too large, API takes feet as default length unit, so you have to set -1500mm like this:

bool bp2 = p2.Set(-4.92125984251969);


Aaron Lu
Developer Technical Services
Autodesk Developer Network
Message 5 of 5

Anonymous
Not applicable

It was easy! Thank you!

0 Likes