Change the reference level of a family instance

Change the reference level of a family instance

Anonymous
Not applicable
4,770 Views
7 Replies
Message 1 of 8

Change the reference level of a family instance

Anonymous
Not applicable

Hi,

 

I'm trying to change the reference level and the offset of a duct corner through the revit API.duct_corner.PNG

 

 

 

This is what I did so far:

private void changeReferenceAndOffset(Element elem, Level lvl, double newOffset)
{
  Parameter param = elem.get_Parameter(BuiltInParameter.INSTANCE_FREE_HOST_OFFSET_PARAM);
  param.Set(newOffset);
  param = elem.get_Parameter(BuiltInParameter.FAMILY_LEVEL_PARAM);
  param.Set(lvl.Id);
}

The element and the level I send to this function are valid. The offset changes, but the reference level doesn't. Yet I'm still able to change it in the properties window in Revit.

What did I do wrong here ?

 

I'm using Revit 2018.2.

0 Likes
Accepted solutions (1)
4,771 Views
7 Replies
Replies (7)
Message 2 of 8

aignatovich
Advisor
Advisor

Hi!

 

Try to be more specific, e.g. Duct has ReferenceLevel property, which has setter, set it directly:

duct.ReferenceLevel = lvl;
Message 3 of 8

Anonymous
Not applicable

Thanks for the quick answer 🙂

 

I did a lot of experiments and I can assure you that this corner is not considered as a duct but as a FamilyInstance by Revit.

duct_corner.PNG

Because of that, I can't use the ReferenceLevel property.

0 Likes
Message 4 of 8

aignatovich
Advisor
Advisor

Oops, image did not load at the first look, sorry)

 

Your code seems to be working for family instances, that does not have any correlations with other element.

 

But you have duct fitting, which is connected to other elements (ducts). May be the best way in your case is just to move the entire (or may be only a part of) system using ElementTransformUtils ?

0 Likes
Message 5 of 8

aignatovich
Advisor
Advisor
Accepted solution

Tested it within this simple case:

test.PNG

 

and simple iron python script code:

e = selection[0]

tx = Transaction(doc, "test")
tx.Start()

e.get_Parameter(BuiltInParameter.INSTANCE_FREE_HOST_OFFSET_PARAM).Set(0.5)
e.get_Parameter(BuiltInParameter.FAMILY_LEVEL_PARAM).Set(ElementId(15913))

tx.Commit()

It also works as expected, e.g. changed both family level and offset parameters... Also ducts stay connected...

Message 6 of 8

Anonymous
Not applicable

I created another command to test what you did and it works ! So the problem comes from my side, I'll investigate my code again now.

 

Thanks again for those quick answers 🙂

0 Likes
Message 7 of 8

Anonymous
Not applicable

My addin works now, I think I messed up the transaction which is why it wouldn't change the level.

What I did was this:

using (Transaction t = new Transaction(doc, "Change reference"))
{
  t.start();
  //loop over every FamilyInstance in selection
  t.commit();
}

Now I'm doing this:

Transaction t = new Transaction(doc, "Change reference");
t.start();
//loop over every FamilyInstance in selection
t.commit();

I don't know why exactly it wasn't working at first but it's the only thing I changed.

Message 8 of 8

Radish_G
Collaborator
Collaborator

Hi @Anonymous,

I don't have any knowledge of programming.

Can you guys guide me to execute this program?

Regards
Radish G
0 Likes