Python Valve Parameter Restriction

Python Valve Parameter Restriction

Rolly.Pagod
Contributor Contributor
1,161 Views
6 Replies
Message 1 of 7

Python Valve Parameter Restriction

Rolly.Pagod
Contributor
Contributor

Hi Plant3Diers's, can you help me regarding python script valves. Want to limit/restrict/hide some dimensional parameters from the properties tool palette.

RollyPagod_0-1669971570632.png

 

0 Likes
Accepted solutions (2)
1,162 Views
6 Replies
Replies (6)
Message 2 of 7

h_eger
Mentor
Mentor
Accepted solution

Dear @Rolly.Pagod ,

 

Python scripts are user-defined and are treated as such in Autodesk AutoCAD Plant 3D.
I am not aware that some parameters can be disabled or hidden in the property manager.

-

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 3 of 7

matt.worland
Advisor
Advisor
Accepted solution
You can 'hide' them inside a different script. You don't need to build every shape in the script that is called by Plant3D or any shapes really.
Your script which is called by P3D can be an overall script that knows which part to insert. Then you could have smaller scripts that are called to generate the parts.
So for your valve, you could simply have one parameter of the valve tag. Then your smaller scripts look up that specific valve tag to find the specific parameters.
If my reply was helpful, please give a "Thumbs Up" or "Accept as Solution"
Message 4 of 7

traiduong014969
Collaborator
Collaborator
Dear sir, Matt Worland
The same problem with numerous parameters appearing in properties when I click on the valve applies to me as well. I don't really understand your strategy. Could you provide me with a sample piece of code to execute it?
0 Likes
Message 5 of 7

matt.worland
Advisor
Advisor

Hello @traiduong014969,

I have attached some example files for testing.

There is an image showing the parameters in the Catalog Editor.

CatImage.png

There is a sample dwg showing the three different options for the valves

Then two python scripts. TestValve.py passes in the parameters from the spec. test_valve_modeler.py does the work. In this example, there is only one parameter TAG, it accepts 3 values; 1, 2, or 3. Each TAG will draw a different sized valve, but it could be any number of changes. This is a simple example with only one parameter, but if you pass in more parameters, its easier to pass them in as an array.

def TestValve(s, TAG= 1, **kw):
    spec_params = {'s': s, 'TAG': TAG, 'specKw': kw}
    valve = Test_Valve_Modeler(spec_params, **kw)
    valve.build_model()

This parameter gets passed into a modeler file where the other parameters are found. Currently they are hard coded, but you could get these values from an external source if needed.

# Check Tag and get these parameters from an outside source, Excel, JSON, ...
if self.tag == 1:
    part_params = {'D': 8.625, 'L': 15.0, 'H': 8.625}
elif self.tag == 2:
    part_params = {'D': 10.625, 'L': 25.0, 'H': 10.625}
elif self.tag == 3:
    part_params = {'D': 12.0, 'L': 36.0, 'H': 12.0}

 

Hopefully this provides a bit more information on how to hide some parameters in the catalog and properties palette.

 

NOTE: This does not need to be created in a class or separate files. Its just how I break my code apart for easier reading and debugging.

 

Let me know if you have any questions.

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

traiduong014969
Collaborator
Collaborator

Thank you for your reply.

I just tested with sample code. It's working so well. However, I only an issue want to ask you. I try to make parameter "TAG" to properties palette., but it doesn't show this property thought I try to insert "Parametric" to component designation in spec editor. You can see some snapshot below:

traiduong014969_0-1693019537785.pngtraiduong014969_1-1693019584977.png

 

0 Likes
Message 7 of 7

matt.worland
Advisor
Advisor

To adjust the properties in the model your valve script and method names need to be prefixed with CPV. Try renaming the script to CPVTestvalve. And choosing TAG was a bad example on my part, since that is a standard property for Plant 3D. I would change that to ValveTypeTag or anything else that is not a standard property.

So to show the property in the model try using something like this:

 

@Anonymous(Group='Valve, ValveBody', TooltipShort='CPVTestValve', TooltipLong='CPV TestValve', LengthUnit='in', Ports='2')
@group('MainDimensions')
@param(ValveTypeTag=ENUM, TooltipLong='1, 2, 3')
@enum(1, 'ValveTag1')
@enum(2, 'ValveTag2')
@enum(3, 'ValveTag3')
def CPVTestvalve(s, ValveTypeTag=1, **kw):
    try:
        spec_params = {'s': s, 'TAG': ValveTypeTag, 'specKw': kw}
        valve = Test_Valve_Modeler(spec_params, **kw)
        valve.build_model()

    except Exception:
        print("Failed to build a valve")

 

With those changes and making the part Parametric in the Spec, you should see this:

mattworland_0-1693406568626.png

 

If my reply was helpful, please give a "Thumbs Up" or "Accept as Solution"
0 Likes