Plant 3D – Adding Custom Components – Part 2 – Breaking down the code.

Share on email
Share on linkedin
Share on facebook
Share on whatsapp

This is the second blog in a series for customised plant components,

In this blog we will look at a high level view of the components in building the Python script,

These are stored in the following location:

C:\AutoCAD Plant 3D 20## Content\CPak Common\CustomScripts\

If this is the first script, the CustomScripts folder will need to be added.


Let’s Take a look at the example script below.














This can be broken up into 3 sections,


The Import:

These brings in segments of code and functions so we don’t have to redefine it.

aqa.math for us to do any mathematical functions,

varmain.primitiv allows us to work with AutoCAD primative shapes,


from aqa.math import *

from varmain.primitiv import *

from varmain.custom import *


The Metadata:

Defining our parameters,

This normally starts with the @activate,

@group(“MainDimensions”) allows us to define the parameters with the @param

The parameters being,

what references to what and the tool tip information when in the spec editor.

these bind our code to the so we can recall it later.



                    TooltipShort=“SO Flange”,

                    TooltipLong=“Slip On Flange”,





@param(D=LENGTH, TooltipShort=“Outer Diameter of the Flange”)

@param(D1=LENGTH, TooltipShort=“Pipe Diameter of the Flange”)

@param(T=LENGTH, TooltipLong=“Thickness of the Flange”)

@param(OF=LENGTH, TooltipLong=“Weld thickness offset”)


The Shape File:

These will help define what Primitives are used, displacement and rotation, how the bodies interact and initial sizing.

def SO_Flange (s, D=210.0, D1=114.3, T=10, OF=-1, **kw):

          F=CYLINDER(s, R=D/2, H=T, O=D1/2).rotateY(90)


Now that we have broken down the script into its 3 parts,

The next blog will look at how our code parts come together,