Esempio n. 1
0
def io(inputfile = "", outputfile = "C:\SAP 2000\output.sdb"):
  """
  Opens the specified inputfile and outputfile. By default, it creates a new 
  model if no inputfile is specified and saves it as the specified outputfile. 
  If no outputfile is specified, the default location is 
  "C:\SAP 2000\output.sdb". Returns the program and model.
  """
  # start program
  program = sap2000.Sap2000()

  # This opens the model if it is passedin
  program.start(filename=inputfile)

  # If there was no model specified, open an empty one
  if inputfile == "":
    model = program.initializeModel()
    return_value = model.File.NewBlank()
    assert return_value == 0

  # Just point model to the right object
  else:
    model = program.sap_com_object.SapModel

  # save with new output file name (create directory if necessary)
  path = os.path.dirname(outputfile)
  path_exists(path)
  program.save(outputfile)

  # reset the correct units
  model.SetPresentUnits(UNITS[variables.program_units])

  return program, model
Esempio n. 2
0
  def reset(self, comment = ""):
    '''
    Allows us to reset everything without exiting the SAP program
    '''
    if self.started:
      # Resetting the SAP Program (this saves the previous file)
      self.SapProgram.reset(template=self.template)

      # Creating new SAP Files
      outputfolder = ('C:\SAP 2000\\' +strftime("%b-%d") + "\\" + 
        strftime("%H_%M_%S") + comment + "\\")
      outputfilename = "tower.sdb"
      outputfile = outputfolder + outputfilename

      # Create directory if necessary
      path = os.path.dirname(outputfile)
      helpers.path_exists(path)

      # Save to the new file
      ret = self.SapModel.File.Save(outputfolder + outputfilename)
      assert ret == 0

      # Reset the structure and the swarm
      self.Structure.reset()
      self.Swarm.reset()

      self.folder = outputfolder
      self.run = False

    else:
      print("The simulation is not started. Cannot reset.")