How to create multiple parametric components using python scripting

How to create multiple parametric components using python scripting

tinuthomasGE9RJ
Advocate Advocate
2,640 Views
14 Replies
Message 1 of 15

How to create multiple parametric components using python scripting

tinuthomasGE9RJ
Advocate
Advocate

Hai team,

           I'm a beginner in plant 3D custom parametric component creation using python scripting. I'm facing difficulties in creating multiple components using scripting. In AutoCAD Plant 3D 2023 Content\CPak Common\custom script folder  I could create one component at a time, if I go for another component, it shows error. So, how can I create multiple components in plant 3D using scripting.

 

0 Likes
Accepted solutions (1)
2,641 Views
14 Replies
Replies (14)
Message 2 of 15

h_eger
Mentor
Mentor

dear @tinuthomasGE9RJ ,

 

yes, that's the way it's meant to be.

You can add some parameters to the script but they will only refer to one component.

There are no multicomponent Python scripts in AutoCAD Plaant 3D.

-

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 15

tinuthomasGE9RJ
Advocate
Advocate

I created a new component using scripting under custom script folder. If I need a new component again by scripting how I will create, or it is not possible?? I tried to create one new script and I put it inside custom script with older script (because I need both components) but after registering and testing the older component is missing from my catalog, 

0 Likes
Message 4 of 15

matt.worland
Advisor
Advisor

Each script is meant for one inline P3D part. You can have multiple shapes that create a single part, but when you go to place the shape in P3D it all needs to be called from a single python file. 

This link shows an example of creating several Box and Cylinder shapes and a custom bolt shape to create a support. It is built from two python files and shows how to use two python files in a single python file. This will allow you to create many shapes but use only one python file for your P3D part.

 

https://stackoverflow.com/questions/48369585/create-custom-component-in-plant3d-with-python

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

tinuthomasGE9RJ
Advocate
Advocate

sir,

    this post was very helpful for me in making a support with different parts, I need to know how I create different supports. There are number of supports, flanges, olets etc. is there inside a catalogue, I like to create a catalogue containing components which is created using scripting. I created one new component inside custom script folder, if I need to create a new component again how I will create it?? I tried like; created a new python script for my new component and placed it in Custom Script folder with the previously created component. but it is not working. so how I handle this problem?

0 Likes
Message 6 of 15

matt.worland
Advisor
Advisor

Yes, for each support type, you will need a new python file. Each time you put a new python file in the Custom Scripts folder, you must run the PlantRegisterCusomtScripts command in P3D. Then close and re-open P3D to test your new python file. If you get an error in the PlantRegisterCustomScripts command, you will need to troubleshoot your latest file to determine where the error is coming from.

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

tinuthomasGE9RJ
Advocate
Advocate

I tried like this only, but after creating second component the first one is not available for use. why it's happening? And the .Png files (32,64,200); how we will distribute for each component in same folder (Custom Script folder) 

0 Likes
Message 8 of 15

matt.worland
Advisor
Advisor

In your CustomScripts folder, you should have a PY file for each python script and the accompanying PNG files. Then after a successful PlantRegisterCustomScripts run, you will get an XML named the same as your PY file and in the _pycahce_ folder, you have a PYC for each python script.  After the prcs command, you will also get a ScriptGroup.xml, variants.map, and variants.xml files.

 

You only need to test each file once, after it succeeds, you need to add it to your catalog and spec to insert it as a standard component.

 

Check through the helpful links provided in your other posts as they explain how to create a python component. Then get one item working from the beginning through inserting it from a spec. Once you have that working, move on to the next component. Without files or screenshots its hard to tell what you have done.

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

tinuthomasGE9RJ
Advocate
Advocate

Thank you for reply.....Actually i"m getting the components but the preview images are not available; 

below shows how i saved inside custom scripts;

tinuthomasGE9RJ_0-1668062327809.png

 

in Spec Editor;

 

tinuthomasGE9RJ_1-1668062426912.png

why this happening?? 

 

 

0 Likes
Message 10 of 15

matt.worland
Advisor
Advisor
Accepted solution

That looks semi-correct with a bit of guessing.

I'm not sure what the extensions are for your expansion joint images. Some of your files have extensions showing while others don't, and I'm guessing that if you turn on extensions for your files, you will see that some have duplicate extensions.

 

Turn on your extensions here:

2022-11-10_9-19-35.png

 

 

Then make sure that your PY and PNG file names are exactly the same, with the exception of the _size at the end of the images.

 

You should have the following:

EXPJOINT1.py

EXPJOINT1.xml

EXPJOINT1_32.png

EXPJOINT1_64.png

EXPJOINT1_200.png

 

As far as I'm aware, it only takes a matching _200.png file to be found, so the image shows in the Spec and Catalog.

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

tinuthomasGE9RJ
Advocate
Advocate

it's working thankyou sir.........

0 Likes
Message 12 of 15

matt.worland
Advisor
Advisor

Glad to hear it. Also, be cautious of case-sensitive names; make sure everything is EXACTLY the same.

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

shreya_valte
Participant
Participant

I am trying to create a support in using python script.
I had written the code, and its working fine shape is created when I checked it in plant3D. But the group type support is not visible in spec.
How can I solve this.

0 Likes
Message 14 of 15

h_eger
Mentor
Mentor

@shreya_valte ,

 

can you please describe the whole process of how you compile your Python script and add it to the support catalogue so that you can then assign it in the support spec so that you can use this component in P3D?

-

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

shreya_valte
Participant
Participant

how to give tag number to support, I know its possible using .net API but this tag number will go from python script, so how can i assign that tag to that support and then using .net reflect it in properties

 

0 Likes