We have an exciting announcement about badges coming in May 2025. Until then, we will temporarily stop issuing new badges for course completions and certifications. However, all completions will be recorded and fulfilled after May 2025.
Ansys Products

Ansys Products

Discuss installation & licensing of our Ansys Teaching and Research products.

Scripting in Mechanical – Accessing ‘Model’

    • Matthew Little
      Subscriber

      When writing a script in Mechanical, the entire Ansys Python class is already in there, and to access the Model, you just type 'Model'.  I'm working on a project where I import another script into Mechanical, but because it's imported, it doesn't have the Ansys namespace.

      I can't seem to find what I need to import from Ansys to access Model.  Seems like it should be Ansys.ACT.Automation.Mechanical.Model, but that doesn't give any options to access anything within the model (e.g., Model.Analyses).

      Any clue as to where all of this info is hidden in the classs?

    • Matthew Little
      Subscriber

      After a few more searches, I found a solution.  In the imported module, you must 'initialize' the Ansys objects you want to use (e.g., ExtAPI, Ansys).  Create a function that takes whatever objects you want and set them to global variables in the imported module.

      In the main Ansys script, after you load your module, you call the initialization function to pass whatever Ansys namespace functions (ExtAPI, Ansys, etc.) to you module.

      This sort of seems like a workaround, and i feel like there should be a direct way to import the needed objects.

    • mjmiddle
      Ansys Employee

      Sending the ExtAPI and Ansys objects to your model in an initialization function is the best way.

Viewing 2 reply threads
  • The topic ‘Scripting in Mechanical – Accessing ‘Model’’ is closed to new replies.