Custom Python Scripts for AutoCAD Plant 3D – Part 5

<?xml encoding=”UTF-8″>By David Wolfe (Contributor)

Get start with Part 1, Part 2, Part 3 and Part 4 of this series.

Python Script Nozzles in AutoCAD Plant 3D

This article will look at creating a nozzle to use in the nozzles catalog which AutoCAD Plant 3D equipment loads when putting nozzles on equipment.

The full sample is available at this link. The script should look like this:

<span># Embedded file name: varmainpipesubcpp_f_f_.pyc</span>
<span>from</span> <span>aqa.math</span> <span>import</span> <span>*</span>
<span>from</span> <span>varmain.flangesub.cpfwo</span> <span>import</span> <span>*</span>
<span>from</span> <span>varmain.pipesub.cpp_util</span> <span>import</span> <span>*</span>
<span>from</span> <span>varmain.primitiv</span> <span>import</span> <span>*</span>
<span>from</span> <span>varmain.var_basic</span> <span>import</span> <span>*</span>
<span>from</span> <span>varmain.custom</span> <span>import</span> <span>*</span>
<span>@activate</span>(Group<span>=</span><span>"StraightNozzle,Nozzle"</span>, TooltipShort<span>=</span><span>"Long Weld Neck"</span>, TooltipLong<span>=</span><span>"Long Weld Neck"</span>, LengthUnit<span>=</span><span>"in"</span>, Ports<span>=</span><span>"2"</span>)
<span>@group</span>(<span>"MainDimensions"</span>)
<span>@param</span>(D10<span>=</span>LENGTH, TooltipShort<span>=</span><span>"Nominal Outside Diameter"</span>,TooltipLong<span>=</span><span>"Nominal Outside Diameter"</span>)
<span>@param</span>(L1<span>=</span>LENGTH, TooltipShort<span>=</span><span>"Overall Length."</span>, TooltipLong<span>=</span><span>"Overall Length"</span>)
<span>@param</span>(L2<span>=</span>LENGTH, TooltipShort<span>=</span><span>"Hub Length"</span>, TooltipLong<span>=</span><span>"Length of flange with weld neck."</span>)
<span>@param</span>(OF<span>=</span>LENGTH, TooltipLong<span>=</span><span>"Length between connection points."</span>)
<span>@param</span>(B1<span>=</span>LENGTH, TooltipLong<span>=</span><span>"Flange Thickness"</span>)
<span>@param</span>(D12<span>=</span>LENGTH, TooltipLong<span>=</span><span>"Flange OD Width"</span>)
<span>@param</span>(D13<span>=</span>LENGTH, TooltipLong<span>=</span><span>"OD of Weld neck"</span>)
<span>def</span> <span>nozflange</span>(s, D10 <span>=</span> <span>4.5</span>, L1 <span>=</span> <span>9</span>, L2 <span>=</span> <span>3</span>, B1 <span>=</span> <span>0.94</span>, D12 <span>=</span> <span>9</span>, D13 <span>=</span> <span>5.31</span>, OF <span>=</span> <span>-1.0</span>,<span>**</span>kw):
xH1 <span>=</span> D12 <span>+</span> OF <span>*</span> <span>2.0</span>
<span>if</span> D12 <span><</span> xH1:
D12 <span>=</span> xH1
W1 <span>=</span> D12
DI <span>=</span> <span>.25</span>
DO <span>=</span> <span>.25</span>
<span>#create the nozzle extension</span>
<span>if</span> L1 <span>></span> <span>0</span>:
oTH <span>=</span> CYLINDER(s, R<span>=</span>D10 <span>/</span> <span>2.0</span>, H<span>=</span>L1, O<span>=</span>D10 <span>-</span> (DO <span>/</span> <span>2.0</span>))<span>.</span>rotateY(<span>90.0</span>)
<span>else</span>:
oTH <span>=</span> <span>None</span>
L1 <span>=</span> <span>-</span>L1
oF1 <span>=</span> CPFWO(s, L<span>=</span>L2, B<span>=</span>B1, D1<span>=</span>D12, D2<span>=</span>D10, D3<span>=</span>D13, W<span>=</span>W1, OF<span>=</span>OF)
<span>if</span> oTH:
oTH<span>.</span>uniteWith(oF1)
oF1<span>.</span>erase()
<span>if</span> W1 <span><=</span> D12:
WA1 <span>=</span> <span>0.0</span>
<span>else</span>:
WA1 <span>=</span> <span>90.0</span>
<span>#set port points</span>
s<span>.</span>setPoint((<span>0.0</span>, <span>0.0</span>, <span>0.0</span>), (<span>-1.0</span>, <span>0.0</span>, <span>0.0</span>), WA1, <span>0.0</span>, L2)
s<span>.</span>setPoint((L1, <span>0.0</span>, <span>0.0</span>), (<span>1.0</span>, <span>0.0</span>, <span>0.0</span>), <span>0</span>, <span>0.0</span>, L2)
<span>return</span>

Metadata

First we have the includes, this script the includes section is particular important because we are using some of the stock flange scripts (flangesub, pipesub).

<span># Embedded file name: varmainpipesubcpp_f_f_.pyc</span>
<span>from</span> <span>aqa.math</span> <span>import</span> <span>*</span>
<span>from</span> <span>varmain.flangesub.cpfwo</span> <span>import</span> <span>*</span>
<span>from</span> <span>varmain.pipesub.cpp_util</span> <span>import</span> <span>*</span>
<span>from</span> <span>varmain.primitiv</span> <span>import</span> <span>*</span>
<span>from</span> <span>varmain.var_basic</span> <span>import</span> <span>*</span>
<span>from</span> <span>varmain.custom</span> <span>import</span> <span>*</span>

