I’m working on automating the insertion of parts from a custom Plant 3D catalog into project drawings using a C# plugin.
What I have so far:
A custom catalog (
.pspx,.acat,.pspc) with supports and other components.I can retrieve the desired part from the catalog as a
SpecPartusingSpecManagerandSpecPartReader.
The problem:
Methods like
InsertCustomGeometryPlaceHolderInModel,InsertPlaceHolderInModel, andInsertPlaceHolderInModelWhileRoutingrequire a block name.The block name is only generated after the part is inserted, which creates a circular dependency:
I need the block name to insert the part, but the block name only exists after insertion.
Goal:
- Insert a part from the catalog into the Plant 3D drawing automatically, using the
SpecPart(orPartSizeProperties) without requiring prior manual placement.
What I’ve Tried
Here’s an example of what I tried using InsertPlaceHolderInModel:
using Autodesk.ProcessPower.Piping;
using Autodesk.ProcessPower.Specification;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Geometry;
public void TryInsertPlaceholder()
{
Document doc = Application.DocumentManager.MdiActiveDocument;
Database db = doc.Database;
SpecManager specManager = SpecManager.GetSpecManager();
SpecPart specPart = specManager.FindPart("MySpec", "PART_CODE");
// Attempt to insert placeholder
PnP3dPlaceholderUtil.InsertCustomGeometryPlaceHolderInModel(
specPart.Name,
"BLOCK_NAME", // <-- Problem: This name only exists after insertion
specPart.PartType,
familyID, // Get it from specPart.PropNames
specPart.NominalDiameter,
"", // Tag is usualy empty
sizeProps,
portProperties
);
doc.Editor.WriteMessage($"\nResult: {result.Status}");
}
Questions
- Is there a way to use the SpecPart I already have and finish the automated insertion into the project?
- If not, what are the recommended approaches for automated insertion from a catalog into Plant 3D drawings?
- Is PipingObjectAdder.Add(PartSizeProperties) the correct method for this? If yes, can someone provide a working example?