How to Set the Parameter value for Python Custom Script ?

How to Set the Parameter value for Python Custom Script ?

Anonymous
Not applicable
2,677 Views
19 Replies
Message 1 of 20

How to Set the Parameter value for Python Custom Script ?

Anonymous
Not applicable

Hi, Experts

Following is a part of my Sample Python Script 

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

 

# Write Metadata Section
@activate(Group="Support", TooltipShort="SAMPLESUPPORT", TooltipLong="SAMPLESUPPORT", LengthUnit="mm", Ports=1)
@group("MainDimensions")
@param(D=LENGTH, TooltipLong="Pipe Diameter")
@param(SL=LENGTH, TooltipLong="Plate Length")
@param(SW=LENGTH, TooltipLong="Plate Width")
@param(SH=LENGTH, TooltipLong="Plate Height")
@param(VOL=LENGTH, TooltipLong="Plate Volume")

 

def SAMPLESUPPORT(s, D = 100, SL = 1000.0, SW = 2000.0, SH = 3000.0, VOL = 0.0, ID = 'SAMPLESUPPORT', **kw):

    box = BOX(s, L=SL, W=SW, H=SH)
    VOL = SL * SW * SH

 

=============================

VOL is a parameter which I want to set the volume of box after I create the box and I expect the VOL parameter to be changed according to the variable value of Width, Height, Length of the box.

 

(VOL = SL * SW * SH) is not effective because VOL always stays same as zero(0)

 

Thank You.

Reply
Reply
0 Likes
Accepted solutions (1)
2,678 Views
19 Replies
Replies (19)
Message 2 of 20

h_eger
Mentor
Mentor

I only have one question:
Where did you get the information from custom Python scripts for the construction of Autodesk AutoCAD Plant 3D objects?

-

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



Reply
Reply
0 Likes
Message 3 of 20

jabowabo
Mentor
Mentor
Accepted solution

There isn't a documented function that will accomplish this. The parameter values do not update based on what happens in the body of the script* - they only read what is defined in the params line.

 

*The setLinearDimension function does update the parameter values but it feeds them back into the params line.

Reply
Reply
Message 4 of 20

Anonymous
Not applicable

Thank You, Jabowabo

Reply
Reply
0 Likes
Message 5 of 20

mikael.santospj
Enthusiast
Enthusiast

Hi GUYS, HOW ARE YOU ALL

I don't know if this is the right thread to ask this, but we have an inline instrument whose flange face to face distance is variable. I would like to insert this item in the instrumentation spec and let the user define this distance in the properties of the component. Is that a way to do that other than the custom part?

Thanks

Reply
Reply
0 Likes
Message 6 of 20

h_eger
Mentor
Mentor

Dear @mikael.santospj ,

With it your wishes come true

# 2 - "Parametric" Component Designation

-

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



Reply
Reply
0 Likes
Message 7 of 20

mikael.santospj
Enthusiast
Enthusiast

Thanks, you are absolutelly right, that's it.

Reply
Reply
0 Likes
Message 8 of 20

mikael.santospj
Enthusiast
Enthusiast

mikaelsantospj_0-1649767474133.png

Only to show, we do need this customization for PSV's and control valves in the instrumentation spec, for example.

Thanks

Reply
Reply
0 Likes
Message 9 of 20

jflorita
Advocate
Advocate

Hello everyone,

 

I would like to share that I have developed a customized support system using Python script. However, there is a certain parameter that is optional, and I intend to have it hidden if the value of the parameter is zero. Unfortunately, it appears that I am unable to input zero as a value.

 

Thank you

Reply
Reply
0 Likes
Message 10 of 20

h_eger
Mentor
Mentor

Dear @jflorita ,

 

I don't know any way to do this.

-

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



Reply
Reply
Message 11 of 20

jflorita
Advocate
Advocate

Thank you for your response @h_eger 

Reply
Reply
0 Likes
Message 12 of 20

theshoaib.mughal
Advocate
Advocate

I hope I am in the right forum. Could anyone guide me if it's possible to change the component family description on-the-go?

 

Let me explain the need. I have  coded the cable tray script that allows from switching between solid bottom, perforated bottom and ladder type after they are placed in the plant3d. I have defined a parameter that listens to these changes. And it works fine. Although for my BoM and isometric I like to change the component description as well with these changes so that the BoM represents the part that is currently placed in the model. Trouble is that this information is stored in the metadata whereas the changes to shape happen in the body of the code. Is there a way to access the metadata and change it from the body of the code. 

 e.g.

