Source code for ACCS_scripting

"""ACCS scripting module

This module allows to integrate ACCS into WB scripting.
It supports WB Project and WB Mechanical.

.. code-block:: python
   :linenos:

   import sys
   sys.path.insert(0,r'D:\cedric\CST_ANSYS\0_stable\ACT\scripting')
   if 'ACCS_scripting' in sys.modules:
      del sys.modules['ACCS_scripting']
   gls = globals()
   for g in [g for g in gls if 'ACCS_' in g]:
      del(globals()[g])
   import ACCS_scripting
   print(dir(ACCS_scripting))

   ACCS_proj = ACCS_scripting.Project()
   print(ACCS_proj.CheckMaterial())

"""


import sys as _sys

try:
   import clr as _clr
   import Ansys as _Ansys
   _clr.AddReference("Ansys.ACT.Core")
except:
   pass

try:
   import Extensions as _Extensions
except:
   pass

class _Meta:
   def __init__(self,API):
      self.ExtAPI = API
      self.ACCS_ext = self.ExtAPI.ExtensionManager.GetExtensionByName("ACCS")
      if self.ACCS_ext==None:
         raise RuntimeError('The ACCS extension does not seem to be loaded')
      self.ACCS_mod = self.ACCS_ext.GetModule()

   def _hideMessageBox(self,state):
      """Hides or shows the message boxes.
      
      :param state: The Message boxes will be hidden if True
      :type state: bool
      """

      if state!=True and state!=False:
         raise RuntimeError('The supplied argument must be a boolean.')
      self.ACCS_mod._IsInteractive = not state

   def _isMechanical(self):
      """determines if it is being run from mechanical.
      """

      return _Ansys.ACT.Core.ApplicationRepository.GetApplication("Project")==None

   def VersionStringDotted(self):
      """Returns the ACCS Version String with dots.
      """

      return self.ACCS_mod.GetACCSVersDot()

   def VersionString(self):
      """Returns the ACCS Version String without dots.
      """

      return self.ACCS_mod.GetACCSVers()

   def VersionStringDottedFull(self):
      """Returns the ACCS Version String with dots and hotfix.
      """

      return self.ACCS_mod.GetACCSVersDotFull()


