Importing a Custom Script in a Python Module

Importing a Custom Script in a Python Module

EddyWagner
Advocate Advocate
528 Views
4 Replies
Message 1 of 5

Importing a Custom Script in a Python Module

EddyWagner
Advocate
Advocate

Hi all,

I found a way to import a custom part in a Plant 3D Python script.
I used the post below as a reference, but I’m receiving the following message from Plant:

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

message:

Command: PLANTREGISTERCUSTOMSCRIPTS

Command: Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "varmain\custom.pyc", line 372, in dumpAll
  File "varmain\custom.pyc", line 326, in dumpAll
  File "varmain\custom.pyc", line 307, in dumpFile
  File "<frozen importlib._bootstrap_external>", line 407, in _check_name_wrapper
  File "<frozen importlib._bootstrap_external>", line 907, in load_module
  File "<frozen importlib._bootstrap_external>", line 732, in load_module
  File "<frozen importlib._bootstrap>", line 265, in _load_module_shim
  File "<frozen importlib._bootstrap>", line 696, in _load
  File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 728, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "t:\plant3d\00 - catalogos\cpak common\customscripts\testes\CPVKSOFL0000.py", line 4, in <module>
    from ANEL_SMS import *
ModuleNotFoundError: No module named 'ANEL_SMS'

And now, when I run the test, I get this message:

Command: (testacpscript "CPVKSOFL0000")
Script CPVKSOFL0000 not found...
nil

Here is my Python code:

import os
import sys
sys.path.insert(0, "T:\\Plant3D\\00 - Catalogos\\CPak Common\\CustomScripts")
from ANEL_SMS import *
from varmain.custom import *
from aqa.math import * 
import math

@activate(Group="Flange", TooltipShort="SO Flange", TooltipLong="Slip On Flange", FirstPortEndtypes="FL", LengthUnit="mm",  Ports="2")
@group("MainDimensions")
@param(D=LENGTH, TooltipShort="Outer Diameter of the Flange", TooltipLong="Outer Diameter of the Flange")
@param(D1=LENGTH, TooltipShort="Pipe Diameter", TooltipLong="Pipe Diameter")
@param(T=LENGTH, TooltipShort="Length of the Flange", TooltipLong="Length of the Flange")
@param(OF=LENGTH, TooltipShort="Thickness offset", TooltipLong="Thickness offset")

#PLANTREGISTERCUSTOMSCRIPTS
#(arxload "PnP3dACPAdapter")
#(testacpscript "CPVKSOFL0000")

def CPVKSOFL0000(s,D=210.0, D1=114.3, T=10.0, OF=-1,**kw):
    bla=ANEL_SMS(s, OD1=50.0,ID1=24.0,H=5.5)
    return

 

 

 

0 Likes
Accepted solutions (1)
529 Views
4 Replies
Replies (4)
Message 2 of 5

Michiel.Valcke
Advisor
Advisor
Accepted solution

I suppose your T: drive is an external drive, can you try to put it local? or replace t: with the actual adress?

Message 3 of 5

matt.worland
Advisor
Advisor

Where does ANEL_SMS reside? Is it a PY file?

Based on the error, it can't find that file:

  File "t:\plant3d\00 - catalogos\cpak common\customscripts\testes\CPVKSOFL0000.py", line 4, in <module>
    from ANEL_SMS import *
ModuleNotFoundError: No module named 'ANEL_SMS'
If my reply was helpful, please give a "Thumbs Up" or "Accept as Solution"
Message 4 of 5

EddyWagner
Advocate
Advocate

Hi,
Thank you, @Michiel.Valcke  — changing the drive letter "T:" to the full path of the NAS server resolved the issue.

@matt.worland , yes, ANEL_SMS is a .py file, but the problem was the use of "T:" as the drive letter for my NAS server.

Thank you!

Edit:

Another issue might be when the .py file is open during the execution of the PLANTREGISTERCUSTOMSCRIPTS command.
That might actually be the real problem...

0 Likes
Message 5 of 5

h_eger
Mentor
Mentor

Please always specify the UNC path when linking *.py files. Anything else cannot be resolved under Windows.

-

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