3D Design

3D Design

How to execute SpaceClaim script within ACT?

    • BJMEL

      Hello everyone

      I'm having difficulties implementing my previously developed SpaceClaim script, into an ACT scripting environment. I want to roll out this script solution out to my colleagues, as this design/analysis is quite repetitive and I thought an ACT (APP) would be quite suitable for the task.

      The SpaceClaim script works perfectly within the SpaceClaim scripting environment. I've modified the IronPython SpaceClaim script slightly to work better with ACT by:

      1. Splitting it into two .py files, the script and the definition (def) I've defined
      2. Modified the input geometry variables to extract the values from the user (see example below)




      So far I've achieved the following in ACT:

      1. Defining the steps
      2. Setting up the workbench interface (separate load cases)
      3. Opening SpaceClaim
      4. Defining the geometry input
      5. Extracting the geometrical values from 4., to be used further in the IronPython code.

      After that the ACT program crashes on a line where I define:

       variable = Direction.Create(1,0,0)


      variable = List[IComponent]()

      My conclusion is therefore that: ACT does not recognize the internal SpaceClaim IronPython functions as default.

      I've tried to define the following default definition that "imports" the default SpaceClaim IronPython definitions. ACT can call and run the definition , but it doesn't work.....

      def script_import():


        This function imports SpaceClaim scripting for ACT


        import clr


        import Ansys


        import SpaceClaim


        from SpaceClaim.Api.V19 import Geometry

        from SpaceClaim.Api.V19 import Modeler


      I've searched for days for some kind of solution online and in the ANSYS guides, but I cannot find my way around this problem. Do any of you have any suggestions?

      Note: I cannot share the source code as it owned by the company I work for, but I can share some of if it would help

    • rmeena
      Ansys Employee
      The SpaceClaim scripting function can not be used in ACT app without importing the spaceclaim libraries.

      I would recommend you to first of all use ACT console in SpaceClaim for developing/Testing the code. Please refer to the help manual to check the parent libraries to be imported for a function (C:\Program Files\ANSYS Inc\v211\scdm\SpaceClaim.Api.V19).

      For example, to use Direction.Create(0,0,1) you can simply search for this function in the help manual to find that you would need SpaceClaim.Api.V19.Geometry to be imported.
      SpaceClaim.Api.V19.Geometry as geometry

      geometry.Direction.Create(0,0,1) #Create a direction object

      Similarly, List is nothing but a .Net array of type System.Collections.Generic.List.
      Hope it helps.

      Thanks Rajesh
    • BJMEL
      Good day Rajesh
      After some trial and error, I had stumbled onto this as well, that if I run the code in the ACT console in SpaceClaim I get access to the SC library.
      The only problem is that for some reason only V17 of the script library is available in ACT/SpaceClaim, so I need go through my original code and modify it to work with V17.
      Do you know why that is? I cannot find anything in the documentation about it.
    • tricha122
      BJMEL, did you ever find a solution for API's beyond V17?

      i am having similar issues, but related to extensions:
      for instance if i have a DesignEdge named "edge" and i want to evaluate its midpoint, i would do so in SC as follows:
      px = edge.EvalMid().Point.X

      however if i have this in a separate script, and run it using execfile, i will get an error that 'DesignEdgeGeneral' has no attribute 'EvalMid'

      If i try to bring in the extensions, it still fails:

      import SpaceClaim.Api.V20.Scripting.Extensions
      px = edge.EvalMid().Point.X

      and if i try to name the extensions, doesnt work:
      import SpaceClaim.Api.V20.Scripting.Extensions as extension
      px = edge.extension.EvalMid().Point.X

      I wonder if youve come across a better solution?
Viewing 3 reply threads
  • You must be logged in to reply to this topic.