3D Design

3D Design

Topics related to Ansys Discovery and Ansys SpaceClaim.

Use part name in a script

    • Andrea Ventura
      Subscriber

      Hello,

      I want to create a script to save unfolded part as DXF using the part name

      DocumentSave.Execute(r"C:\temp\temp1.dxf")

      Something like this, where "C:\temp\" + VARNAME + ".dxf" is a variable.
      Can you help me?

    • Devendra Badgujar
      Forum Moderator

      Hello DrkAngl

      Let me check this and will get back to you.

    • Devendra Badgujar
      Forum Moderator

      Hello DrkAngl

      You just need to construct the string as you have shown it, but there can be issues using in strings because it is used by formatting in python to put in return characters and other things. You should be able to do something like this using \. Alternatively you can also use unix style / for the path.

      Save file with variable in file path

      Text

      # Python Script, API Version = V20
      fileName="NewFile"
      DocumentSave.Execute("D:\temp\"+fileName+".dxf")
      #or DocumentSave.Execute("D:/temp/"+fileName+".dxf")
    • Andrea Ventura
      Subscriber

      Thanks Devendra,

      but how to get unfolded part name?

    • Devendra Badgujar
      Forum Moderator

      Hello DrkAngl

      You can use a snippet like this to select a file location for the export.

      DXF File Export Path

      Text

      fileDialog=SaveFileDialog()
      fileDialog.Filter="DXF|*.dxf"
      fileDialog.Title="Export Unfolded DXF"
      fileDialog.Show()
      filePath=fileDialog.FileName
      DocumentSave.Execute(filepath)

      The rest of the script will have to cover how the part is unfolded or what ever the you want to get unfolded part name to do before the file is saved as a dxf.

      Can you please let me know all the steps of the process that you do till now to get the file out of the tool using the GUI ?

    • Andrea Ventura
      Subscriber

      Thanks Devendra Badgujar ,
      but it not solve.
      I try to explain better the process.
      I want to save a DXF using as name the component name (not the unfolded name, but folded one)

       

    • Devendra Badgujar
      Forum Moderator

      Hello DrkAngl

      Let me discuss this with the team and will update you once I get useful information.

      Regards.

    • Devendra Badgujar
      Forum Moderator

      Hello DrkAngl

      You can use something like this to get component name for DXF:

      component = part.GetComponents(comp_name)
      comp_name = "Ünfolded"
      new_name = " part name

      Then you will have to manually record the steps in SpaceClaim to get unfolded as a part name in the         '' unfolded part ''  window using Record button in the scripts, then you will need to add some more scripting things to add this functionalities like:

      component.Rename

      Then you add snippet like this shown below in the script to select a file location for the export.

      DXF File Export Path

      Text

      fileDialog=SaveFileDialog()
      fileDialog.Filter="DXF|*.dxf"
      fileDialog.Title="Export Unfolded DXF"
      fileDialog.Show()
      filePath=fileDialog.FileName
      DocumentSave.Execute(filepath)

      You can learn more about scripting from this Scripting tutorial, please use this link to check it

      Discovery SpaceClaim: Model Prep for CAE & MFG - SpaceClaim Tutorials - Ansys Discovery Forum

      Let me know if you need further assistance.

      Regards.

Viewing 7 reply threads
  • The topic ‘Use part name in a script’ is closed to new replies.