twitter youtube facebook linkedin email
Connect with:

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

Martin Schmid

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.

UPDATE: See how to export each assembly to a separate PCF file in this blog post

What is BIM (Building Information Modeling)?

Free Form Rebar - Aligned Distribution

Featured Links

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.

8 Comments

View by:
Most Recent Oldest
  1. AvatarmasondT2ZCD

    0

    0

    This macro works great! One thing I am hoping for is a way to utilize a macro similar to this one but instead of using fabrication parts, can it be modified to export assemblies of plain Revit parts?

    1. Martin SchmidMartin Schmid (Post author)

      0

      0

      Hi masondT2ZCD – modifying this macro for generic design parts is not possible.

  2. Avatarbbebout

    0

    0

    Thanks for the awesome code Martin! Is there a way to make the file name match the Assembly Name?
    Know of any way to find/replace text in the same export so we don’t have to in Notepad++ etc? For our .pcf import to work correctly in Acorn I need to replace the SCH40, SCH80, STD pipe weights with a generic “BASSETTNH3SPEC”.

    1. Martin SchmidMartin Schmid (Post author)

      0

      0

      Hi bbebout – good question. Regarding the macro, yes this would likely be possible, but would require some renovation. Presently, it just places all elements in all assemblies in a single PCF. A better solution would likely be to create a PCF for each created assembly.

      With regard to the SCH80, etc.. It wouldn’t necessarily be related to the macro itself, but rather how your content is defined, replacing the strings in the appropriate locations in the fabrication database.

  3. Avatarandersp.hammer

    0

    0

    Hi Martin,
    Is it so that above code is only working for assemblies of fabrication parts? I’m normally working with piping systems that are not fabrication parts, and would appreciate a code that can export piping systems to pcf so that we can run preliminary stress analysis prior to detailing everything….

    1. Martin SchmidMartin Schmid (Post author)

      0

      0

      Correct, it only works for the fabrication piping elements.

  4. Avataregelsey6ALW8

    0

    0

    Martin,

    Thanks for providing the information a subject that many of us have been researching. Unfortunately when I attempted to implement this code in the Macro it did not produce a *.PCF file.
    Maybe I did not understand the purpose of this code… But it was my understanding that it would export “Assemblies” that are Revit based Families/Elements/Entities. Possibly I’m not unstanding
    the term “assembly/assemblies” correctly… I selected a Piping Run that contained Revit pipe, valves and fittings as a test. The macro/code did not result in any errors in Revit.
    The code was then checked in the Sharpdeveloper and, hit “Rebuild” to check the code for Errors and/or Warnings which; there were none. Can you assist me on what terminology I maybe misunderstanding or on how I may improve the code to get the desire *.PCF file.

    Thanks in a advance Martin.

    1. Martin SchmidMartin Schmid (Post author)

      0

      0

      The macro only works for the more detailed Fabrication piping elements.