3D Design

3D Design

Topics related to Ansys Discovery and Ansys SpaceClaim.

How to run a Spaceclaim script from an external IDE like vscode?

    • FirasBejar
      Subscriber

      Hello,

      I have a file "file.py" that contains simple commands that I want to execute from vscode without opening spaceclaim itself.

      How can I achieve this?

      Also, I noticed that commands like numpy are not define within spaceclaim, is there a way to import them?

      Thank you,

    • Aniket
      Forum Moderator
    • mjmiddle
      Ansys Employee

      Most Ansys products use IronPython for scripting. Mechanical has a beta option to use CPython in the scripting console. You can use other python variants externally. Given the title of your post, you can launch any python variant, or for that matter any script interpreter (Tcl, Perl, sh, bat, etc...), and do what you can there then have that script launch SpaceClaim:

      "C:\Program Files\ANSYS Inc\v232\scdm\SpaceClaim.exe" /Welcome=False /Splash=False /RunScript="D:\my_path\my_script.py" /ExitAfterScript=True /Headless=True

      The my_script.py will have to be an IronPython script through. Your external script interpreter could even write this script.

      Once inside SpaceClaim or Mechanical, they could also take this external approach to write a data file, then run a system command (python exec()) to launch any of script interpreter and read the data file. This is the approach taken in the link of Aniket's post. It uses an ACT extension, but you could also launch an external program in Mechanical using a "Python Code" or "Python Result" or even an APDL command snippet (/SYS command). 

    • mjmiddle
      Ansys Employee

      Since IronPython use .Net Framework it does not support a lot of CPython modules. An alternative is to use MathNet library (http://numerics.mathdotnet.com/). You can download the library yourself, but Ansys has distributed it inside the Ansys installation. Here is how you can access it with IronPython:

      import os
      import clr
      clr.AddReference("Ans.Utilities")
      version = Ansys.Utilities.ApplicationConfiguration.DefaultConfiguration.VersionInfo.VersionString
      sys.path.append(os.environ["AWP_ROOT" + version] + "\\Addins\\ACT\\bin\\Win64")
      clr.AddReferenceToFile("MathNet.Numerics.dll")
      import MathNet.Numerics

Viewing 3 reply threads
  • The topic ‘How to run a Spaceclaim script from an external IDE like vscode?’ is closed to new replies.