twitter youtube facebook linkedin email
Connect with:

REVIT BLOG

Exporting PCF Files from Revit 2018 – Part 2 (Assemblies)

Martin Schmid
July 27, 2017

PCF and Assemblies

In a prior post, we showed how to output pipe fabrication parts to a PCF file.  If you are using Assemblies in Revit to generate assembly views, and want to output a PCF of that assembly, you will find that you need to make some enhancements to the PCF output macro.

To do so, we will use a helper function (GetElementIdsInAssembly) to get the element IDs inside any selected assemblies.

Modify the original ExportSelectionToPCF function as shown below, and add the helper function (copy and paste from below).

After making these changes, you should be able to select a single assembly instance, and generate the required PCF output.

The Code

public void ExportSelectionToPCF()
 {
      // get the selected element ids
      List<ElementId> elementIdsToPCF = new List<ElementId>();
      List<ElementId> selectedElementIds = 
           this.ActiveUIDocument.Selection.GetElementIds().ToList();
      elementIdsToPCF.AddRange(selectedElementIds);

      // add the element ids that are in assemblies
      List<ElementId> selectedAssemblySubElementIds = 
           GetElementIdsInAssembly(
               selectedElementIds, 
               this.ActiveUIDocument.Document);
      elementIdsToPCF.AddRange(selectedAssemblySubElementIds);

      // output the PCF
      Autodesk.Revit.DB.Fabrication.FabricationUtils.ExportToPCF(
           this.ActiveUIDocument.Document,
           elementIdsToPCF,
           "C:\\temp\\somefile.pcf");
 }

// Get the element ids in the selected assemblies
 public  List<ElementId> GetElementIdsInAssembly(
     List<ElementId> selectedElementIds, 
     Document theDocument)
 {
      List<ElementId> lstElemIds = new List<ElementId>();
      foreach (ElementId id in selectedElementIds)
      {
           AssemblyInstance assemblyInst = 
                theDocument.GetElement(id) as AssemblyInstance;
           if (assemblyInst == null)
                continue;

           lstElemIds.AddRange(assemblyInst.GetMemberIds());
       }
       return lstElemIds;
 }

See Part 1:  Exporting PCF Files from Revit 2018 to learn how to create a PCF file from Revit.

Martin Schmid

Martin Schmid joined Autodesk in 2005 as a project consultant for MEP customers, both for Revit MEP and AutoCAD MEP. Martin holds a BS in Architectural Engineering, and MS in Engineering from Kansas State University, and a Masters in Management of Technology from the University of Texas at San Antonio. He worked as an electrical designer, engineering coordinator, and application developer before joining Autodesk. Martin has co-authored books for Revit and AutoCAD MEP, and is a licensed engineer in the state of New Hampshire. Martin worked in the product globalization and customer success teams prior to joining the product management team, where he now guides direction related to the extended MEP product portfolio, including MEP functionality within Revit, CADmep, ESTmep, CAMduct, and AutoCAD Plant 3D. In his spare time, Martin enjoys reading, travelling, and attending his kids’ activities.

0 Comments;