Discovery Import

Discovery Import

Scripting and using csv data

    • thilliard
      Subscriber

      Ok so what I am trying to get is all the P values (jigz.txt file) change for every job and I pull the values from an excel worksheet now I need to pass those into my script. How is this done? trying not to have to hard code them each time  Thanks 

      🛈 This post originally contained file attachments which have been removed in compliance with the updated Ansys Learning Forum Terms & Conditions
    • Naresh Patre
      Ansys Employee

      Hello frogdude01

      You can read the text file and store all the data from the text file for using it in your script. There is a built-in example showing how to read a csv file in the snippets section which you can refer. See below snapshot. This snippet can be accessed in Insert Snippet - Reading from Files - Reading From a CSV File. You can use similar logic to read txt file and use the data from the txt file in your script.

       

    • thilliard
      Subscriber

      I tried that I don't know how to pull the information so that in my script P1 will equal 7.125 that is in the text file. I'm a total newbie at this stuff  

    • Naresh Patre
      Ansys Employee

      Hello frogdude01

      You will have to make use of basic python functionalities like split, dictionary and so on. Please refer below sample code:

      f = open("E:\support\forum\JIGZ.txt", "r")

      my_dict = {}
      for x in f:
          temp = x.split("=,")  # split each line by =,
          my_dict[temp[0]] = temp[1]

      # Sketch Line UPPER S DIA 'P5')
      start = Point2D.Create(MM(-1*float(my_dict['p1'])*25.4), MM(float(my_dict['p5'])*25.4))
      end = Point2D.Create(MM((-1*float(my_dict['p2'])*25.4)-R1), MM(float(my_dict['p5'])*25.4))
      result = SketchLine.Create(start, end)
      # EndBlock

    • thilliard
      Subscriber

      Thank you will be doing some Python tutorials to be better scripted :) 

Viewing 4 reply threads
  • You must be logged in to reply to this topic.