Sie sind auf Seite 1von 9

Custom Python Scripts for AutoCAD Plant 3D Part 5 - AutoCAD... http://adndevblog.typepad.com/autocad/2016/01/custom-python...

01/21/2016

By David Wolfe (http://www.autodesk.com/expert-elite/featured-


members/david-wolfe) (Contributor)

Get start with Part 1 (http://adndevblog.typepad.com/autocad


/2015/06/custom-python-scripts-for-autocad-plant-3d-part-1.html),
Part 2 (http://adndevblog.typepad.com/autocad/2015/06/custom-
python-scripts-for-autocad-plant-3d-part-2.html), Part 3
(http://adndevblog.typepad.com/autocad/2015/06/custom-python-
scripts-for-autocad-plant-3d-part-3.html) and Part 4
(http://adndevblog.typepad.com/autocad/2015/07/custom-python-
scripts-for-autocad-plant-3d-part-4.html) 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


(http://adndevblog.typepad.com/files/nozflange-script.zip). The
script should look like this:

1 of 9 4/03/2017 12:49 AM
Custom Python Scripts for AutoCAD Plant 3D Part 5 - AutoCAD... http://adndevblog.typepad.com/autocad/2016/01/custom-python...

# Embedded file name: varmain\pipesub\cpp_f_f_.p


yc
from aqa.math import *
from varmain.flangesub.cpfwo import *
from varmain.pipesub.cpp_util import *
from varmain.primitiv import *
from varmain.var_basic import *
from varmain.custom import *

@activate(Group="StraightNozzle,Nozzle", Tooltip
Short="Long Weld Neck", TooltipLong="Long Weld N
eck", LengthUnit="in", Ports="2")
@group("MainDimensions")
@param(D10=LENGTH, TooltipShort="Nominal Outside
Diameter",TooltipLong="Nominal Outside Diameter"
)
@param(L1=LENGTH, TooltipShort="Overall Length."
, TooltipLong="Overall Length")
@param(L2=LENGTH, TooltipShort="Hub Length", Too
ltipLong="Length of flange with weld neck.")
@param(OF=LENGTH, TooltipLong="Length between co
nnection points.")
@param(B1=LENGTH, TooltipLong="Flange Thickness"
)
@param(D12=LENGTH, TooltipLong="Flange OD Width"
)
@param(D13=LENGTH, TooltipLong="OD of Weld neck"
)

def nozflange(s, D10 = 4.5, L1 = 9, L2 = 3, B1 =


0.94, D12 = 9, D13 = 5.31, OF = -1.0,**kw):
xH1 = D12 + OF * 2.0
if D12 < xH1:
D12 = xH1
W1 = D12
DI = .25
DO = .25
#create the nozzle extension
if L1 > 0:
oTH = CYLINDER(s, R=D10 / 2.0, H=L1, O=D
10 - (DO / 2.0)).rotateY(90.0)
else:
oTH = None
L1 = -L1

2 of 9 4/03/2017 12:49 AM
Custom Python Scripts for AutoCAD Plant 3D Part 5 - AutoCAD... http://adndevblog.typepad.com/autocad/2016/01/custom-python...

oF1 = CPFWO(s, L=L2, B=B1, D1=D12, D2=D10, D


3=D13, W=W1, OF=OF)
if oTH:
oTH.uniteWith(oF1)
oF1.erase()
if W1 <= D12:
WA1 = 0.0
else:
WA1 = 90.0
#set port points
s.setPoint((0.0, 0.0, 0.0), (-1.0, 0.0, 0.0)
, WA1, 0.0, L2)
s.setPoint((L1, 0.0, 0.0), (1.0, 0.0, 0.0),
0, 0.0, L2)
return

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).
# Embedded file name: varmain\pipesub\cpp_f_f_.py
c
from aqa.math import *
from varmain.flangesub.cpfwo import *
from varmain.pipesub.cpp_util import *
from varmain.primitiv import *
from varmain.var_basic import *
from varmain.custom import *
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.
@activate(Group="StraightNozzle,Nozzle", TooltipS
hort="Long Weld Neck", TooltipLong="Long Weld Nec
k", LengthUnit="in", Ports="2")
@group("MainDimensions")
@param(D10=LENGTH, TooltipShort="Nominal Outside
Diameter",TooltipLong="Nominal Outside Diameter")
@param(L1=LENGTH, TooltipShort="Overall Length.",
TooltipLong="Overall Length")
@param(L2=LENGTH, TooltipShort="Hub Length", Tool
tipLong="Length of flange with weld neck.")
@param(OF=LENGTH, TooltipLong="Length between con
nection points.")
@param(B1=LENGTH, TooltipLong="Flange Thickness")
@param(D12=LENGTH, TooltipLong="Flange OD Width")
@param(D13=LENGTH, TooltipLong="OD of Weld neck")

3 of 9 4/03/2017 12:49 AM
Custom Python Scripts for AutoCAD Plant 3D Part 5 - AutoCAD... http://adndevblog.typepad.com/autocad/2016/01/custom-python...

(http://adndevblog.typepad.com
/.a/6a0167607c2431970b01b7c80ac6e9970b-pi)
StraightNozzles

(http://adndevblog.typepad.com
/.a/6a0167607c2431970b01b7c80ac6f3970b-pi)
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");

4 of 9 4/03/2017 12:49 AM
Custom Python Scripts for AutoCAD Plant 3D Part 5 - AutoCAD... http://adndevblog.typepad.com/autocad/2016/01/custom-python...

(http://adndevblog.typepad.com
/.a/6a0167607c2431970b01b8d194d5c3970c-pi)

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.

(http://adndevblog.typepad.com
/.a/6a0167607c2431970b01b7c80ac703970b-pi)

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

The default path for the nozzle catalog is "C:\AutoCAD Plant 3D 2016
Content\CPak Common\NOZZLE 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

5 of 9 4/03/2017 12:49 AM
Custom Python Scripts for AutoCAD Plant 3D Part 5 - AutoCAD... http://adndevblog.typepad.com/autocad/2016/01/custom-python...

nozzle.

(http://adndevblog.typepad.com
/.a/6a0167607c2431970b01bb08af933d970d-pi)

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

(http://adndevblog.typepad.com
/.a/6a0167607c2431970b01b7c80ac712970b-pi)

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.

Posted at 09:00 AM in Plant3D (http://adndevblog.typepad.com/autocad


/plant3d/) | Permalink (http://adndevblog.typepad.com/autocad/2016/01/custom-

6 of 9 4/03/2017 12:49 AM
Custom Python Scripts for AutoCAD Plant 3D Part 5 - AutoCAD... http://adndevblog.typepad.com/autocad/2016/01/custom-python...

python-scripts-for-autocad-plant-3d-part-5.html)

Reza said...

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
Reply
02/23/2016 at 12:10 AM (http://adndevblog.typepad.com/autocad/2016/01
/custom-python-scripts-for-autocad-plant-3d-part-5.html#comment-
6a0167607c2431970b01bb08bde9de970d)
_davewolfe (http://twitter.com/_davewolfe) said...

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 (http://usa.autodesk.com/adsk/servlet/index?siteID=123112&
id=15460551)
Reply
02/24/2016 at 06:05 AM (http://adndevblog.typepad.com/autocad/2016/01
/custom-python-scripts-for-autocad-plant-3d-part-5.html#comment-
6a0167607c2431970b01b7c819b13a970b)
Reza said...

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.
Reply
02/28/2016 at 06:23 AM (http://adndevblog.typepad.com/autocad/2016/01
/custom-python-scripts-for-autocad-plant-3d-part-5.html#comment-
6a0167607c2431970b01b8d1a57558970c)
_davewolfe (http://twitter.com/_davewolfe) said...

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.

7 of 9 4/03/2017 12:49 AM
Custom Python Scripts for AutoCAD Plant 3D Part 5 - AutoCAD... http://adndevblog.typepad.com/autocad/2016/01/custom-python...

Reply
03/07/2016 at 07:34 AM (http://adndevblog.typepad.com/autocad/2016/01
/custom-python-scripts-for-autocad-plant-3d-part-5.html#comment-
6a0167607c2431970b01b8d1aa2c8f970c)
Comment below or sign in with Typepad (http://www.typepad.com
/sitelogin?uri=http%3A%2F
%2Fadndevblog.typepad.com%2Fautocad%2F2016%2F01%2Fcustom-python-
scripts-for-autocad-plant-3d-part-5.html&
fp=2416f6fe6e795b8413af6d64dbbf7e17&view_uri=http%3A%2F
%2Fprofile.typepad.com%2F&via=blogside&post_uri=http:
//adndevblog.typepad.com/autocad/2016/01/custom-python-scripts-for-autocad-
plant-3d-part-5.html) Facebook (http://www.typepad.com/sitelogin?uri=http
%3A%2F%2Fadndevblog.typepad.com%2Fautocad%2F2016%2F01%2Fcustom-
python-scripts-for-autocad-plant-3d-part-5.html&
fp=2416f6fe6e795b8413af6d64dbbf7e17&view_uri=http%3A%2F
%2Fprofile.typepad.com%2F&via=blogside&service=facebook&post_uri=http:
//adndevblog.typepad.com/autocad/2016/01/custom-python-scripts-for-autocad-
plant-3d-part-5.html) Twitter (http://www.typepad.com/sitelogin?uri=http
%3A%2F%2Fadndevblog.typepad.com%2Fautocad%2F2016%2F01%2Fcustom-
python-scripts-for-autocad-plant-3d-part-5.html&
fp=2416f6fe6e795b8413af6d64dbbf7e17&view_uri=http%3A%2F
%2Fprofile.typepad.com%2F&via=blogside&service=twitter&post_uri=http:
//adndevblog.typepad.com/autocad/2016/01/custom-python-scripts-for-autocad-
plant-3d-part-5.html) Google+ (http://www.typepad.com/sitelogin?uri=http
%3A%2F%2Fadndevblog.typepad.com%2Fautocad%2F2016%2F01%2Fcustom-
python-scripts-for-autocad-plant-3d-part-5.html&
fp=2416f6fe6e795b8413af6d64dbbf7e17&view_uri=http%3A%2F
%2Fprofile.typepad.com%2F&via=blogside&service=gplus&post_uri=http:
//adndevblog.typepad.com/autocad/2016/01/custom-python-scripts-for-autocad-
plant-3d-part-5.html) and more... (http://www.typepad.com/sitelogin?uri=http
%3A%2F%2Fadndevblog.typepad.com%2Fautocad%2F2016%2F01%2Fcustom-
python-scripts-for-autocad-plant-3d-part-5.html&
fp=2416f6fe6e795b8413af6d64dbbf7e17&view_uri=http%3A%2F
%2Fprofile.typepad.com%2F&via=blogside&service=openid&post_uri=http:
//adndevblog.typepad.com/autocad/2016/01/custom-python-scripts-for-autocad-
plant-3d-part-5.html)

8 of 9 4/03/2017 12:49 AM
Custom Python Scripts for AutoCAD Plant 3D Part 5 - AutoCAD... http://adndevblog.typepad.com/autocad/2016/01/custom-python...

(You can use HTML tags like <b> <i> and <ul> to style your text. URLs automatically linked.)

Email address is not displayed with comment.

(http://www.typepad.com/)

AutoCAD DevBlog (http://adndevblog.typepad.com/autocad/)

9 of 9 4/03/2017 12:49 AM

Das könnte Ihnen auch gefallen