General Mechanical

General Mechanical

Topics relate to Mechanical Enterprise, Motion, Additive Print and more

Executing a python script in ACP out of Workbench

    • julius.langenhorst
      Hello,nI wrote a script in ACP to extract shear angles at specific locations. This works fine as long as I run it directly in ACP.nI wrote another script in Workbench to update the next Design Point, Mechanical and ACP, then open ACP and run the ACP-script (= automate my parameter study). Now I'm getting an error basically saying that Ironpython does not support numpy. nI already know that it is not possible to get Ironpython working with numpy but the thing is that the command model.mesh_query creates a numpy.ndarray.nnTo avoid this problem, I tried different approaches:nRunScript(FilePath=E:/~/ This ends in the numpy no supported-errornnimport subprocessnrun_python = 'python -batch Script'nsubprocess.Popen(run_python) This does nothing but also not spitting out an error.nnfrom System.Diagnostics import Processnp = Process()np.StartInfo.UseShellExecute = Falsenp.StartInfo.RedirectStandardOutput = Falsenp.StartInfo.RedirectStandardError = Falsenp.StartInfo.CreateNoWindow = Truenp.StartInfo.FileName = 'E:/~/'np.Start()np.WaitForExit() Doesn't work since is not a executable file.nnWhat I would like to know now is how to get the script running. Is there a way to start the python engine where I can execute the script in (just like matlab.engine)? Or is it possible to go the other way around: starting in ACP and controlling workbench?nThank you very much.n
    • cagdasakalin
      @waldmeistersweinnI have a related issue with script reading in ACP. As far as I understood, you are more ahead of me in terms of reading scripts in ACP.n

      Dear all,According to the "Basic Scripting" procedure it is obvious that in ACP Pre module we can read copy commands appearing in "History View" and paste them in a notepad and save it as *.py. am trying to apply step by step what is written in the precedure as follows. would appreciate it if you point out the part/step that I miss when I try to read from *.py file and explain why I am getting this "1 Error" window.

      Can I kindly ask you to read my discussion for which I posted the link above, and give your suggestion regarding how to do it?, your answer and help is highly appreciated.n
    • Gary Stofan
      Ansys Employee
      nKnowledge Resources: Solutionsn#2052288nHow can I use Numpy or SciPy with ACT ?.Product Family: ScriptingnProduct: ANSYS Customization SuitenVersion: 18.2nArea: ACTnSubArea: N/AnLast Updated: Nov 29 2017nnAnswer:nn​Numpy and SciPy are numerical libraries used with Python. ACT is based on IronPython and those libraries are not supported.nYou can use instead of Numpy or SciPy. is supported for IronPython and available for ACT.​ Libraries are in ANSYS Installation directory : ​C:\Program Files\ANSYS Inc\v182\Addins\ACT\bin\Win64\MathNet.Numerics.dllnn​Here are some examplesnn----------------------------------------------n​​import clrnimport Systemnimport osnclr.AddReferenceToFileAndPath(C:\\Program Files\\ANSYS Inc\\v182\\Addins\\ACT\\bin\\Win64\\MathNet.Numerics.dll)nn# Example 1nimport MathNetnfrom MathNet.Numerics.LinearAlgebra import *nV=Vector[System.Double].BuildnM=Matrix[System.Double].Buildnnm = M.Random(3,4)nv = V.Random(3)nnr=v*mnprint rnn# Example 2nimport MathNet.Numerics.LinearAlgebra as lannfrom System importas sys_arrayndef array(*x): return sys_array[float](x) #float is equivalent to .Net doublennA = la.Double.Matrix.Build.DenseOfRows(narray(3, 2,-1),narray(2,-2,4),narray(-1,.5,-1)n)nnb = la.Double.Vector.Build.DenseOf(array(1, -2, 0))nx = A.Solve(b)nnprint xnn# Example 3nA1 = la.Double.Matrix.Build.DenseOfRows(narray(3.0, 4.0, -1.0, 0.0),narray(4.0, 5.0, 0.0, -1.0),narray(5.0, 6.0, 0.0, 0.0),narray(6.0, 7.0, 0.0, 0.0)n)nb1 = la.Double.Vector.Build.DenseOf(array(0, 0, 20, 0))nx1 = A1.Solve(b1)nnprint x1nn
Viewing 2 reply threads
  • The topic ‘Executing a python script in ACP out of Workbench’ is closed to new replies.