Revit panel in panelTypes

Revit panel in panelTypes

Anonymous
Not applicable
1,064 Views
4 Replies
Message 1 of 5

Revit panel in panelTypes

Anonymous
Not applicable

Hi,

 

I have created a family that represents panel (panello.rfa).

When I try to search that panel inside the list of panels and in Revit family it appears (panels.PNG), it is not in list

 

FilteredElementCollector panelTypes
                    = new FilteredElementCollector(doc)
                      .OfClass(typeof(PanelType));

                    bool found= false;
                    foreach (PanelType pt in panelTypes)
                    {   
                        if ("pannello" == pt.Name)
                        {
                            windowType = pt;
                            found= true;
                        }
                    }

 

Can someone tell me why and how to solve?

 

Regards,

 

Bruno

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

Charles.Piro
Advisor
Advisor

Hi,

 

you must search inside Family, not in PanelType :

 

public Result Execute(ExternalCommandData extCmdData, ref string msg, ElementSet elmtSet)
        {
            UIApplication uiapp = extCmdData.Application;
            UIDocument uiDoc = uiapp.ActiveUIDocument;
            Application app = uiapp.Application;
            Document doc = uiDoc.Document;

            try
            {
                string strRfa = "pannello";
                FilteredElementCollector fltElmntCol = new FilteredElementCollector(doc).OfClass(typeof(Family));
                int n = fltElmntCol.Count<Element>(e => e.Name.Equals(strRfa));
                if (0 < n)
                {
                    Family famille = fltElmntCol.First<Element>(e => e.Name.Equals(strRfa)) as Family;
                }
            }
            catch (Exception e)
            {
                msg = e.Message;
                return Result.Failed;
            }
            return Result.Succeeded;
        }
    }

Smiley Wink



PIRO Charles
Developer

PIRO CIE
Linkedin


0 Likes
Message 3 of 5

Anonymous
Not applicable

ok, understood, thank you.

 

But how to cast my family into paneltype? the point is that I need to insert the family pannelli.rfa in a curtaingrid. If I do it in Revit I can do it but via API I'm not able to do this because I can't find myfamily in paneltype.

 

FilteredElementCollector panelTypes
                    = new FilteredElementCollector(doc)
                      .OfClass(typeof(PanelType));

                    bool found= false;
                    foreach (PanelType pt in panelTypes)
                    {   
                        if ("pannello" == pt.Name)
                        {
                            windowType = pt;
                            found= true;
                        }
                    }

 

//Try to set a panel in curtaingrid as my panel type loaded from pannelli.rfa

foreach (ElementId id in myWall.CurtainGrid.GetPanelIds())
 {
                         
    if (found)
          {
             Autodesk.Revit.DB.Panel panel = doc.GetElement(id) as Autodesk.Revit.DB.Panel;
             panel.Pinned = false;

             if (pannelloVisiva != null)
                panel.PanelType = windowType ;
                            
               break;
           }
}

 

Thank you,

 

regards,

 

Bruno

0 Likes
Message 4 of 5

Charles.Piro
Advisor
Advisor
Accepted solution

Hi,

 

for change, the Type of Panel in a curtainWall, you can try this :

 

 [Transaction(TransactionMode.Manual)]
    public class Command : IExternalCommand
    {
        public Result Execute(ExternalCommandData extCmdData, ref string msg, ElementSet elmtSet)
        {
            UIApplication uiapp = extCmdData.Application;
            UIDocument uiDoc = uiapp.ActiveUIDocument;
            Application app = uiapp.Application;
            Document doc = uiDoc.Document;

            string strRfa = "pannello";
            ElementId elmntId = null;
            ElementType famille = null;

            try
            {
                Reference refsel = uiDoc.Selection.PickObject(ObjectType.Element, "Select Curtain Wall");
                Element elmnt = doc.GetElement(refsel.ElementId);
                Wall _wall = elmnt as Wall;
                Panel _panel = doc.GetElement(_wall.CurtainGrid.GetPanelIds().First()) as Panel;

                
                FilteredElementCollector fltElmntCol = new FilteredElementCollector(doc).OfClass(typeof(ElementType));
                int n = fltElmntCol.Count<Element>(e => e.Name.Equals(strRfa));
                if (0 < n)
                {
                    famille = fltElmntCol.First<Element>(e => e.Name.Equals(strRfa)) as ElementType;
                    elmntId = famille.Id;
                }
              
                using (Transaction trans = new Transaction(doc))
                {
                    trans.Start("Change Type");
                    _panel.ChangeTypeId(elmntId);
                    trans.Commit();
                }
                
            }
            catch (Exception e)
            {
                msg = e.Message;
                return Result.Failed;
            }
            return Result.Succeeded;
        }

Smiley Wink



PIRO Charles
Developer

PIRO CIE
Linkedin


0 Likes
Message 5 of 5

Anonymous
Not applicable

Thank you.

It works perfectly.

 

 

Regards,

 

Bruno

0 Likes