Second is the section declaring our tooltips and parameters.  One the first line here, because we want the script listed under the StraightNozzle and Nozzle categories, we include both.

<span>@activate</span>(Group<span>=</span><span>"StraightNozzle,Nozzle"</span>, TooltipShort<span>=</span><span>"Long Weld Neck"</span>, TooltipLong<span>=</span><span>"Long Weld Neck"</span>, LengthUnit<span>=</span><span>"in"</span>, Ports<span>=</span><span>"2"</span>)
<span>@group</span>(<span>"MainDimensions"</span>)
<span>@param</span>(D10<span>=</span>LENGTH, TooltipShort<span>=</span><span>"Nominal Outside Diameter"</span>,TooltipLong<span>=</span><span>"Nominal Outside Diameter"</span>)
<span>@param</span>(L1<span>=</span>LENGTH, TooltipShort<span>=</span><span>"Overall Length."</span>, TooltipLong<span>=</span><span>"Overall Length"</span>)
<span>@param</span>(L2<span>=</span>LENGTH, TooltipShort<span>=</span><span>"Hub Length"</span>, TooltipLong<span>=</span><span>"Length of flange with weld neck."</span>)
<span>@param</span>(OF<span>=</span>LENGTH, TooltipLong<span>=</span><span>"Length between connection points."</span>)
<span>@param</span>(B1<span>=</span>LENGTH, TooltipLong<span>=</span><span>"Flange Thickness"</span>)
<span>@param</span>(D12<span>=</span>LENGTH, TooltipLong<span>=</span><span>"Flange OD Width"</span>)
<span>@param</span>(D13<span>=</span>LENGTH, TooltipLong<span>=</span><span>"OD of Weld neck"</span>)

image1 
StraightNozzles

image2 
Nozzle class shown by clicking advanced shape options and selecting nozzle.

Testing

To test the script, I made a tool palette icon with this in the macro portion:
^C^CPLANTREGISTERCUSTOMSCRIPTS;^C^C(command “arx” “l” “Pnp3dacpadapter”);(testacpscript “nozflange”);

image3

Once the script is tested, we need to be able to test it in a catalog.  For Plant 3D, all of the nozzles are read from a shared content folder path. You can find the path by running the spec editor as administrator, and then going to Tools > Modify Shared Content folder.

image4

The default path is C:AutoCAD Plant 3D 2016 Content.

The default path for the nozzle catalog is “C:AutoCAD Plant 3D 2016 ContentCPak CommonNOZZLE Catalog.acat”

To open the nozzle catalog, switch to the Catalogs tab, and go to open, and then browse to it.  Once in the catalog you can click create new component and select your script. Fill in some sample data and save your catalog component and the catalog. Note that for flanged nozzles, your end type and pressure class must be set.

In a project drawing, create a piece of equipment, and then pick your nozzle.

image5

You can change the nozzle orientation in the Change location tab.

image6

Note that if you want the user to override the nozzle length, you should use the L parameter in your script. In this case (using L1), for a long weld neck, the catalog data will drive the length, and the user won’t be able to change it.

Deployment

Because you can’t directly modify the nozzle catalog on a user’s computer without overwriting it, you should deploy a folder (eg CPak Custom Nozzles) with your nozzle catalog. The user then will be responsible to add the nozzles. Another option would be to deploy two catalogs, one with the stock nozzles + your custom nozzles, and one with just your custom nozzles.  You could write an installer that lets the user pick which of the two installs they want.  In either case, you should use a property like Design Pressure Factor to include unique information so that they can quickly filter to locate your nozzles.


Comments

9 responses to “Custom Python Scripts for AutoCAD Plant 3D – Part 5”

  1. Dear David,
    I want to create equipment in plant 3d from predefined shape. (1 Torispheric Head, 2 Cylinder, …)
    I want to implement it in C# program.
    Best Regards

  2. Did you look at the samples in the 2016 Plant 3d SDK? They added an equipment api in 2016. http://usa.autodesk.com/adsk/servlet/index?siteID=123112&id=15460551

  3. Thank you for your comment. In sample code, equipment created from predefined template (Create from package). I want to create equipment from predefined shape like torispheric Head + cylinder + ..)
    Actually I want to import PVELITE model in autocad plant 3d. I can extract equipment shape from SQLite database of PVELITE file.
    CADWorx impliment import of PVELITE in his software.
    Any comment will be depreciated.

  4. I think you’ll have to build your own model using AutoCAD 3d solids and then convert that to an equipment block. PV Elite can add more types with dimensional data that doesn’t correlate to the Plant 3d equipment drawing methods.

  5. Dear David
    I made python compiled files and script group with PLANTREGISTERCUSTOMSCRIPTS .. how to assemble that in .peqx

  6. Niels van den Belt Avatar
    Niels van den Belt

    Good afternoon,
    What code can be used in Python to get a grabpoint for changing the length?
    in example the pipe support lenght sliding parameter.
    Is it the Ask4Dist=True command?
    Niels

  7. Hello dear Dave
    I am working generating supports for pipes in autocad plant 3d with the Python program and I have the following problem when trying to compile the source file:
    ModuleNotFoundError: No module named ‘aqa’
    Could you help me, I’m going to thank you very much.
    Greetings

  8. send your code on ajay1579@gmail.com, i will develope it further

  9. rakesh Avatar
    rakesh

    Hi david,
    could you share the python script to import spec from excel or csv file?
    i want to create new spec in plant 3d using excel file or csv file data? How this can be achieved pls help.

Leave a Reply to RezaCancel reply

Discover more from Autodesk Developer Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading