Testing a Python script - TESTACPSCRIPT

Testing a Python script - TESTACPSCRIPT

Anonymous
Not applicable
5,372 Views
23 Replies
Message 1 of 24

Testing a Python script - TESTACPSCRIPT

Anonymous
Not applicable

I cannot get TESTACPSCRIPT to run correctly, it returns nil. (similar to thread below). 

 

- My script is in 'C:\AutoCAD Plant 3D 2018 Content\CPak Common\CustomScripts'

 

- I have PnP3dACPAdapter.arx loaded

 

- I have run PLANTREGISTERCUSTOMSCRIPTS without errors and it has created the metadata files

 

but when I run (TESTACPSCRIPT "BOX01") it returns 'nil'

 

Where do I begin troubleshooting this? Thanks. 

 

 

https://forums.autodesk.com/t5/autocad-plant-3d-forum/custom-python-scripts/td-p/7086045

 

5,373 Views
23 Replies
Replies (23)
Message 2 of 24

Anonymous
Not applicable

Update:

 

I did find another post which talked about restarting Plant3D. So in this order...

 

1. PLANTREGISTERCUSTOMSCRIPTS

 

2. restart Plant3D

 

3. (arxload "PnP3dACPAdapter.arx")

 

4. (TESTACPSCRIPT "Box01")

 

I believe I'm reproducing the steps correctly, so the error may be in my script? Hard to tell without a debugger??

 

from varmain.primitiv import *
from varmain.custom import *
from math import *

 

@Anonymous(Group="Valve", TooltipShort="Box", TooltipLong="Test Box as a Valve", LengthUnit="in")
@group("MainDimensions")
@param(L=LENGTH, TooltipShort="Length")
@param(W=LENGTH, TooltipLong="Width")
@param(H=LENGTH, TooltipShort="Height")

 

def box01(s, L=1,W=1,H=1, OF=0,**kw):
s=BOX(s, L, W, H)

 

[TABS] where needed. like I said it compiles and generates the metadata. Thanks.

0 Likes
Message 3 of 24

Anonymous
Not applicable

Well, I'm getting there. After the last post I noticed some grammatical mistakes and unneeded parameters. I was also able to get an example script to work. But with my test script I'm getting this error:

 

Geometry can not be generated with the given parameters.nil

 

I'm curious what the '**kw' are for at the end of the def statement? Thanks. 

 

 

from varmain.primitiv import *
from varmain.custom import *
from math import *

 

@Anonymous(Group="Vessel", TooltipShort="Box", TooltipLong="Test Box as a Valve", LengthUnit="in")
@group("MainDimensions")
@param(L=LENGTH, TooltipShort="Length")
@param(W=LENGTH, TooltipShort="Width")
@param(H=LENGTH, TooltipShort="Height")

 

def Box01(s, L=10,W=20,H=30,**kw):
s=BOX(s, L, W, H)

 

 

0 Likes
Message 4 of 24

Anonymous
Not applicable

Unbelievable! So as it turns out I couldn't set the primitives default parameters directly. I feel like I'm starting the year off right! Now the hard part.

 

from varmain.primitiv import *
from varmain.custom import *
from math import *

@Anonymous(Group="Vessel", TooltipShort="Box", TooltipLong="Test Box as a Valve", LengthUnit="in")
@group("MainDimensions")
@param(Lx=LENGTH, TooltipShort="Length")
@param(Wx=LENGTH, TooltipShort="Width")
@param(Hx=LENGTH, TooltipShort="Height")

def Box01(s, Lx=10,Wx=20,Hx=30,**kw):
s=BOX(s, L=Lx, W=Wx, H=Hx)

0 Likes
Message 5 of 24

h_eger
Mentor
Mentor

Dear @Anonymous,

 

try this script:

 

import aqa.math
import math
from varmain.primitiv import *
from varmain.var_basic import *
from varmain.custom import *

@activate(Group="Vessel", TooltipShort="HE_Box", TooltipLong="Test Box as a Valve", LengthUnit="mm")
@group("MainDimensions")
@param(L=LENGTH, TooltipShort="Length")
@param(W=LENGTH, TooltipShort="Width")
@param(H=LENGTH, TooltipShort="Height")
@group(Name="meaningless enum")
@enum(1, "align X")
@enum(2, "align Y")
@enum(3, "align Z")

def HE_BOX(s, D = 500.0, W = 250.0, H = 1000.0, ID = 'HE_BOX', **kw):
    BOX(s, L=W, W=H, H=D).translate((0, 0, H / 2.0))
    s.setPoint((0, 0, 0), (0, 0, -1))
    s.setPoint((0, 0, H), (0, 0, 1))

-

If my reply was helpful, please give a "Kudo" or click the "Accept as Solution" button below (or both).

Hartmut Eger
Senior Engineer
Anlagenplanung + Elektotechnik
XING | LinkedIn

EESignature



Message 6 of 24

Anonymous
Not applicable

Well, your script didn't work either!!

0 Likes
Message 7 of 24

h_eger
Mentor
Mentor

Dear @Anonymous,

 

and it works !!!  Smiley Very Happy

 

http://autode.sk/2FdFVD8

-

If my reply was helpful, please give a "Kudo" or click the "Accept as Solution" button below (or both).

Hartmut Eger
Senior Engineer
Anlagenplanung + Elektotechnik
XING | LinkedIn

EESignature



0 Likes
Message 8 of 24

jpnoronha
Advocate
Advocate

Hi

When we use testacpscript in Plant what is in "" is not the name of the file but the description/name of the function.

So, in in the code is "HE_BOX" as below (attention to Caps).

def HE_BOX(s, D = 500.0, W = 250.0, H = 1000.0, ID = 'HE_BOX', **kw):

After entering "(arxload "PnP3dACPAdapter.arx")" in Plant command line i should use:

(testacpscript "HE_BOX")

Best regards

Message 9 of 24

DGRL
Advisor
Advisor

EDIT EDIT

 

Just got it to run 

Thanks for the thread

 

 

 

 

Dear @h_eger 

 

May i ask you what commands you used to make the script run?

I followed the whole thread but the script you provided in blue does not seems to work in P3D 2020

 

Regards

 

If this was of any help please kudo and/or Accept as Solution
Kind Regards
0 Likes
Message 10 of 24

h_eger
Mentor
Mentor

Dear @DGRL ,

 

first step:
create in your content folder
"AutoCAD Plant 3D 2020 Content" under "CPak Common" the folder with the name "CustomScripts"
All custom scripts are stored and processed in this folder.

 

second step:
add the file "PnP3dACPAdapter.arx" via "APPLOAD" in AutoCAD Plant 3D.

 

third step:
execute the "PLANTREGISTERCUSTOMSCRIPTS" command in an open Plant 3D drawing.
We compile the processing file HE_BOX.pyc from the script HE_BOX.py.

 

fourth step:
with the LISP routine "(TESTACPSCRIPT "HE_BOX")
the script HE_BOX.pyc is loaded and executed.

 

that was it.

-

If my reply was helpful, please give a "Kudo" or click the "Accept as Solution" button below (or both).

Hartmut Eger
Senior Engineer
Anlagenplanung + Elektotechnik
XING | LinkedIn

EESignature



Message 11 of 24

jignesh.chauhan
Explorer
Explorer

Thank you sir,

It is very useful..

Please keep sharing python related more information whatever you have!!!!

0 Likes
Message 12 of 24

Anonymous
Not applicable

Good Day. I would like to ask.. What is the use of the group declared meaningless enum as well as the align values below it. Still new this custom scripting.

0 Likes
Message 13 of 24

Anonymous
Not applicable

