Closed pmaroneh closed 1 year ago
@pmaroneh
materials.py
comes from the installation at vNNN/Addins/ACT/libraries/Mechanical
. You can import them if you first run:
import sys
sys.path.append('/path/to/vNNN/Addins/ACT/libraries/Mechanical')
this location has these files:
These names are quite general, and I feel a little uncomfortable with the idea of adding this path by default. This will reserve and overwrite the statements import graphics
import ansys
, etc, when the user uses pymechanical. @akaszynski thoughts?
As another workaround I currently do this: material_file = material_file.replace("\", "\\") script = 'DS.Tree.Projects.Item(1).LoadEngrDataLibraryFromFile("' + material_file + '");' ExtAPI.Application.ScriptByName('jscript').ExecuteCommand(script)
Hi @koubaa , thanks for your comments on this. I think the first solution is OK as long as we explain this in the doc somewhere and show some examples that use this. I don't like the second solution much as we've been told to tell our users to not use jscript and that its use is not supported (at least with standard support in standard Mechanical). So if I have to vote I think the first proposal is good.
Method 1 works fine. I had an issue with Method 2:
@pmaroneh github comments apparently don't handle backslashes properly. Here it is correctly:
material_file = get_material_file().replace("\\", "\\\\")
@paroneh I also don't like jscript, but we can hide this behind a python API inside of pymechanical that we can change to the real API once its supported by the Mechanical team (planned for 232). I still don't like the idea of adding a bunch of generic named libraries to the user's environment by default.
@pmaroneh a function to import a material library is now available, try this:
from ansys.mechanical.core.embedding import shims
shims.import_materials(app, material_file)
The shims
module is a place where we put functions that require jscript in current releases but will have direct python apis in future releases. This protects scripts from directly invoking jscript, which we want to avoid.
I'll keep this issue open while we debate what to do about vNNN/Addins/ACT/libraries/Mechanical
This is great news @koubaa !
@RemishR please open a separate issue for this as this is not related to the issue mentioned in the title, and also avoid posting the same issue several times. Thank you
π Before submitting the issue
π Description of the bug
In the GUI one can use:
import materials
but in embedded mode the module is not available:π Steps to reproduce
See above.
π» Which operating system are you using?
Windows
π Which Python version are you using?
3.7
π¦ Installed packages