hexagon logo

Using script to create folder for prg and save part program

Been reading up on the script manual (PC-DMIS) 3.6 Basic Language Reference Manual) trying to figure out how to get the script to create a folder for the report, the .prg, and any other files associated with the program by serial number of the part.

For example:
PART#_DESCRIPTION_SERIAL#_DATE_TIME

The goal is to write a script contained in the .prg that, upon execution of the part program, will create a folder in a specified directory with the variable filename using the inputs from the part program and save the .prg with the same name.

How would I pass the information from the operator inputs of the part program into the script to make this happen?
  • Look at the "Create folder script" by me that is listed down below under the headline "Similar threads" (or use the search function, Rookie).

    If it by any reason won't show up for you, here's the link:
    http://www.pcdmisforum.com/showthread.php?8552-Create-folder-script

    It may contain stuff you can use to build further on.
    It saves the report (not the program) but can easily be modified to do so.
  • Sub Main
    
    ' THIS SECTION DECLARES THE VARIABLES For THE FILENAME SAVE And FOLDER CREATE
    ' "SET" DECLARES THE VALUE OF THE VARIABLES
    ' "PART.GETVARIABLEVALUE" PULLS THE VARIABLE VALUE FROM THE .PRG UPON EXECUTION
    
    Dim App As Object
    Set App = CreateObject("PCDLRN.Application")
    
    Dim Part As Object
    Set Part = App.ActivePartProgram
    
    'Declares PartProg As the Active part program
    Dim PartProg As Object
    Set PartProg = App.ActivePartProgram
    
    Dim Cmds As Object
    Set Cmds = Part.Commands
    
    Dim  VSERIAL As Object
    Set VSERIAL = PART.GETVARIABLEVALUE ("VSERIALNUMBER")
    
    Dim  VDATE As Object
    Set VDATE = PART.GETVARIABLEVALUE ("VDATE")
    
    Dim VTIME As Object
    Set VTIME = PART.GETVARIABLEVALUE ("VTIME")
    
    Dim  VPARTNUMBER As Object
    Set VPARTNUMBER = PART.GETVARIABLEVALUE ("VPART")
    
    Dim VDESCRIPTION As Object
    Set VDESCRIPTION = PART.GETVARIABLEVALUE ("VDESCRIPTION")
    
    
    
    
    End Sub

    Would this work for a start? There's a lot of commands in that code that I'm not yet familiar with...
    I will be studying that post for a while.

    Thanks for the help, vpt. You have no idea how much it's appreciated.
  • I guess that will work, but that code needs assignments in your partprogram before it can do anything else (VSERIALNUMBER, VDATE, VTIME, VDESCRIPTION).
  • I guess that will work, but that co  de needs assignments in your partprogram before it can do anything else (VSERIALNUMBER, VDATE, VTIME, VDESCRIPTION).


    Attaching a .png of the issue you just mentioned. When I execute the part program and in turn the script inside the program, I get the error shown in the screenshot. Those values (VSERIALNUMBER...ETC.) are input variables from comments in the part program. The scripting engine tells me that they do not have a default value. I need them to be variable for the script to work like I need it to.

    If this method is not good, then please let me know. I will take any suggestions since this is my first attempt at scripting.

    I just don't know the code well enough yet to know any better...
  • Ah, didn't notice it in the code you posted. You are trying to create an object from a string concatenation.

    Try dim'ing the FILENAME, FILEPATH and FOLDER as strings instead.

    Add this to the beginning of your script:
    Dim FILENAME, FILEPATH, FOLDER As string


    Then just remove the "CREATEOBJECT( .. )" from the FILENAME, FILEPATH and FOLDER definitions.
    Leave the Set FILENAME = "D:........" as is for FILENAME, FOLDER and FILEPATH.

    ...or post the entire script you got so we can edit that directly.
  • So what command (syntax) actually creates the folder I want? CreateObject?


    Sub Main
    
    ' THIS SECTION DECLARES THE VARIABLES For THE FILENAME SAVE And FOLDER CREATE
    ' "SET" DECLARES THE VALUE OF THE VARIABLES
    ' "PART.GETVARIABLEVALUE" PULLS THE VARIABLE VALUE FROM THE .PRG UPON EXECUTION
    
    Dim App As Object
    Set App = CreateObject("PCDLRN.Application")
    
    Dim PART As Object
    Set Part = App.ActivePartProgram
    
    'Declares PartProg As the Active part program
    
    Set PartProg = App.ActivePartProgram
    
    Set Cmds = Part.Commands
    
    Set VSERIAL = PART.GETVARIABLEVALUE ("VSERIALNUMBER")
    
    Set VDATE = PART.GETVARIABLEVALUE ("VDATE")
    
    Set VTIME = PART.GETVARIABLEVALUE ("VTIME")
    
    Set VPARTNUMBER = PART.GETVARIABLEVALUE ("VPART")
    
    Set VDESCRIPTION = PART.GETVARIABLEVALUE ("VDESCRIPTION")
    
    Set RESULTS = RESULTS
    
    Set  VPROGRAMID = PART.GETVARIABLEVALUE ("VPROGRAMID")
    
    'Creates the file folder path
    
    Set FILENAME = CREATEOBJECT(VPART & "_" & VDESCRIPTION & "_" & VSERIALNUMBER & "_" & VDATE & "_" & VTIME)
    
    Set FILEPATH = CREATEOBJECT("D:\CMM_PROGRAMS\" & VPART & "_" & VDESCRIPTION & "_" & VPROGRAMID & "\" & RESULTS & "\")
    
    Set FOLDER = CREATEOBJECT(FILEPATH & FILENAME)
    
    End Sub
    
  • Ah, didn't notice it in the code you posted. You are trying to create an object from a string concatenation.

    Try dim'ing the FILENAME, FILEPATH and FOLDER as strings instead.

    Add this to the beginning of your script:
    Dim FILENAME, FILEPATH, FOLDER As string


    Then just remove the "CREATEOBJECT( .. )" from the FILENAME, FILEPATH and FOLDER definitions.
    Leave the Set FILENAME = "D:........" as is for FILENAME, FOLDER and FILEPATH.

    ...or post the entire script you got so we can edit that directly.

    Dim FILENAME, FILEPATH, FOLDER As String
    
    Dim App As Object
    Set App = CreateObject("PCDLRN.Application")


    Gives me same error
  • Ah, didn't notice it in the code you posted. You are trying to create an object from a string concatenation.

    Try dim'ing the FILENAME, FILEPATH and FOLDER as strings instead.

    Add this to the beginning of your script:
    Dim FILENAME, FILEPATH, FOLDER As string


    Then just remove the "CREATEOBJECT( .. )" from the FILENAME, FILEPATH and FOLDER definitions.
    Leave the Set FILENAME = "D:........" as is for FILENAME, FOLDER and FILEPATH.


    Additionally, you'll have to access the properties of the Variable type objects to get the data. Like this:

    FILENAME = VPART.StringValue & "_" & VDESCRIPTION.StringValue & "_" & VSERIALNUMBER.StringValue & "_" & VDATE.StringValue & "_" & VTIME.StringValue
  • So what command (syntax) actually creates the folder I want? CreateObject?


    I would really recommend that you go to your local used bookstore and pick up a book on VBScript. No offense, but this question demonstrates a complete lack of understanding about what's going on. You need to obtain a basic understanding before taking off. (a book is how I got started on my first programming language - VAX VMS based Fortran77!)

    Anyways, to answer your question: there are a couple of ways to create the folder(s) you can use the VB based MkDir() to create the folder(s), along with Dir() to see if it needs to be created, or you can use the scripting file system object as vpt does in his script.
  • I would really recommend that you go to your local used bookstore and pick up a book on VBScript. No offense, but this question demonstrates a complete lack of understanding about what's going on.


    None taken. I admittedly have no idea. That's why I'm trying to learn. You never learn anything until you ask...right?

    I only started learning PC-DMIS in February. I had a Drafting and CAD background and was hired to learn programming. I pick up pretty quick, but I can't use "the force" to learn the script. LOL

    I would really recommend that you go to your local used bookstore and pick up a book on VBScript.


    Good suggestion...