ExportSelectoinToPCF
http://blogs.autodesk.com/revit/2019/01/08/export-assembly-separate-pcf-file/?wpfpaction=add&postid=4287
public void ExportSelectoinToPCF()
{
// get the selected element ids
List<ElementId> elementIdsToPCF = new List<ElementId>();
List<ElementId> selectedElementIds =
this.ActiveUIDocument.Selection.GetElementIds().ToList();
elementIdsToPCF.AddRange(selectedElementIds);
// output PCF for each assembly
OutputAssemblyPCFs(
elementIdsToPCF,
this.ActiveUIDocument.Document);
} // ExportSelectoinToPCF
public void OutputAssemblyPCFs(
List<ElementId> selectedElementIds,
Document theDocument)
{
foreach (ElementId id in selectedElementIds)
{
// check if this is an assembly
AssemblyInstance assemblyInst =
theDocument.GetElement(id) as AssemblyInstance;
if (assemblyInst == null)
continue;
// get the items IDs the assembly
List<ElementId> lstElemIds = new List<ElementId>();
lstElemIds.AddRange(assemblyInst.GetMemberIds());
// get the name of the assembly
string assemblyName = assemblyInst.AssemblyTypeName;
string fileName = "C:\\temp\\" + assemblyName + ".pcf";
// create the PCF file using the assembly name
Autodesk.Revit.DB.Fabrication.FabricationUtils.ExportToPCF(
this.ActiveUIDocument.Document,
lstElemIds,
fileName);
} // foreach
} // OutputAssemblyPCFs
// 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());
} // foreach
return lstElemIds;
} // GetElementIdsInAssembly
Comments
Post a Comment