Custom Python Supports calling other custom scripts

Custom Python Supports calling other custom scripts

dmckagueN6VZ3
Enthusiast Enthusiast
4,033 Views
13 Replies
Message 1 of 14

Custom Python Supports calling other custom scripts

dmckagueN6VZ3
Enthusiast
Enthusiast

Hello all,

We currently use python scripts for custom supports. I have been trying to find a way to add new 'primitive' shapes that I can use in the scripts. For example, instead of creating 3 BOXES every time I need to make a channel shape, I just want to write a script creating our most used channel sizes, then call that channel script once in the final support script. Is this possible?

I have called OOTB python scripts into my custom support scripts just by including, for example, "from varmain.divsub.cbolt6_001 import CBOLT6_001". But I am not sure how to translate that to use a script from the custom path. I have also tried to add my own compiled custom scripts to the 'variants.zip' folder and then calling them using the same import style but didn't have success. I'm assuming because the activation of the OOTB and custom scripts are different.

If anyone could offer assistance it would be greatly appreciated!

Accepted solutions (1)
4,034 Views
13 Replies
Replies (13)
Message 2 of 14

李榕华|Ronghua.LI
Advisor
Advisor

You can refer to the following link:

https://forums.autodesk.com/t5/autocad-plant-3d-forum/python-scripting/m-p/6900759#M26125 

 

 


李榕华

13489140049@qq.com




0 Likes
Message 3 of 14

rajendra.prajapat
Advisor
Advisor
Accepted solution

@dmckagueN6VZ3  please use below lines to call the python script from custom script folder.

 

import os
import sys
sys.path.insert(0, 'C:\AutoCAD Plant 3D 2021 Content\CPak Common\CustomScripts')

from (script name) import *

If my reply was helpful, please give a "Kudo" or click the "Accept as Solution" button below (or both).
0 Likes
Message 4 of 14

dmckagueN6VZ3
Enthusiast
Enthusiast

Our custom scripts and shared folder are on a network drive. Would it still work the same if I just enter the network path instead of the C:\ drive path or will it have to be stored local?

0 Likes
Message 5 of 14

rajendra.prajapat
Advisor
Advisor

@dmckagueN6VZ3 just replace the path and checked.if it will not work then please let me know.

If my reply was helpful, please give a "Kudo" or click the "Accept as Solution" button below (or both).
0 Likes
Message 6 of 14

matt.worland
Advisor
Advisor

Hello @rajendra.prajapat,
I see you are adding it to the first position, is there a benefit to adding it there instead of appending it to the end?

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

rajendra.prajapat
Advisor
Advisor

@matt.worland no benefits , it is just practice.

If my reply was helpful, please give a "Kudo" or click the "Accept as Solution" button below (or both).
0 Likes
Message 8 of 14

matt.worland
Advisor
Advisor

Thanks, one thing we have noticed is that it can be added multiple times. Be sure to check if it exists before adding:

scriptpath = os.path.normpath(sys.PnP3dNativeContentCustomScriptsPath)
if scriptpath not in sys.path:
  sys.path.append(scriptpath)
If my reply was helpful, please give a "Thumbs Up" or "Accept as Solution"
Message 9 of 14

dmckagueN6VZ3
Enthusiast
Enthusiast

Looks to be working from the network path given. I have not added it to a catalog or spec and tested yet but it works when testing the script with (TESTASCRIPT "").
However, I am having another issue now. I can call my secondary script and use it in another, but whenever I try to rotate or translate the object created with the script it will not run. Below is a small snippit of my test code.

 

def TESTW4(s, N = 0.0, D = 3.50, L = 72.0, ID = 'SPS-W4', **kw):

 

# Location Parameters
R1 = D / 2.0

 

# Structural members
s1 = W4x13(s, E = L/2)
s1.rotateX(90)

 

If I leave out the line "s1.rotateX(90)", it works fine and creates my W4x13 beam from my secondary script. But if I add that line, or a translate or anything else, I get the error "Geometry can not be generated with the given parameters.nil". There are no errors when registering the script though. Is this not possible?
Any suggestions?

Message 10 of 14

plantinfo28
Contributor
Contributor

@dmckagueN6VZ3  check the indention error.

0 Likes
Message 11 of 14

rajendra.prajapat
Advisor
Advisor

@dmckagueN6VZ3  

please use this s1.rotateX(90.0).

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

phantri.bl
Contributor
Contributor

Hi,

How to creat quickly L or C or H channel without 2 BOX or 3 BOX in python ?

What is the command? if you have experience or you can creat quickly. Pls teach me.

Tks

0 Likes
Message 13 of 14

l_fatych
Enthusiast
Enthusiast

In the sub-function return the body - I tried and it works.

Example

def W4x13(s, N = 0.0, D = 3.50, L = 72.0, ID = 'SPS-W4', **kw):

       o1=BOX(..........)

       return o1

 

0 Likes
Message 14 of 14

Fahad_YK
Enthusiast
Enthusiast

Hi @rajendra.prajapat ,
Do You ever develop custom Python support based on company pipe support standards?
I'm planning to develop a custom Python support based on my company's pipe support standard.

Do You have any advice on how I do it and where to start?

0 Likes