Shape =0 means solid

Shape =1 means perforated

Shape =2 means ladder

 

So if i choose either value, the IF loop in the code executr relevant portion only and i get the desired result. I wonder if I could insert a code line for changing the component description in these IF loops. 

 

Any thoughts??

Reply
Reply
0 Likes
Message 13 of 20

theshoaib.mughal
Advocate
Advocate

One more thing. Is there a way to make a copy of an object. I hate to code same components over and over. If i could make a copy and move it with translate command then it will be a treasure

Reply
Reply
0 Likes
Message 14 of 20

jabowabo
Mentor
Mentor

@theshoaib.mughal wrote:

I hope I am in the right forum. Could anyone guide me if it's possible to change the component family description on-the-go?

 

Let me explain the need. I have  coded the cable tray script that allows from switching between solid bottom, perforated bottom and ladder type after they are placed in the plant3d. I have defined a parameter that listens to these changes. And it works fine. Although for my BoM and isometric I like to change the component description as well with these changes so that the BoM represents the part that is currently placed in the model. Trouble is that this information is stored in the metadata whereas the changes to shape happen in the body of the code. Is there a way to access the metadata and change it from the body of the code. 

 e.g.

Shape =0 means solid

Shape =1 means perforated

Shape =2 means ladder

 

So if i choose either value, the IF loop in the code executr relevant portion only and i get the desired result. I wonder if I could insert a code line for changing the component description in these IF loops. 

 

Any thoughts??


There is no link between the two. You would need 3 different spec items with different descriptions if you don't want to modify them in the model. 

 

This can only be automated via the .NET API. Related info: https://forums.autodesk.com/t5/autocad-plant-3d-p-id-ideas/where-we-can-get-dimensions-of-python-scr...

Reply
Reply
0 Likes
Message 15 of 20

jabowabo
Mentor
Mentor

@theshoaib.mughal wrote:

One more thing. Is there a way to make a copy of an object. I hate to code same components over and over. If i could make a copy and move it with translate command then it will be a treasure


I don't think it's possible to copy items. You can import items from other scripts multiple times though: https://forums.autodesk.com/t5/autocad-plant-3d-forum/custom-python-supports-calling-other-custom-sc...

Reply
Reply
0 Likes
Message 16 of 20

theshoaib.mughal
Advocate
Advocate

3 specs is kinda long way around although it gets the job done but the other option seems promising. I will give that a try and see what happens. 

Reply
Reply
0 Likes
Message 17 of 20

theshoaib.mughal
Advocate
Advocate
Hmm. Thats a thought. Not suitable for my current problem as i want copying the object created in same script. But its gonna be useful in other because most of the begining blocks for creating shapes are usually simple and same. It can help me there. Thanks 😉
Reply
Reply
0 Likes
Message 18 of 20

jabowabo
Mentor
Mentor

@theshoaib.mughal wrote:

3 specs is kinda long way around although it gets the job done but the other option seems promising. I will give that a try and see what happens. 


Three items, based on the same script with appropriate shape values and descriptions, in one spec.

Reply
Reply
0 Likes
Message 19 of 20

theshoaib.mughal
Advocate
Advocate

Hello guys. One quick question. I have to work with reducers. I added 'custom' in the specs editor so I can the parameter in the drawing. Now this has caused a trouble. The component size in the catalog and specs was 300x100 (in mm) so port 1 was 300 and port 2 was 100. If I place it as is then its all good. But if i change size of either port say e.g. make it 400x100 the two things happen;

1. Since the '+' sign adds a corresponding pipe to the port; it doesn't add a corresponding 400 size pipe instead it adds a 300 size pipe which is default size of the component. I want it to add a 400 size pipe

2. The description of reducer in isometric is still 300x100 even if I manually add a 400 size pipe. How can I change the description of port size to 400x100 in this case?

 

I know there maybe a reducer defined for 400x100 size but what if there is a size that isnt defined then what??

Reply
Reply
0 Likes
Message 20 of 20

jflorita
Advocate
Advocate

Hello @theshoaib.mughal 

I think you should make a new post regarding your concern. This thread is for python scripting, and it is also marked as solved, but I'll answer it anyways.

 

What you changed were only the parameters of the 3d model, if you want to change the size you have to do it in the spec editor, else it won't work. If you want a 400x100 then register it, you can't change nominal sizes of components in the properties.

Reply
Reply
0 Likes