Total Pageviews

Monday, March 25, 2013

Python Scripting!

Python Scripting! 

Oh, how fun this is now... Oh, how horrible it was before figuring it out.  Documentation on this was scarce but if you dig around enough, you will find some stuff that is useful.

What is Python Scripting?

In P3D, you can generate parametric 3D objects to use in your specs and catalogs.  I have been making all kinds of aux steel supports for our Piping Design group.  The one below is a Beam with an Angle Trapeze.  The beam and the angles are all adjustable in size and the lengths, heights, and widths are adjustable as well.  This support is placed using the existing pipe and adjusts for the pipe diameter.


How is this done?

You start with a PY file.  This is the native Python file (which by the way, the name came from Monty Python).  You write code using a Python Editor.  I use this one:


You can find it at http://www.python.org/.  You might even need a decompiler if you are trying to edit the PYC (compiled PY files) that you can find in the Content folder hidden in the VARIANTS.ZIP file under CPAK Common.  The decompiler is found at https://sourceforge.net/projects/easypythondecompiler/

Your code needs to have certain items in order for it to work.  This was the most irritating thing of the entire process because I found no COMPLETE documentation on this process... so, I guess this is the first blog to include it.

First, you need the "import" information.  If you plan to use any math functions (like tan, cos, sin, pi) you need to import them into your code.  The highlighted yellow portion is your import.  I put it at the top of my code.

 
Then you need the "@activate" and "@param" information.  The @activate is the name of your PY file or how you want it to show up in the spec and catalog of Plant 3D.  Circled in RED is the one piece that had me stumped for a week and to why my code would not work or import into the catalog.  It is a simple "Ports=X" entry.  I could not find any documentation on this needing to be there so... you're welcome!  The @param is the list of parameters you want to show up in the Properties Dialog in Plant and also the items to fill out in the catalog.  These show =LENGTH only but you can use an =STRING if your entry is just a number, letter, or anything other than a length value.  Also, you can use =ANGLE for an angle value.
 

Next, write your code.  Use this link to get some good info on what the code should consist of.  https://knowledge.autodesk.com/community/article/316796

Once you write your code, test it in Plant 3D.  For info on how to test, go to this link:  https://www.autodesk.com/autodesk-university/class/Scripting-Components-AutoCADR-Plant-3D-2012  Download the HANDOUT(.DOC) in the upper right corner.  (Thanks Dave Wolfe!)

After testing, then add to your AutoCAD Plant 3D Catalog.  I created a separate Supports Catalog for my custom items.  Then add them to your PROJECT'S PipeSupportsSpec.pspx.  I Cap'ed and Bold PROJECT'S because that is another one of those things that will stump you.  Each project has a set of specs, including the PipeSupportsSpec.pspx file.  Make sure you add it there!

If you have any questions, email me.  jh2008jh@gmail.com

Enjoy!

________________________________________________________________
Acts 1:8 "But you will receive power when the Holy Spirit has come upon you,
and you will be my witnesses in Jerusalem and in all Judea and Samaria,
and to the end of the earth."


4 comments:

Unknown said...

Hi Scott,

I am also trying to figure out how to python scripting in Plant3D.

Can you let me know how to test the script in Plant3D?

Scott Hallmark said...

check the link I posted in this entry. It is an AU document. It details out the procedure very well.

Unknown said...

Очень хорошая статья. Давно пытаюсь сделать 3D динамические параметрические блоки в autocad P3D 2013. Можно более подробно рассмотреть создание одного такого элемента с самого начала?. Огромное спасибо.
----------------------
Very good article. Have been trying to make parametric 3D dynamic blocks in autocad P3D 2013. More to consider the creation of one such element from the beginning?. Thank you very much.

vietpdx said...

Enjoyed reading your blog entry. Thanks!

Supports has long been a sore spot in our utilization of plant 3D and doing this is a great workaround.

-Viet

http://www.protocad-inc.com