StructuralFramingUtils

StructuralFramingUtils

Ryan
Enthusiast Enthusiast
1,257 Views
6 Replies
Message 1 of 7

StructuralFramingUtils

Ryan
Enthusiast
Enthusiast

This is probably very simple, but im probably just to new the api to figure it out.

 

Im trying to select framing element(s) in revit, and running the structuralframingutlis.DisallowJoinAtEnd command to mass dissallow framing joins on all selected objects.

 

I dont have much code to post because im stuck right from the start.

 

I can get selected objects elemntid's, but i dont know how to turn that infomation in to family instances, which what the   StructuralFramingUtils

wants. 

 

Am i starting in the wrong place? Im not even sure of the proper syntax for   StructuralFramingUtils.

 

Thanks!

 

           // Get the element selection of current document.
            Selection selection = uidoc.Selection;
            ICollection<ElementId> selectedIds = uidoc.Selection.GetElementIds();

 

0 Likes
Accepted solutions (1)
1,258 Views
6 Replies
Replies (6)
Message 2 of 7

Anonymous
Not applicable

You can loop through the selection and get each element with

 Element e = doc.GetElement(elementid);

 

And then filter on it's category.

 

You can also search a document for all it's structural elements without letting the user select elements like :

        FilteredElementCollector structuralCollection = new FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_StructuralFraming);

 

Hope this helps,

0 Likes
Message 3 of 7

Anonymous
Not applicable
Oh yeah, one other thing. DisallowJoinAtEnd only works in Revit 2015
0 Likes
Message 4 of 7

Ryan
Enthusiast
Enthusiast

Thanks R.van,

 

 

I am working in 2015. Mainly for that function.

 

That's pretty much what i have been trying, but when i try to pass in the ids into GetElement, I get an error saying 

cannot convert from 'System.Collections.Generic.ICollection<Autodesk.Revit.DB.ElementId>' to 'Autodesk.Revit.DB.ElementId' (CS1503)

 

 


            UIDocument uidoc = this.ActiveUIDocument;            
            Document doc = uidoc.Document;
         
            Selection selection = uidoc.Selection;
            ICollection<ElementId> elementId = uidoc.Selection.GetElementIds();
            
            Element e = doc.GetElement(elementId);
            
              FilteredElementCollector structuralCollection = new FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_StructuralFraming);


 

0 Likes
Message 5 of 7

Anonymous
Not applicable
Accepted solution

And Revit is right, you are putting an ICollection of elementIds in a function that expects one single elementId.

 

Try something like this:

 

List<Element> myelements = new List<Element>

foreach (elementid elid in uidoc.Selection.GetElementIds())

{

    myelements.add(doc.GetElement(elid));

}

 

 

Message 6 of 7

Ryan
Enthusiast
Enthusiast

Thanks again R.Van,

 

Got it working.

To take it one step further, how would i pass the selected elements through a filter so that it will only send the framing elements to the StructUtils command. So i wont have to manually filter the elements.

 

I tried with the filtered elements collector, that's really the only way i know how to filter elements. 

 

But i have a feeling there is another way to go about it.

 

 

 

 

    
            Selection selection = uidoc.Selection;
            ICollection<ElementId> selectedIds = uidoc.Selection.GetElementIds();
            List<Element> myElements = new List<Element>();
            


              foreach (ElementId elid in uidoc.Selection.GetElementIds())
            {
                  

//Not sure how to apply a filter to the elements so that it will only pass through structural framing elements.
                  /*
                  FilteredElementCollector collector = new FilteredElementCollector(doc);
                collector.OfCategory(BuiltInCategory.OST_StructuralFramingOther);

var query = from element in collector
    where element.Equals(myElements)
    select element;*/
                  
                  
                  
                myElements.Add(doc.GetElement(elid));
                                             
           }


 

 

0 Likes
Message 7 of 7

Anonymous
Not applicable

Okay, that would be something like this :

 

Try something like this:

 

List<Element> myelements = new List<Element>

foreach (elementid elid in uidoc.Selection.GetElementIds())

{

    Element elem = doc.GetElement(elid);

    if(el.category.name.Contains("structural") myelements.add(elem);

 

// or .Equal("Structural framing")

}