1

I am trying to create a .bat file which can check if abaqus session is open and if it is open then open its run script prompt. For that i am using following code:

@echo off
if exist c:\SIMULIA\Abaqus\6.14-3\code\bin\abq6143.exe goto openscript
else exit
:openscript
echo "file exist"   
abaqus cae noGUi=D:\Saurabh\example\macro1.py
pause

A command window comes with msg "file exist" then the following error comes

Abaqus Licence Manager checked out the following license(s): "cae" release 6.14 from Flexnet server myshec184706d <13 out of 130 licenses remain available>

and the command window suddenly disappears. "macro1" is actually recorded using macro manager and when I run this from file>runscript it works fine.
what I actually want is to prompt "runscript" from this .bat file in already open abaqus application. This .bat file is required for tracking purpose i.e. how many times the scripts are being used. can anyone help me with this problem?

thanks in advance!

  • What exactly is the problem? – Andre Kampling Jun 28 '17 at 09:34
  • @Andre thanks for replying. when i run the bat file with "abaqus cae noGUI=D:\Saurabh\exmple\macro1.py" cmd window comes with msg "file exist" for like 2 seconds and then some message starts printing and the cmd window vanishes immediately. with that a abaqus.rpy file gets created. i want this macro1 to run in already open session of abaqus. – sourabh goyal Jun 28 '17 at 09:45
  • Having an external process drive an already open GUI would be highly non trivial. You would need to do something like write java code to simulate mouse and keyboard activity. In any case you should edit the question to clarify more clearly what you are actually trying to do. – agentp Jun 28 '17 at 14:31
  • The `if` condition with `else` branch is definitely written wrong and results in an error message if the executable does not exist. Use instead of those two lines `if not exist C:\SIMULIA\Abaqus\6.14-3\code\bin\abq6143.exe exit /B` to exit batch file execution when the file does not exist. Otherwise the batch execution is continued on next line. Open a command prompt window and run `if /?` for help on command __IF__ and read answer on [IF ELSE syntax error within batch file?](https://stackoverflow.com/a/25471786/3074564) – Mofi Jun 30 '17 at 05:55

1 Answers1

0

As far as I know, it is not possible to update a model database that is already open for read/write. However, if you would like to simply read or copy data from an open session, you can try to access the data using an auxiliary Mdb. For example:

try:
    openMdb(filename)
except AbaqusException, Msg:
    sys.__stdout__.write("File may be in use by another CAE session.\n")
    sys.__stdout__.write("Error Msg: {0}\n".format(Msg))
    sys.__stdout__.write("Now opening file in a temporary auxiliary mdb.\n")
    mdb = Mdb()
    mdb.openAuxMdb(filename)
# The auxMdb object has a few methods documented in the scripting user's manual
# Otherwise, copy a model from the auxMdb and then you'll have full access.
# Don't forget to save your work, if you made changes to the Mdb. Note that saving
# will result in a new on-disk cae file in the current work directory.

Once the cae file is open and you have access to the Mdb, or a copy of it as I've shown above, then you can 1) use the macro function in your Python script directly, or 2) call your macro script using:

import allAbaqusMacros
allAbaqusMacros.Macro1()
Matt P
  • 2,287
  • 1
  • 11
  • 26
  • Thanks Matt P. I actually want to make a .bat or .exe file, using which I can launch runscript prompt directly in abaqus cae. This file is required for tracking purpose i.e. how many times scripts are being run in abaqus. – sourabh goyal Jun 29 '17 at 03:54
  • @sourabhgoyal You can call the cae/macro script from the bat file if you like. But the point is that if the Mdb is already open in another session then you'll be locked out, and you may want to handle it as I've shown you in this answer. – Matt P Jun 29 '17 at 15:16
  • @sourabhgoyal I've added an update that shows how you can run a macro from a regular CAE/Python script, once you have the file and an Mdb open. – Matt P Jun 29 '17 at 15:20