I've followed this procedure with the same script with HE_Box but it still returns a nil value upon testing. I've tried a lot of scripts that I believe works but when I run it in on my AutoCAD then check the catalog, it doesn't appear at all.
I'm really lost in this process. Is their any setup or procedure to perform first before using the command or is their any standard format to be followed in syntax?? Because I followed all of the instruction here and still doesn't generate the component.. 

0 Likes
Message 14 of 24

mlandmann
Participant
Participant

I cannot see a .pyc file appearing in the CustomScripts directory. Should there be?

 

Should the file with the script not end in .txt, but .py? 

 

Thanks so much for your help!! 

0 Likes
Message 15 of 24

h_eger
Mentor
Mentor

Dear @mlandmann ,

 

the file extension is * .PY
After you have executed the command "PLANTREGISTERCUSTOMSCRIPT" (in Plant 3D) the `* .PYC files are created.
Please read the documentation through which I sent you in the other post!

-

If my reply was helpful, please give a "Kudo" or click the "Accept as Solution" button below (or both).

Hartmut Eger
Senior Engineer
Anlagenplanung + Elektotechnik
XING | LinkedIn

EESignature



0 Likes
Message 16 of 24

andrzej.lach89
Observer
Observer

Hi,

I have created a simple Python app for testing custom scripts outside Plant 3D. It won't let you test if geometry is generated as intended, you can however find and fix syntax errors without the need to restart Plant 3D each time you change your script. The app covers all the primitive shapes, but another shapes from custom scripts or decompiled Plant scripts can be added running additional script.

https://github.com/AndrzejLach89/AutoCAD-Plant-3D-Script-Tester 

Message 17 of 24

theshoaib.mughal
Advocate
Advocate

Hi, I am trying to make some modifications to my script to test if I get the right geometry. But everytime i make a change and load the script into P3D using PLANTREGISTERCUSTOMSCRIPT, and followup with TESTACPSCRIPT, it shows me the very first version of the script geometry. The changes are not reflected in the geometry. What am I doing wrong here?

0 Likes
Message 18 of 24

theshoaib.mughal
Advocate
Advocate

Okay, Now I have figured out a way to adjust the script. The geometry is all good and finalized. Now, I am having trouble getting this script component in the catalog. I don't know what to do here. I have compiled the script, produced the standard images, and TESTACPSCRIPT as well.

 

PNG_32PNG_32

 

PNG_64PNG_64PNG_200PNG_200

 

 

PythonScript MetaDataPythonScript MetaData

 

CustomCatalog and its Content Folder (housing the PNGs)CustomCatalog and its Content Folder (housing the PNGs)

 

CreateComponent window from CatalogCreateComponent window from Catalog

 

CustomScript Folder with compiled script in itCustomScript Folder with compiled script in it

 

 

Now when I go to the Specs editor and try to Create a New Component, it shows me my component there but without any image. What is this and why is this? Any help??

 

Take a look at the screenshots

0 Likes
Message 19 of 24

matt.worland
Advisor
Advisor

Try to change the name of your py file to match the name of your function LD_FO_C.py

If my reply was helpful, please give a "Thumbs Up" or "Accept as Solution"
Message 20 of 24

theshoaib.mughal
Advocate
Advocate

Testing script command is (TESTACPSCRIPT "xYZabCd"). Remember the quoted words "xYZabCd" are the name of your function butt the name of script file. Also it's case sensitive. 

 

If this thing is not the problem then you have problem with code. Keep in mind 'PKANTREGISTERCUSTOMSCRIPT' command throws error only for improper syntax meaning of you forgot a comma, choosing a bracket etc.  It doesn't give error in geometry problem. Say for example you are subtracting one box from another but the according to your code the boxes are placed ina such a way that they do not overlap anywhere. This way testing will result in error because that's now an autocad function error. Also, indentation is very important if you use conditions such as 'if' or 'while' etc. It sometimes happen that you misplace an indentation and that may result a line of coke either exit the condition barrier or enters it which is not originally intended. Check for those. Use Notepad++ for editing (after changing is language to python)

Hope you got the idea

0 Likes