AutoCAD Plant 3D Forum
Welcome to Autodesk’s AutoCAD Plant 3D Forums. Share your knowledge, ask questions, and explore popular AutoCAD Plant 3D topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Python Scripting

10 REPLIES 10
SOLVED
Reply
Message 1 of 11
twdtech
4807 Views, 10 Replies

Python Scripting

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.

 

10 REPLIES 10
Message 2 of 11
twdtech
in reply to: twdtech

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?

Message 3 of 11
twdtech
in reply to: twdtech

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.

Message 4 of 11
TRdesigner82
in reply to: twdtech

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

Message 5 of 11

Please solution

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

Message 6 of 11

Up.

 

I'm also interested. Please share the solution.

 

Thanks

Message 7 of 11

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
in reply to: twdtech

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"

Message 9 of 11
vsungur
in reply to: Anonymous

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?

Message 10 of 11
Brandon.Warren
in reply to: vsungur

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!!

Message 11 of 11
theshoaib.mughal
in reply to: vsungur

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

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost