custom python scripts

custom python scripts

Anonymous
Not applicable
8,848 Views
28 Replies
Message 1 of 29

custom python scripts

Anonymous
Not applicable

Hello

 

with the awesome help of the

 

Custom Python Scripts for AutoCAD Plant 3D

By David Wolfe

 

int the AutoCAD DevBlog I started scripting successfull.

 

On the contrary to the blog, I have to create a part, based on my new script, first before I can test it with 'TESTACPSCRIPT'. Is this actual the typical workaround?

 

Where can I find a documentation, which sub routines are in which import files (in /varmain), which parameters expect the sub routines and which order is importent for the import files?

 

 

Thanks

Reply
Reply
0 Likes
8,849 Views
28 Replies
Replies (28)
Message 2 of 29

Anonymous
Not applicable

:On the contrary to the blog, I have to create a part,

:based on my new script, first before I can test it with

:'TESTACPSCRIPT'. Is this actual the typical workaround?

 

I am not sure I understand the question you are asking.

 

:Where can I find a documentation, which sub routines

:are in which import files (in /varmain), which parameters

:expect the sub routines and which order is importent for

:the import files?

 

If you look in the variants.zip file in the root of the CPAK Common folder, you will find the other PYC scripts.  you can call any of them you like into your own script.  for example, I call this NUT script:

 

from varmain.divsub.cnut6_001 import *

 

and use it here:

 

o1 = CNUT6_001(s, D=0.5, W=0.5, H=0.0).rotateY(270.0).translate((0.0, 0.0, 0.0))

 

The rotateY is optional, but the translate needs to be there to locate it.

 

This is how you locate the file to get the syntax name from above:

 

6-21-2017 4-18-57 PM.png

Reply
Reply
Message 3 of 29

Anonymous
Not applicable

Hi,

 

thanks for your answer.

 

:On the contrary to the blog, I have to create a part,

:based on my new script, first before I can test it with

:'TESTACPSCRIPT'. Is this actual the typical workaround?

 

I am not sure I understand the question you are asking.

 

This means, I can not test the script in ACAD until I created a part in the spec editor, based on this script.

 

 

o1 = CNUT6_001(s, D=0.5, W=0.5, H=0.0).rotateY(270.0).translate((0.0, 0.0, 0.0))

 

Where did you find the parameters (the syntax)  (D=0.5, W=0.5, H=0.0)  which the function expects.

Reply
Reply
0 Likes
Message 4 of 29

Anonymous
Not applicable

No, you do not have to have the part in the spec to test.  If that was the case, I would have quit doing this python stuff a long time ago.

 

You need to do this from the command line (or build into a toolbar button like I did)

Command: (arxload "pnp3DACPadapter")

Command: PLANTREGISTERCUSTOMSCRIPTS

 

After that is run, you can run this from the command line:  (TESTACPSCRIPT "Scriptname")

 

Scriptname is whatever you names the PY file you are scripting. 

For example TESTSUPPORT.PY would look like this on the command line: (TESTACPSCRIPT "TESTSUPPORT")

 

You should get a return result of <Entity name: 22a315cc70>  (that alpha-numeric value is randomly generated) and you script, if it worked will place the 3D component on the 0,0,0 origin.

 

Let me know if this works for you.

 

As for the 2nd part of the question, I looked in the variants.zip file to find the PYC of another out-of-the-box part that was calling for a nut (basically another support) and then looked at the code (after decompiling it for research purposes) and then I could see how it was called in the script and what needed to be adjusted.  It takes a lot of trial and error.  We can assist with remote support if needed but we do that as a paid service.  Hope this helps.

Reply
Reply
Message 5 of 29

Anonymous
Not applicable

Hello

 

so I don't know what it is...

I have script that works, I copy it (with another file name), run PLANTREGISTERCUSTOMSCRIPTS, run (TESTACPSCRIPT "MY_Scriptname") and that returns nil Smiley Mad

 

I also decompiled pyc-files but this is a hard way to get a 'documentation'...

 

 

anyway thanks for your help

Reply
Reply
0 Likes
Message 6 of 29

Anonymous
Not applicable

you do have this script located in your content folder correct?  C:\AutoCAD Plant 3D 20XX Content\CPak Common\CustomScripts?  It has to be there for it to work.  The PLANTREGISTERCUSTOMSCRIPTS will look there and create the PYC file out of the PY.

Reply
Reply
0 Likes
Message 7 of 29

Anonymous
Not applicable

Yes it is there in the correct folder, like the other script that works fine...the copied py is compiled after PLANTREGISTERCUSTOMSCRIPTS as well.

Reply
Reply
0 Likes
Message 8 of 29

mlandmann
Participant
Participant

I cannot see where the .pyc files are going? Do they stay in the CustomScripts directory? 

Reply
Reply
0 Likes
Message 9 of 29

Anonymous
Not applicable

mlandmann,

Yes, PLANTPARTCONVERT compiles it (and creates the XML) and places it back into the ...\CustomScripts\<subfoldername> folder where the .py file is located.

Reply
Reply
0 Likes
Message 10 of 29

