3D Design

3D Design

SpaceClaim – Scripting – add some Modules

    • frussold
      Subscriber

      Hi @ all.


      I´m new in SpaceClaim but i saw, its support scripting.
      I tryed some scripts and it works well.


      But I´d like to include some python modules like openpyxl, numpy. After I copyed it to ...ANSYS Studentv192scdmLibraryIronPythonLib


      I got a strange error like


      German: Das Objekt des Typs "Microsoft.Scripting.Runtime.Uninitialized" kann nicht in Typ "System.Exception" umgewandelt werden.
      English:


      Unable to cast object of type 'Microsoft.Scripting.Runtime.Uninitialized'
      to type 'System.Exception'

      Has anyone some ideas?


       


      Thanks


      Florian

    • Naresh Patre
      Ansys Employee

      Hello frussold,


      External python modules cannot be currently added to the scripting database.


      Regards,


      Naresh Patre

    • Keyur Kanade
      Ansys Employee

      Hi, 


      As you are new to SpaceClaim, request you to explore various tools in SpaceClaim like creating groups for parameters etc. Correct usage of different tools can avoid need of scripting. You can find many videos on SpaceClaim at following link


      http://www.spaceclaim.com/en/default.aspx


      Regards,


      Keyur


       

    • frussold
      Subscriber

      I´ve googled but i can´t find a way to load parameters via excel. It just works with groups and groups can´t be import in the script file.


      Or someone has an idea. .csv is not a solution for me.


       


      Thanks,


      Florian

    • frussold
      Subscriber

      I´ve found a solution...it´s not perfect but i can work with it.


      import clr
      import sys

      clr.AddReference("Microsoft.Office.Interop.Excel")
      import Microsoft.Office.Interop.Excel as Excel
      from System.Runtime.InteropServices import Marshal


      class DoImport:
      def __init__(self):
      self.excel = Excel.ApplicationClass()
      self.workbook,self.worksheet = ""


      def open(self):
      self.excel.Visible = True

               self.FileName = self.excel.GetOpenFilename(
      FileFilter = "Excel Files,*.xlsx",
      FilterIndex = 1,
      Title = "Open Import File",
      MultiSelect = False)

      if self.FileName != False:
      self.workbook = self.excel.Workbooks.Open(self.FileName)
      self.excel.Visible = False
      else:
                  self.excel.DisplayAlerts = False
                  Marshal.ReleaseComObject(self.excel)
      MessageBox.Show("Script abort - please restart")
      sys.exit()

      def get_xlsx_data(self):
      a = []
      for i in range(self.workbook.Worksheets.Count):
      i = i + 1
      a.append(self.workbook.Worksheets.Name)
      if a == "ScriptData":
      self.worksheet = self.workbook.Worksheets

      data = {}

      for row in range(self.worksheet.UsedRange.Rows.Count):
      datalist = []
      for columns in range(self.worksheet.UsedRange.Columns.Count):
      datalist.append(self.worksheet.Cells[row + 1, columns + 1].Text)
      f = self.worksheet.Cells[row + 1, 1].Value2
      data[f] = datalist

      self.workbook.Close()
      self.excel.Quit()
      Marshal.ReleaseComObject(self.workbook)
      Marshal.ReleaseComObject(self.worksheet)
      Marshal.ReleaseComObject(self.excel)

      return data

      if __name__ == "__main__":
      x = DoImport()
      x.open()
      data = x.get_xlsx_data()
      print data

       


       

    • frussold
      Subscriber

      copy the *.py file into ..scdmLibraryIronPythonLib


      in SpaceClaim you can do this


      import import_xlsx

      load = import_xlsx.DoImport()
      load.open()
      import_data = load.get_xlsx_data()

    • frussold
      Subscriber

      please add...i found some errors, sry


      clr.AddReference("System.Windows.Forms")
      from System.Windows.Forms import MessageBox


    • prabhukumar
      Subscriber

      Hi all,


       


      I am trying to automate a process in spaceclaim. My goal is to import an STL file, extrude it and save it as STEP file. I could record the script in the spaceclaim software and it works perfectly fine. I would like to run the script directly from the command terminal without manually opening the software. Any help would be appreciated. Thank you very much.


       


      Regards,
      Prabhu. 

    • Aniket
      Ansys Employee
Viewing 8 reply threads
  • You must be logged in to reply to this topic.