Python Scripting

Python Scripting

twdtech
Advocate Advocate
6,239 Views
10 Replies
Message 1 of 11

Python Scripting

twdtech
Advocate
Advocate

I am using Python scripts to create custom pipe supports but, there is a problem when I try to import a custom script into another custom script. The host script runs successfully in test but, does not run in production. I have successfully imported standard Plant 3D Python scripts into custom scripts and therefore believe the problem may have something to do with the syntax of the import declaration. Below are the import declarations used in the host script. "B1A" is the custom script I am importing.

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

Any help would be appreciated.

 

Accepted solutions (1)
6,240 Views
10 Replies
Replies (10)
Message 2 of 11

twdtech
Advocate
Advocate

I have an update to this problem. If I run the import script "B1A" into a drawing, I can then successfully run the host script which is importing script "B1A". However, if I do not place "B1A" into a drawing then the host script will not run. Anyone know how I can fix this problem?

0 Likes
Message 3 of 11

twdtech
Advocate
Advocate
Accepted solution

I have found the solution. It was a pathing issue. Once I added a reference in the script to the path of the CustomScripts folder the issue was resolved.

0 Likes
Message 4 of 11

Anonymous
Not applicable

I think I'm having the same problem. Can you post your script and tell me what  you changed to make it work?

0 Likes
Message 5 of 11

Anonymous
Not applicable

Please solution

 Can you post your script and tell me what  you changed to make it work?

0 Likes
Message 6 of 11

Anonymous
Not applicable

Up.

 

I'm also interested. Please share the solution.

 

Thanks

0 Likes
Message 7 of 11

sschachinger
Contributor
Contributor

I currently also had the same problem - and i have found the solution.

With the following script-code the path to the custom-scripts will be added to the search-paths:

import os
import sys
sys.path.append(os.path.normpath(sys.PnP3dNativeContentCustomScriptsPath))

After that you can use

from B1A import *

for loading the custom script "B1A".

Message 8 of 11

Anonymous
Not applicable

Python scripting is easier than other languages. In this, we will use the extension .py, just to help us know that the script contians python code and not standard UNIX shell commands.

The first script that we will use will be a simple script that will output the text "Hello Python". You can use any file editor, personally, I use vi. Create a file named "hello.py" and use the following for its contents:

#!/usr/bin/env python
# This is my first script.

print "Hello Python"

0 Likes
Message 9 of 11

Anonymous
Not applicable

Hello,

I am trying to learn to write script  with phyton.

When I  type below line, it gives me errror "

 

 

from varmain.flangesub.cpfwo import  "ImportError: No module named varmain.flangesub.cpfwo"

 

is there anybody to help me?

0 Likes
Message 10 of 11

Brandon.Warren
Explorer
Explorer

Anyone at all? I'm having the same issue, go to register the script and Plant 3D is telling me there is no module named ******......... Please help.  Post up your Python knowledge please!!

0 Likes
Message 11 of 11

theshoaib.mughal
Advocate
Advocate
Try changing ‘varmain.flangesub.cpfwo’ to ‘varmain.flangesub_cpfwo’. Because ‘flangesub’ is the group name under which ‘cpfwo’ function is defined. If i assume correctly you are trying to access that function from that script. Also add an asterik (*) after the import if you dont specifically what to look for
0 Likes