help, auto save .prg after run, in a specific location variable.

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • help, auto save .prg after run, in a specific location variable.

    I have been looking through all the past topics about this. but I am having trouble getting them working. I tried copy and pasting a few of them. and saving them as a .bas file and running the script. but i cant get one to work for me.


    i currently already have a script that auto creates a folder from an operator input and saves the cmm report in that folder.

    so ideally i want to follow that same train of thought and save a .prg & .cad in that same folder already created.


    please advice.

    -riley Lawlor
    Southern California
    Aerospace CNC Machinery

  • #2
    Credit goes to pcdmisforum.com username vpt.se

    Hopefully your CMM computer has the correct permission settings to run BAS scripts.

    1. At beginning of program:
    Code:
    'TOTALLY FREE OPEN SOURCE CODE NO TRADEMARK OR COPYRIGHT WHATSOEVER
    'NO WARRANTY OR GUARANTEE IMPLIED OR SPECIFIED
    'WORKS WITH WITH PC-DMIS SOFTWARE
    
    ' Displays an inputbox telling the user To enter a serialnumber
    ' Or other information that will be concatenated To the partprogram
    ' Part Name from program header And saved In the current partprogram folder.
    ' If the file already exist, the user will be prompted and told
    ' to enter a new serial.
    '
    ' vpt.se 2011
    
    '1) Requires variable assignment for SERNO to be in PC-DMIS program
    
    '2) Insert at beginning of program.
    
    '3) Additionally, use companion "Auto Save" script at end of program.
    
    '4) For PCDMIS v2011 MR1 and up, Registy Setting "DocumentRecovery" needs to be set to False
    
    '--------------------------------------------------------------------------
    
    Sub Main()
    Dim PCDApp, PCDPartPrograms, PCDPartProgram
    
    Set PCDApp = CreateObject("PCDLRN.Application")
    Set PCDPartPrograms = PCDApp.PartPrograms
    Set PCDPartProgram = PCDApp.ActivePartProgram
    Dim Cmds As Object
    Dim Cmd As Object
    Set Cmds = PCDPartProgram.Commands
    
    ser$ = InputBox$("Enter serial number:", "Serial", "", 200, 175)
    If ser$ <> "" Then
      newname = PCDPartProgram.Path & PCDPartProgram.PartName & "_" & ser$ & ".PRG"
      retval = PCDPartProgram.SaveAs(newname)
    End If
    
    For Each Cmd In Cmds
    If Cmd.Type = ASSIGNMENT Then
       If Cmd.GetText(DEST_EXPR, 0) = "SERNO" Then
          bln = Cmd.PutText("""" + ser$+ """", SRC_EXPR, 0)
          Cmd.ReDraw
       End If
    End If
    Next Cmd
    
    ' Cleanup
    Set PCDPartProgram = Nothing
    Set PCDPartPrograms = Nothing
    Set PCDApp = Nothing
    End Sub
    and

    2. At end of program:
    Code:
    'TOTALLY FREE OPEN SOURCE CODE NO TRADEMARK OR COPYRIGHT WHATSOEVER
    'NO WARRANTY OR GUARANTEE IMPLIED OR SPECIFIED
    'WORKS WITH WITH PC-DMIS SOFTWARE
    
    '     1) Insert at end of program.
    
    '     2) Additionally, use companion "Auto Save With Serial Number" script at beginning of program.
    
    
    Sub Main()
    Dim PCDApp, PCDPartPrograms, PCDPartProgram 
    
    Set PCDApp = CreateObject("PCDLRN.Application")
    Set PCDPartPrograms = PCDApp.PartPrograms
    Set PCDPartProgram = PCDApp.ActivePartProgram
    
      retval = PCDPartProgram.Save
    
    
    ' Cleanup
    Set PCDPartProgram = Nothing
    Set PCDPartPrograms = Nothing
    Set PCDApp = Nothing
    End Sub

    Comment


    • vpt.se
      vpt.se commented
      Editing a comment
      Thanks for the credits, it's rare thing in our times.

  • #3
    I wouldn't recommend saving the .CAD file though, as you will quickly fill up hard drive or network space that way. The program files are fairly small so just save them. make sure that you take note within the program which version of CAD was used and if and when you need it you can add the cad back in very easily.

    Comment


    • #4
      Here's mine, feel free to use.

      Note - it doesn't save the CAD (if it did my archive would be MASSIVE)

      If I want to review the program with CAD in it I simply import the .CAD file from the original program

      Code:
      '
      JON WOOD - AUTOMETTECH LTD (UK) www.automettech.com
      
      Sub main()
      
      
      '========= SETTINGS =================
      
      'Root save directory For archive
      Dim archivePath
      archivePath = "C:\CMM\Archive\AutoArchive"
      
      'This is the Name of a PC-Dmis ASSIGNMENT - If it exists the value it holds will be used In the file Name
      'of the archived program (i.e. can be a serial number, Or works order number etc)
      Dim myUID
      myUID = "UID"
      
      'NOTE! - File Name will be In the following format...
      'SaveDirectory\Program Name\ProgramName_UniqueID_DateTime.prg
      
      'i.e. C:\CMM Files\Part Program Run Instances Archive\123456-01\123456-01_abc123_20140824104232.prg
      
      'Where...
      'archivePath = "C:\CMM Files\Part Program Run Instances Archive"
      'Part program = 123456-01.prg
      'Serial Number / Unique Id = abc123
      'DateTime = 24/08/2014 10:42:32
      
      
      '===========End OF SETTINGS==========
      
      'Create objects
      Dim pcapp As Object
      Set pcapp = createobject("pcdlrn.application")
      
      Dim pcpart As Object
      Set pcpart = pcapp.activepartprogram
      
      'Save existing program
      pcpart.save
      
      'Get the current program path
      Dim source_path
      source_path = pcpart.fullname
      
      'Get program Name (without file extension)
      Dim progname
      progname = left(pcpart.Name,len(pcpart.Name)-4)
      
      'Create File System Object For file operations 
      Dim fso As Object
      Set fso = createobject("scripting.filesystemobject")
      
      'Check main archive directory And program specific directories exist
      Dim ofolder As Object
      
      If Not fso.folderexists(archivepath) Then
      Set ofolder = fso.createfolder(archivepath)
      End If
      
      If Not fso.folderexists(archivepath & "\" & progname) Then
      Set ofolder = fso.createfolder(archivepath & "\" & progname)
      End If
      
      'Get a UID If present
      Dim uid
      uid=""
      
      Dim myvar As Object
      Set myvar = pcpart.getvariablevalue(myUID)
      
      If Not myVar is Nothing Then
      uid = myvar.stringvalue
      'MsgBox(uid)
      End If
      
      'Genrate the destination (save) path
      dest_path = archivepath & "\" & progname & "\" & progname & "_" & uid & "_" &  format(now(),"YYYYMMDDHHNNSS") & ".prg"
      'MsgBox(dest_path)
      
      
      'Save the file
      fso.copyfile source_path, dest_path
      
      
      'Tidy up
      Set fso = Nothing
      Set pcpart = Nothing
      Set pcapp = Nothing
      
      
      End Sub
      Automettech - Automated Metrology Technology

      Comment


      • #5
        And mine, from the old thread - http://www.pcdmisforum.com/forum/pc-...873#post301873

        What version of PC-DMIS are you running? 32- or 64-bit? Do note that 64 bit PC-DMIS versions has had quite a lot of bugs in the BASIC department, among other things my script didn't work. I believe those BASIC bugs are fixed now, but I don't remember exactly from which version...

        My script definitely works in 2016.0 SP7 (I don't have anything older immediately at hand).
        AndersI
        SW support - Hexagon Metrology Nordic AB

        Comment


        • #6
          running 2016 & or 2017. Thanks guys!!!!
          -riley Lawlor
          Southern California
          Aerospace CNC Machinery

          Comment


          • #7
            I have everything set up now., after the program is complete it will create a SN-(folder) with comment input. Then it dumps the CMM report in that folder, along with .prg & .CAD(for now) and creates an .IGES file of all the measure data. The script has me assign which alignment to use for creating the .iges file, and the first and last feature. And creates a .MEA file of scan files.


            So excited i got everything completed this week.
            -riley Lawlor
            Southern California
            Aerospace CNC Machinery

            Comment


            • Zeros
              Zeros commented
              Editing a comment
              If possible could you share the completed code so others can learn from it?

            • DaVe_M
              DaVe_M commented
              Editing a comment
              I'd like to echo Zeros' request... I've been trying to accomplish the folder creation aspect as well as auto saving the program and data in said folder. So far I've had little success, so if you wouldn't mind sharing the completed code that would be fantastic

          • #8
            By any chance would anyone else be able to offer a suggestion as to what I'm doing wrong here? I'm attempting to check for an existing folder in Q:\Quality\In Process Inspection Plans\11127-MACHINE\CMM REPORTS for a folder named for the Job Number. If the folder exists, I'm wanting to save both the readout and the program in this folder with the serial number for the part attached to the end of each to differentiate each one from the readout and program saved for the other parts with differing serial number but are under the same job(work order).
            I had the code working to save the program in the CMM REPORTS folder, but when I attempted to modify it to put it in the folder that was created using the Job number, it gave me an "OLE Automation method exception" error on the line beginning with "newname". I'm not sure if I'm not setting the file path up correctly or what exactly I'm doing wrong, but any help would be appreciated...

            Code:
            Sub Main()
            Dim PCDApp,PCDPartProgram, PCDCommands, PCDCommand, retval
            Dim objFSO
            Set objFSO = CreateObject ("Scripting.FileSystemObject")
            
            Set PCDApp = CreateObject("PCDLRN.Application")
            Set PCDPartPrograms = PCDApp.PartPrograms
            Set PCDPartProgram = PCDApp.ActivePartProgram
            Dim Cmds As Object
            Dim Cmd As Object
            Set Cmds = PCDPartProgram.Commands
            Dim setCrntName As String
            Dim PartNo As Object
            Dim JobNo As Object
            Dim SerNo As Object
            Dim SerialNo As String
            Dim Results As String
            
            Set PartNo = PCDPartProgram.GetVariableValue ("V5")
            Set JobNo = PCDPartProgram.GetVariableValue ("V1")
            Set SerNo = PCDPartProgram.GetVariableValue ("V2")
            Set Serial = PCDPartProgram.GetVariableValue ("V2")
            
            strPath = "Q:\Quality\In Process Inspection Plans\PartNo.StringValue\CMM REPORTS\"
            strFolderName = JobNo.StringValue & "_" & SerNo.StringValue
            strFolder = strPath & "\RESULTS\" & strFolderName
            
            If Not objFSO.FolderExists(strFolder) Then
            Set objFolder = objFSO.CreateFolder(strFolder)
            
            End If
            
            SerialNo = Serial.StringValue
            setCrntName = PCDPartProgram.FullName
            newname = "Q:\Quality\In Process Inspection Plans\" & PartNo.StringValue & "\CMM REPORTS\ObjFolder\" & PCDPartProgram.PartName & " - " & SerialNo & ".PRG"
            
            retval = PCDPartProgram.SaveAs(newname)
            retval = PCDPartProgram.SaveAs(setCrntName)
            
            ' Cleanup 
            
            Set PCDPartProgram = Nothing
            Set PCDPartPrograms = Nothing
            Set PCDApp = Nothing
            End Sub
            sigpic

            Comment


            • #9
              Don't know if this will help with the error, but this line is wrong:

              strPath = "Q:\Quality\In Process Inspection Plans\PartNo.StringValue\CMM REPORTS"
              Should be:

              strPath = "Q:\Quality\In Process Inspection Plans\" & PartNo.StringValue & "\CMM REPORTS"
              PC-DMIS CAD++ 2o19 R1 SP4

              Comment


              • #10
                As I have noted in other posts, the "\" is a special character inside strings and needs to be doubled.
                (And as I have also noted, it is special in the forum software... sigh!)

                Your
                Code:
                strPath = "Q:\Quality\In Process Inspection Plans\PartNo.StringValue\CMM REPORTS\"
                needs to be changed to at least
                Code:
                strPath = "Q:\Quality\In Process Inspection Plans\PartNo.StringValue\CMM REPORTS\\"
                but it might be even better to change them all:
                Code:
                strPath = "Q:\\Quality\\In Process Inspection Plans\\PartNo.StringValue\\CMM REPORTS\\"
                \" is read by PC-DMIS to mean "insert a quotation mark in the string"
                \\ means "insert one \ in the string"
                Last edited by AndersI; 08-28-2018, 04:42 AM. Reason: This **** forum software eats one level of backslash each time I edit...
                AndersI
                SW support - Hexagon Metrology Nordic AB

                Comment


                • #11
                  Thank you for the great explanation AndersI.

                  B&S CHAMELEON/PCDMIS CAD++ V2011

                  There are no bugs, only "UNDOCUMENTED ENHANCEMENTS!"

                  sigpic

                  Comment


                  • #12
                    Thanks for the answer and explanation AndersI.

                    B&S CHAMELEON/PCDMIS CAD++ V2011

                    There are no bugs, only "UNDOCUMENTED ENHANCEMENTS!"

                    sigpic

                    Comment


                    • #13
                      Your help is very much appreciated, gentlemen...unfortunately, after incorporating both suggested changes, I'm still getting "Error on line: 29 - OLE Automation Exception" (Line 29 being "newname = "Q:\Quality\In Process Inspection Plans" & PartNo.StringValue & "\CMM REPORTS\ObjFolder" & PCDPartProgram.PartName & " - " & SerialNo & ".PRG")
                      . I've looked up information on this error message and haven't been able to find anything that was of any real use in helping me resolve it. I don't know if it's a formatting issue or what exactly I'm looking at here, but it's definitely got me stumped.
                      sigpic

                      Comment


                      • #14
                        Thought that I had it here, but no such luck.

                        Code:
                        newname = "Q:\Quality\In Process Inspection Plans\" & PartNo.StringValue & "\CMM REPORTS\" & ObjFolder & "\" & PCDPartProgram.PartName & " - " & SerialNo & ".PRG"
                        sigpic

                        Comment


                        • AndersI
                          AndersI commented
                          Editing a comment
                          Did you read my post? You can't end a string with \", it must be \\" (Or was it the forum that removed the doubles?)

                        • DaVe_M
                          DaVe_M commented
                          Editing a comment
                          So would it need to be like this?

                          Code:
                          newname = "Q:\Quality\In Process Inspection Plans\" & PartNo.StringValue & "\CMM REPORTS\" & ObjFolder & "\\" & PCDPartProgram.PartName & " - " & SerialNo & ".PRG"
                          I still get the same error message...

                          Same with this

                          Code:
                          newname = "Q:\\Quality\\In Process Inspection Plans\\" & PartNo.StringValue & "\\CMM REPORTS\\" & ObjFolder & "\\" & PCDPartProgram.PartName & " - " & SerialNo & ".PRG"
                          Last edited by DaVe_M; 08-28-2018, 10:59 AM.

                      • #15
                        I guess I'm not the only one stumped by this...
                        sigpic

                        Comment

                        Related Topics

                        Collapse

                        Working...
                        X