[docs]class Project(_Meta): """ Project class Class to use to script ACCS from Workbench .. note:: It is important to create the instance after loading the project """ def __init__(self): try: _Extensions.LoadExtension(Id="90932E6A-9319-4952-B00B-3B2857BEA465", Format="Binary") except: try: _Extensions.LoadExtension(Id="90932E6A-9319-4952-B00B-3B2857BEA465", Format="Scripted") except: pass API = _Ansys.ACT.Core.ApplicationRepository.GetApplication("Project").GetExtensionApi(None) _Meta.__init__(self, API) if self._isMechanical(): raise RuntimeError('This can only be used within a Project script.')
[docs] def CheckMaterial(self): """Checks all materials in the project to see if they have not been imported from an earlier release. """ self._hideMessageBox(True) ret = self.ACCS_mod.CheckMaterial() self._hideMessageBox(False) return ret
[docs] def UpgradeMaterial(self): """Upgrades all materials that were imported from an earlier release. """ self._hideMessageBox(True) self.ACCS_mod.ACCS_Proj_Upgrade(None) self._hideMessageBox(False)
[docs] def HomogeneizeMaterial(self): """Adds homogeneized properties for all materials which were defined via the fibre/matrix formulation. """ self._hideMessageBox(True) self.ACCS_mod.ACCS_Proj_FM(None) self._hideMessageBox(False)
[docs]class Mechanical(_Meta): """ Mechanical class Class to use to script ACCS from Mechanical """ def __init__(self, API): _Meta.__init__(self,API) if not self._isMechanical(): raise RuntimeError('This can only be used within a Mechanical script.')
[docs] def AddACCS(self,analysis): """Adds the ACCS module to the input analysis. :param analysis: The analysis to which it should be added :type analysis: Ansys.ACT.Automation.Mechanical.Analysis """ if not isinstance(analysis,_Ansys.ACT.Automation.Mechanical.Analysis): raise RuntimeError('The supplied argument must be an analysis.') self._hideMessageBox(True) load = self.ACCS_mod.ACCS_Mech_AddLd(analysis) if load==None: load = [o for o in analysis.GetLoadObjects("ACCS") if o.Name=='ACCS_Ld'][0] self._hideMessageBox(False) return ACCSload(load)
[docs] def AddSupportRemover(self,analysis): """Adds the ACCS module to the input analysis. :param analysis: The analysis to which it should be added :type analysis: Ansys.ACT.Automation.Mechanical.Analysis """ if not isinstance(analysis,_Ansys.ACT.Automation.Mechanical.Analysis): raise RuntimeError('The supplied argument must be an analysis.') self._hideMessageBox(True) load = self.ACCS_mod.ACCS_Mech_AddSupRem(analysis) self._hideMessageBox(False) return ACCSsuprem(load)
[docs] def AddSurfaceExporter(self,analysis): """Adds the ACCS Surface Exporter module to the input analysis. :param analysis: The analysis to which it should be added :type analysis: Ansys.ACT.Automation.Mechanical.Analysis """ if not isinstance(analysis,_Ansys.ACT.Automation.Mechanical.Analysis): raise RuntimeError('The supplied argument must be an analysis.') self._hideMessageBox(True) res = self.ACCS_mod.ACCS_Mech_AddExpSurf(analysis) self._hideMessageBox(False) return ACCSsurexp(res)
[docs] def AddResultState(self,analysis): """Adds the ACCS Material State result to the input analysis. :param analysis: The analysis to which it should be added :type analysis: Ansys.ACT.Automation.Mechanical.Analysis """ if not isinstance(analysis,_Ansys.ACT.Automation.Mechanical.Analysis): raise RuntimeError('The supplied argument must be an analysis.') self._hideMessageBox(True) res = self.ACCS_mod.ACCS_Mech_AddResState(analysis) self._hideMessageBox(False) return res
[docs] def AddResultAlpha(self,analysis): """Adds the ACCS Degree of Cure/Crystallisation result to the input analysis. :param analysis: The analysis to which it should be added :type analysis: Ansys.ACT.Automation.Mechanical.Analysis """ if not isinstance(analysis,_Ansys.ACT.Automation.Mechanical.Analysis): raise RuntimeError('The supplied argument must be an analysis.') self._hideMessageBox(True) res = self.ACCS_mod.ACCS_Mech_AddResAlpha(analysis) self._hideMessageBox(False) return res
[docs] def AddResultTg(self,analysis): """Adds the ACCS Glass transition temperature/reference result to the input analysis. :param analysis: The analysis to which it should be added :type analysis: Ansys.ACT.Automation.Mechanical.Analysis """ if not isinstance(analysis,_Ansys.ACT.Automation.Mechanical.Analysis): raise RuntimeError('The supplied argument must be an analysis.') self._hideMessageBox(True) res = self.ACCS_mod.ACCS_Mech_AddResTg(analysis) self._hideMessageBox(False) return res
[docs] def AddResultHeat(self,analysis): """Adds the ACCS Generated Heat result to the input analysis. :param analysis: The analysis to which it should be added :type analysis: Ansys.ACT.Automation.Mechanical.Analysis """ if not isinstance(analysis,_Ansys.ACT.Automation.Mechanical.Analysis): raise RuntimeError('The supplied argument must be an analysis.') self._hideMessageBox(True) res = self.ACCS_mod.ACCS_Mech_AddResQdot(analysis) self._hideMessageBox(False) return res
[docs] def AddResultEpsShXX(self,analysis): """Adds the ACCS Cure Shrinkage XX result to the input analysis. :param analysis: The analysis to which it should be added :type analysis: Ansys.ACT.Automation.Mechanical.Analysis """ if not isinstance(analysis,_Ansys.ACT.Automation.Mechanical.Analysis): raise RuntimeError('The supplied argument must be an analysis.') self._hideMessageBox(True) res = self.ACCS_mod.ACCS_Mech_AddResExtraEpsShXX(analysis) self._hideMessageBox(False) return res
[docs] def AddResultEpsShYY(self,analysis): """Adds the ACCS Cure Shrinkage YY result to the input analysis. :param analysis: The analysis to which it should be added :type analysis: Ansys.ACT.Automation.Mechanical.Analysis """ if not isinstance(analysis,_Ansys.ACT.Automation.Mechanical.Analysis): raise RuntimeError('The supplied argument must be an analysis.') self._hideMessageBox(True) res = self.ACCS_mod.ACCS_Mech_AddResExtraEpsShYY(analysis) self._hideMessageBox(False) return res
[docs] def AddResultEpsShZZ(self,analysis): """Adds the ACCS Cure Shrinkage ZZ result to the input analysis. :param analysis: The analysis to which it should be added :type analysis: Ansys.ACT.Automation.Mechanical.Analysis """ if not isinstance(analysis,_Ansys.ACT.Automation.Mechanical.Analysis): raise RuntimeError('The supplied argument must be an analysis.') self._hideMessageBox(True) res = self.ACCS_mod.ACCS_Mech_AddResExtraEpsShZZ(analysis) self._hideMessageBox(False) return res
[docs] def AddResultEpsElXX(self,analysis): """Adds the elastic strain XX result to the input analysis. :param analysis: The analysis to which it should be added :type analysis: Ansys.ACT.Automation.Mechanical.Analysis """ if not isinstance(analysis,_Ansys.ACT.Automation.Mechanical.Analysis): raise RuntimeError('The supplied argument must be an analysis.') self._hideMessageBox(True) res = self.ACCS_mod.ACCS_Mech_AddResExtraEpsElXX(analysis) self._hideMessageBox(False) return res
[docs] def AddResultEpsElYY(self,analysis): """Adds the elastic strain YY result to the input analysis. :param analysis: The analysis to which it should be added :type analysis: Ansys.ACT.Automation.Mechanical.Analysis """ if not isinstance(analysis,_Ansys.ACT.Automation.Mechanical.Analysis): raise RuntimeError('The supplied argument must be an analysis.') self._hideMessageBox(True) res = self.ACCS_mod.ACCS_Mech_AddResExtraEpsElYY(analysis) self._hideMessageBox(False) return res
[docs] def AddResultEpsElZZ(self,analysis): """Adds the elastic strain ZZ result to the input analysis. :param analysis: The analysis to which it should be added :type analysis: Ansys.ACT.Automation.Mechanical.Analysis """ if not isinstance(analysis,_Ansys.ACT.Automation.Mechanical.Analysis): raise RuntimeError('The supplied argument must be an analysis.') self._hideMessageBox(True) res = self.ACCS_mod.ACCS_Mech_AddResExtraEpsElZZ(analysis) self._hideMessageBox(False) return res
[docs] def AddResultEpsElXY(self,analysis): """Adds the elastic strain XY result to the input analysis. :param analysis: The analysis to which it should be added :type analysis: Ansys.ACT.Automation.Mechanical.Analysis """ if not isinstance(analysis,_Ansys.ACT.Automation.Mechanical.Analysis): raise RuntimeError('The supplied argument must be an analysis.') self._hideMessageBox(True) res = self.ACCS_mod.ACCS_Mech_AddResExtraEpsElXY(analysis) self._hideMessageBox(False) return res
[docs] def AddResultEpsElYZ(self,analysis): """Adds the elastic strain YZ result to the input analysis. :param analysis: The analysis to which it should be added :type analysis: Ansys.ACT.Automation.Mechanical.Analysis """ if not isinstance(analysis,_Ansys.ACT.Automation.Mechanical.Analysis): raise RuntimeError('The supplied argument must be an analysis.') self._hideMessageBox(True) res = self.ACCS_mod.ACCS_Mech_AddResExtraEpsElYZ(analysis) self._hideMessageBox(False) return res
[docs] def AddResultEpsElXZ(self,analysis): """Adds the elastic strain XZ result to the input analysis. :param analysis: The analysis to which it should be added :type analysis: Ansys.ACT.Automation.Mechanical.Analysis """ if not isinstance(analysis,_Ansys.ACT.Automation.Mechanical.Analysis): raise RuntimeError('The supplied argument must be an analysis.') self._hideMessageBox(True) res = self.ACCS_mod.ACCS_Mech_AddResExtraEpsElXZ(analysis) self._hideMessageBox(False) return res
[docs] def CopyAnalysisSettings(self,AnalysisFrom,AnalysisTo): """Copies analysis settings between two simulations. :param AnalysisFrom: The source analysis :type AnalysisFrom: Ansys.ACT.Automation.Mechanical.Analysis :param AnalysisTo: The destination analysis :type AnalysisTo: Ansys.ACT.Automation.Mechanical. """ if not isinstance(AnalysisFrom,_Ansys.ACT.Automation.Mechanical.Analysis) or \ not isinstance(AnalysisTo,_Ansys.ACT.Automation.Mechanical.Analysis): raise RuntimeError('The supplied arguments must be analyses.') self._hideMessageBox(True) self.ACCS_mod.CopyAS(AnalysisFrom,AnalysisTo) self._hideMessageBox(False)
[docs]class ACCSload: """ ACCS load class Class to use to script the ACCS load from Mechanical """ def __init__(self, load): self.load = load
[docs] def setAnalysisType(self,t): """Sets the ACCS Analysis Type. :param t: The analysis type either 'Full' or 'Fast' :type t: str """ if self.load.Analysis.PhysicsType=="Thermal": raise RuntimeError('The ACCS analysis type can only be set for a Mechanical analysis.') if not t in self.load.Properties['ACCS_Ld_SelectType'].Options: raise RuntimeError('The analysis type must be among these valid options: '+str(self.load.Properties['ACCS_Ld_SelectType'].Options)) self.load.Properties['ACCS_Ld_SelectType'].Value = t self.load.NotifyChange()
[docs] def setMRCC(self,steps): """Sets the ACCS Cure cycle for the mechanical FAST approach. :param MRCC: The cure cycle shall be defined with a list of steps. A step can be defined as a Heating/Cooling step with ['Heating Rate', X, Y] defines a Heating/Cooling step at a rate of X C/min until reaching Y C or ['Fixed temperature', Z]: defines a Fixed temperature step with a duration of Z minutes. :type MRCC: list[step] """ if self.load.Analysis.PhysicsType=="Thermal": raise RuntimeError('The ACCS Cure Cycle can only be defined for a Mechanical analysis.') SelectType = self.load.Properties['ACCS_Ld_SelectType'] if SelectType.Value != 'Fast': raise RuntimeError('The ACCS Cure Cycle can only be defined for a ACCS FAST approach.') Tprof_type = SelectType.Properties.GetByName("ACCS_Ld_fast_Tprof_type") Tprof_type.Value = "MRCC" self.load.NotifyChange() MRCC = Tprof_type.Properties.GetByName("ACCS_Ld_fast_Tprof_MRCC") MRCC_Type = MRCC.Properties.GetByName("ACCS_Ld_fast_Tprof_MRCC_Type") HeatingRate = MRCC_Type.Properties.GetByName("ACCS_Ld_fast_Tprof_MRCC_HeatingRate") Temperature = MRCC_Type.Properties.GetByName("ACCS_Ld_fast_Tprof_MRCC_Temperature") Time = MRCC_Type.Properties.GetByName("ACCS_Ld_fast_Tprof_MRCC_Time") while 0<MRCC.RowCount: MRCC.DeleteRow(0) for s in steps: MRCC.AddRow() if s[0].lower()=='heating rate': MRCC_Type.Value = "Heating Rate" HeatingRate.Value = s[1] Temperature.Value = s[2] elif s[0].lower()=='fixed temperature': MRCC_Type.Value = "Fixed temperature" Time.Value = s[1] else: raise RuntimeError('The step type must be among these valid options: '+str(MRCC_Type.Options)) Time.Validate() MRCC.SaveActiveRow() MRCC.Validate()
[docs] def setTvst(self,Tprof): """Sets the ACCS Cure cycle for the mechanical FAST approach. :param Tprof: The cure cycle shall be defined with a list of points. [10, 120] defines a point at 10 seconds and 120 C :type Tprof: list[point] """ if self.load.Analysis.PhysicsType=="Thermal": raise RuntimeError('The ACCS Cure Cycle can only be defined for a Mechanical analysis.') SelectType = self.load.Properties['ACCS_Ld_SelectType'] if SelectType.Value != 'Fast': raise RuntimeError('The ACCS Cure Cycle can only be defined for a ACCS FAST approach.') Tprof_type = SelectType.Properties.GetByName("ACCS_Ld_fast_Tprof_type") Tprof_type.Value = "Temperature-time" self.load.NotifyChange() Tvst = Tprof_type.Properties.GetByName("ACCS_Ld_fast_Tprof_Tvst") Time = Tvst.Properties.GetByName("ACCS_Ld_fast_Tprof_Tvst_Time") Temperature = Tvst.Properties.GetByName("ACCS_Ld_fast_Tprof_Tvst_Temperature") while 0<Tvst.RowCount: Tvst.DeleteRow(0) for pt in Tprof: Tvst.AddRow() Time.Value = pt[0] Temperature.Value = pt[1] Tvst.SaveActiveRow() Tvst.Validate()
[docs] def setViscoElasticity(self,v): """Activates or deactivate the viscoelasticity. :param v: The viscoelasticity will be activated if True :type v: bool .. note:: The corresponding properties do need to have been defined in Engineering Data. """ if self.load.Analysis.PhysicsType=="Thermal": raise RuntimeError('The ACCS analysis type can only be set for a Mechanical analysis.') if not v in self.load.Properties['ACCS_Ld_SelectType/ACCS_Ld_full_visco'].Options: raise RuntimeError('The analysis type must be among these valid options: '+str(self.load.Properties['ACCS_Ld_SelectType'].Options)) self.load.Properties['ACCS_Ld_SelectType/ACCS_Ld_full_visco'].Value = v self.load.NotifyChange()
[docs]class ACCSsuprem: """ ACCS support remover class Class to use to script the ACCS support remover from Mechanical """ def __init__(self, load): self.load = load
[docs] def setStep(self,step): """Defines when will the support remover will be active. :param step: The step number :type step: scalar """ if not step in self.load.Properties['ACCS_SupRem_Step'].Options: raise RuntimeError('The step number must be among these valid options: '+str(self.load.Properties['ACCS_SupRem_Step'].Options)) self.load.Properties['ACCS_SupRem_Step'].Value = step self.load.NotifyChange()
[docs] def setSurfacesByGeoSelection(self,selection): """Sets the surfaces where it applies via Geometry Selection. :param selection: The selected surfaces :type selection: SelectionInfo """ self.load.Properties['ACCS_SupRem_Geometry/DefineBy'].Value = 'ID_GeometrySelection' self.load.NotifyChange() self.load.Properties['ACCS_SupRem_Geometry/DefineBy/Geo'].Value = selection self.load.NotifyChange()
[docs] def setSurfacesByNamedSelection(self,selection): """Sets the surfaces where it applies via Named Selection. :param selection: Instance or ID reference to the named selection containing the surfaces :type selection: NamedSelection or NamedSelection ID """ if isinstance(selection, _Ansys.ACT.Automation.Mechanical.NamedSelection): selection = selection.Id self.load.Properties['ACCS_SupRem_Geometry/DefineBy'].Value = 'ID_NamedSelection' self.load.NotifyChange() self.load.Properties['ACCS_SupRem_Geometry/DefineBy/NamedSelection'].Value = selection self.load.NotifyChange()
[docs]class ACCSsurexp: """ ACCS support remover class Class to use to script the ACCS support remover from Mechanical """ def __init__(self, result): self.result = result
[docs] def setExportPath(self,filepath): """Sets the path to the exported path. :param filepath: The full path or relative path defining where the file will be saved :type filepath: string """ self.result.Properties['ACCS_ExpSurf_FilePath'].Value = filepath self.result.NotifyChange()
[docs] def setSurfacesByGeoSelection(self,selection): """Sets the surfaces where it applies via Geometry Selection. :param selection: The selected surfaces :type selection: SelectionInfo """ self.result.Properties['ACCS_ExpSurf_Geometry/DefineBy'].Value = 'ID_GeometrySelection' self.result.NotifyChange() self.result.Properties['ACCS_ExpSurf_Geometry/DefineBy/Geo'].Value = selection self.result.NotifyChange()
[docs] def setSurfacesByNamedSelection(self,selection): """Sets the surfaces where it applies via Named Selection. :param selection: Instance or ID reference to the named selection containing the surfaces :type selection: NamedSelection or NamedSelection ID """ if isinstance(selection, _Ansys.ACT.Automation.Mechanical.NamedSelection): selection = selection.Id self.result.Properties['ACCS_ExpSurf_Geometry/DefineBy'].Value = 'ID_NamedSelection' self.result.NotifyChange() self.result.Properties['ACCS_ExpSurf_Geometry/DefineBy/NamedSelection'].Value = selection self.result.NotifyChange()