Change beam type

Change beam type

markjvlampad
Advocate Advocate
2,882 Views
8 Replies
Message 1 of 9

Change beam type

markjvlampad
Advocate
Advocate

how can I change Beam type? for example I have beam 310UB40 beam size and now I want to change the size into 530UB92 using APi.

 

or from 310UB40 change to 300PFC.

 

 

0 Likes
Accepted solutions (1)
2,883 Views
8 Replies
Replies (8)
Message 2 of 9

jeremytammik
Autodesk
Autodesk

Set the family instance element type via its Symbol property:

 

https://apidocs.co/apps/revit/2019/4157fff5-cde3-cbb7-1df8-03f77d64712f.htm

 

By the way, this is a very basic question that is answered by the Revit API getting started material, so you may want to work through that before submitting any further questions:

 

https://thebuildingcoder.typepad.com/blog/about-the-author.html#2

  

I also strongly suspect that this question has been asked in the past, so I would also suggest you always search for existing answers before submitting new questions.

 

Thank you!

 

Cheers,

 

Jeremy

 

 

 

 



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

0 Likes
Message 3 of 9

markjvlampad
Advocate
Advocate

hi Jeremy,

 

thank you for your quick response. 

 

I've used this code and when I run it. it change the typename but not the actual size.

 

string wName = "310UB32";
type = new FilteredElementCollector(doc).OfClass(typeof(ElementType))
.First<Element>(a => a.Name.Equals(wName)) as ElementType;

 

FamilySymbol fs = fi.Symbol as FamilySymbol;
fs.Name = type.Name;

 

 

0 Likes
Message 4 of 9

so-chong
Advocate
Advocate
Accepted solution

Hi,

 

Could this macro be useful to you?

It will change the size of the beam, i'm not sure if this is what you're looking for.

Hope this helps.

 

     public void changeBeamType()
{
        Document doc = this.ActiveUIDocument.Document;

        using (Transaction t = new Transaction(doc, "Change Beam Type"))
        {
        t.Start();
             
         // the familyinstance you want to change -> e.g. UB-Universal Beam 305x165x40UB
         List<FamilyInstance> beams = new FilteredElementCollector(doc, doc.ActiveView.Id)         
        .OfClass(typeof(FamilyInstance))
        .Cast<FamilyInstance>()
        .Where(q => q.Name == "305x165x40UB").ToList();
             
         // the target familyinstance(familysymbol) what it should be -> e.g. UB-Universal Beam 533x210x92UB         
         FamilySymbol fs = new FilteredElementCollector(doc)
         .OfClass(typeof(FamilySymbol))
         .Cast<FamilySymbol>()
         .FirstOrDefault(q => q.Name == "533x210x92UB"as FamilySymbol; 
 
         foreach (FamilyInstance beam in beams)
         {
             beam.Symbol = fs;
         }
                
         t.Commit();
         }
}
0 Likes
Message 5 of 9

markjvlampad
Advocate
Advocate

hi So-Chong,

 

that's exactly what I am looking for. but there is a bit of issue. code works perfectly when changing the type from

UB to any type of Beam like concrete, PFC, Angle and so on. but give error from UB to UB.

like 150UB to 310UB.

0 Likes
Message 6 of 9

so-chong
Advocate
Advocate

Hi,

That's strange that UB to UB gives error.

I had loaded the "UB-Universal Beam.rfa" from the default metric library and created two UB beams.

The macro seems no problem dealing with it.

Even other type of beam seems to work.

Do you know what kind of "UB Beam.rfa" you are using?

UB-beam.png

 

0 Likes
Message 7 of 9

markjvlampad
Advocate
Advocate

hi,

 

yeah I am using the default UB-Universal Beams.

what Revit version you used?

 

0 Likes
Message 8 of 9

markjvlampad
Advocate
Advocate

hi So-chong,

 

already settled, I don't know what happen. but I just restart my unit and when I run again your code. it works perfectly.

 

thanks,

Mark

0 Likes
Message 9 of 9

so-chong
Advocate
Advocate

Hi Mark,

 

I had tested the macro with another project document and indeed i got also an error.

I had added two extra lines of code and now it run smoothly.

The UB- profile type "name" could exist as a column or beam in your document, i assume.

These lines of code will choose the beam to filter with.

 

Hope this clarifies and will be useful to you.

Cheers,

So-chong

 

        public void changeBeamType()
        {
            Document doc = this.ActiveUIDocument.Document;

            using (Transaction t = new Transaction(doc, "Change Beam Type"))
            {
            t.Start();
                         
             // the familyinstance you want to change -> e.g. UB-Universal Beam 305x165x40UB
             List<FamilyInstance> beams = new FilteredElementCollector(doc, doc.ActiveView.Id)         
            .OfClass(typeof(FamilyInstance))
            .OfCategory(BuiltInCategory.OST_StructuralFraming)
            .Cast<FamilyInstance>()
            .Where(q => q.Name == "305x165x40UB").ToList();
             
             // the target familyinstance what it should be    -> e.g. UB-Universal Beam 533x210x92UB         
                FamilySymbol fs = new FilteredElementCollector(doc)
            .OfClass(typeof(FamilySymbol))

            .OfCategory(BuiltInCategory.OST_StructuralFraming)
            .Cast<FamilySymbol>()
            .FirstOrDefault(q => q.Name == "533x210x92UB"as FamilySymbol; 
 
            foreach (FamilyInstance beam in beams)
            {
                beam.Symbol = fs;
            }
                
            t.Commit();
            }
        }