imran khan
imran khan

Reputation: 21

I need to convert a python script developed in ABAQUS PDE to an executable file

I want to convert a python script to an executable file. This python script will call another python script, which is the requirement.

Script :

from abaqus import *
from abaqusConstants import *
import __main__
import allAbaqusMacros

def Macro1():

import section
import regionToolset
import displayGroupMdbToolset as dgm
import part
import material
import assembly
import step
import interaction
import load
import mesh
import optimization
import job
import sketch
import visualization
import xyPlot
import displayGroupOdbToolset as dgo
import connectorBehavior
import os

execfile('C:\\\\Users\\\\Me\\\\Desktop\\\\Sample.py')""") - This also works

However, the code works only in ABAQUS PDE (Similar to VBA editor in Excel)

To track the usage of the few python scripts, I am doing this. I know we can run it from File->RunScript or in the CLI with an Abaqus Command. But that's not the requirement.

I want it as a file, which will run the other desired script on a single-click. Also, I have tried it as a batch file to run it in the command prompt.

Batch Command :

"C:\SIMULIA\Abaqus\6.14-3\code\bin\abq6143.exe" cae script =C:\Users\Me\Desktop\Sample.py %*

This works but it starts a new session. I have used "noGUI" instead of script, but

I get this error Message

getInputs cannot be used with the -noGUI option.

Also, I have tried running it using the below command as well.

C:\Python27\python.exe C:\Users\Me\Desktop\Sample.py

For this, the error message was

Traceback <most recent call last>:
  File "C:\Users\Me\Desktop\Sample.py", line 1, in <module>
    from abaqus import *
  File "SMAPyModules\SMAPyaAbqPy.m\src\abaqus.py", line 5 in <module>
  File "SMAPyModules\SMAPyaUtilsPy.m\src\i18n.py", line 1 in <module>
  File "SMAPyModules\SMAPyaUtiPy.m\src\uti.py", line 5 in <module>
  File "SMAPyModules\SMAPyaUtiPy.m\src\utiinternal.py", line 52 in <module>
  File "SMAPyModules\SMAPyaUtiPy.m\src\uticty.py", line 145 in <module>
  File "SMAPyModules\SMAPyaUtiPy.m\src\uticty.py", line 136 in _loadAbaqusDll
Value Error : dll not found : ABQSMABasShared.dll

Press any key to contuinue...

Is there any way to convert a Python script developed in Abaqus PDE or any Plug-in Development Environment to an executable file? Please help

Upvotes: 0

Views: 1815

Answers (1)

Matt P
Matt P

Reputation: 2347

The Abaqus/Python API is useful for a variety of purposes, including pre/post-processing tasks, GUI building, and creating macros. I can see that you're just getting started and are operating under a number of misconceptions, so I will gently nudge you toward carefully reading the official docs, which answer all of your questions and more, very completely1.

However, because those docs might seem like quite a lot of information to absorb, I'll try to give you a few helpful tips to start with.

  1. You can not access Abaqus modules using only a standard Python installation, such as you have attempted with the command python file_name.py.
  2. You may run general Python scripts from the system shell (CMD or Bash, for example) using the same Python bundled with Abaqus using abaqus python [file_name.py].
  3. You can start an interactive Python session from the system shell if you type only abaqus python. Note, this is not part of the Abaqus kernel process - meaning you can't import any Abaqus-related modules this way, but the Python standard library should be available.
  4. Abaqus modules require access to the CAE kernel (and license) if the object/functionality you want is provided via the model database (Mdb). You may call these kinds of scripts from the system shell using abaqus cae file_name.py. This command starts up a new CAE session and runs your script.
  5. You can run a script that accesses the CAE kernel without starting up a new CAE session using the alternative: abaqus cae noGUI=file_name.py.
  6. Some functionality is not available without a graphical CAE session, for example, getInputs, because it requires a GUI popup window.
  7. Instead, you can pass command-line args from the system shell, for example: abaqus cae noGUI=MyScript.py -- value1. You can use as many command line args as you want. Alternatively, put the arguments into a file and open/read the file from within the script.
  8. You will need to import the proper modules. For example, you should no longer need import __main__. If errors occur, the Python traceback usually tells you what is wrong.
  9. You can put the Abaqus execution commands into a batch script, if you like, so you can double-click it to run.
  10. Rather than execfile, you can use the functions/objects in other Python script(s) with the import statement. For example from File_A import function1, from File_B import function2, etc. These imported Python scripts are then usually referred to as modules.

These hints should help you get started, but remember it is just the tip of the iceberg, so to speak. For further execution options and details, see the Abaqus Analysis Users Manual > Introduction, Spatial Modeling, and Execution > Job Execution > Execution Procedures.

1Specifically, see the Abaqus Analysis User's Manual for instructions on how to call/execute Python scripts from the system shell, and see the Abaqus Scripting User's Manual for helpful examples and explanations for how Python is used with Abaqus. This should be read in tandem with the Abaqus Scripting Reference Manual, where full API details are available.

Upvotes: 4

Related Questions