JameseeT3KVM
Advocate
Advocate

Morning Scott-

 

Trying to do is make a support that uses 2 UBOLTS. For large bore pipe we have a standard that requires one ubolt on each side of the web.

Can I leverage the existing ubolt and multiple it with a new parametric dimension in between? Or do I need to reuse the entire ubolt script?

 

You mention decompiling, how can i do that? Because I am missing where you find the scripts for the out of the box parts. Is decompiling the trick?

 

Just getting started with Python Support script writing. Sorry for lame questions. 😄

Reply
Reply
0 Likes
Message 11 of 29

mikael.santospj
Enthusiast
Enthusiast

Hi guys, how are you?

I am trying to implement some new items with python to our catalogue. But, I thnk I'm making some debutant mistake.

could you help me to identify if there is some error in the code.

It bothers me the fact that the folder _pycache_ is always generated and not a .pyc file.

thanks

Reply
Reply
0 Likes
Message 12 of 29

nghiabt04
Advocate
Advocate
Could you snapshot your error ?
Reply
Reply
0 Likes
Message 13 of 29

mikael.santospj
Enthusiast
Enthusiast

Hi, thanks.

I didn't get any error message when I type the commands: PLANTREGISTERCUSTOMSCRIPTS”, (COMMAND "ARX" "I" "PNP3DACPADAPTER") and (TESTACPSCRIPT "PSVFR"). It only doesn't seems right to me the creation of the folder _pycache_ with the file PSVFR.cpython-37.pyc. Is that correct? The two videos I saw, there were generated only a file .pyc with the same name of the python script.

Reply
Reply
0 Likes
Message 14 of 29

matt.worland
Collaborator
Collaborator

Plant3D 2022 now creates a _pychche_ folder to contain all of the pyc files. The pyc files also contain .cpython-37.pyc at the end of the original name. This is a change to 2021 and previous. As long as you are getting an object to appear at 0,0 then your python is generating correctly.

If my reply was helpful, please give a "Thumbs Up" or "Accept as Solution"
Reply
Reply
Message 15 of 29

mikael.santospj
Enthusiast
Enthusiast
Thanks!! That's what I wanted to know.
So, I am on the right way.
Reply
Reply
0 Likes
Message 16 of 29

nghiabt04
Advocate
Advocate
@mikael.santospj
May you ask about compiling way of python.
You are using P3D version 2022, right ? P3D 2022 using Python 3, when compiling in python 3, the folder __pycache__ will be created, this folder content .pyc (compiled file). P3D version 2021 and earlier using Python 2, when you compile, no such folder __pycache__ will create.
And you could ignore all of them, it does not affect the scripts
Reply
Reply
0 Likes
Message 17 of 29

mikael.santospj
Enthusiast
Enthusiast
Okay, thanks for sharing. I didn'd know this much
Reply
Reply
0 Likes
Message 18 of 29

mikael.santospj
Enthusiast
Enthusiast

I just want clarify one more detail if it is possible: I couldn't find any specialized book, article or library about how to use the shaps out of the box in Plant 3D. For example, I wanted to use the valve body in the folder: C:\Program Files\Autodesk\AutoCAD 2022\PLNT3D\ContentScripts\metadata\varmain\valvsub\cpva128sub\cpva128000sub.

When I call this function:

CPVA128000(s, D1=D11, D2=D22, L1=L11, L2=L22, H1=H11, H2=H22, W1=W11, W2=W22, D3=D33, H3=H33, A=A1, OF=OF1, B1=B11, B2=B22)

 

Do I have to provide the arguments in the same order, amount and units as they appear in the catalogue editor, isn't it? 

this didn't work much for me, plant said that it wasn't possisble to build the geometry with parameters.

My best regards

Reply
Reply
0 Likes
Message 19 of 29

matt.worland
Collaborator
Collaborator

Not all python parameters need to be shown in the catalog editor. To determine the parameters each ootb shape needs, you can study the scripts found in this zip file:

C:\Program Files\Autodesk\AutoCAD 2022\PLNT3D\ContentScripts\variants.zip

 

They need to be decompiled to read them and this link discusses different ways of reading those files:

https://forums.autodesk.com/t5/autocad-plant-3d-forum/how-to-decomplied-pyc-to-py/m-p/10748016#M5225...

If my reply was helpful, please give a "Thumbs Up" or "Accept as Solution"
Reply
Reply
0 Likes
Message 20 of 29

mikael.santospj
Enthusiast
Enthusiast

HY Guys, How are you all?

I have yet a few questions about this topic:

 

1 - We have supports with structural profiles. Is that possible to make the python script take a plant 3D steel profile and draw a member ? I don't know I was clear, but I imagined a line command in the script like: DRAW PLANTSTEELMEMBER(Member IPE-200 x 1005.82, INITIAL POINT, FINAL POINT)

 

2 - We have supports mounted on flanges instead on pipe, I was wonder if there was a way to import the shape at the top of the code: "from varmain.flangesub. ...". and use a command like getFlangeHubDiameter(). Is that possible?

 

Thanks

Reply
Reply
0 Likes