hexagon logo

Auto Archive Freebie!

Hi All,

Here's my script for archiving programs.

Copy it to notepad and save it as AUTOARCHIVE.BAS

NOTE / WARNING -- This script first saves the program with the current measurement data in it, then takes a copy of the file to archive.


'JON WOOD - 2013 - 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 exist the value it holds will be used In the file Name
'of the archived program (i.e. can be a serial number, Or 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 uniqueid
uniqueid=""

Dim myvar As Object
Set myvar = pcpart.getvariablevalue(myUID)

If Not myVar is Nothing Then
uniqueid= myvar.stringvalue
'MsgBox(uniqueid)
End If

'Genrate the destination (save) path
dest_path = archivepath & "\" & progname & "\" & progname & "_" & uniqueid & "_" & 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

[CODE]


Usage in part program...

[CODE]


ASSIGN/UID="abc123"


CS5        =SCRIPT/FILENAME= C:\CMM FILES\SUBROUTINES\AUTOARCHIVE.BAS
            FUNCTION/Main,SHOW=YES,,
            STARTSCRIPT/
            ENDSCRIPT/

  • Hello, just a little help with the "Dim myUID" line! how can I put here the part serial number.
    this is how it is on my part program:
    -----------------------------------------------------------------
    C1 =COMMENT/INPUT,NO,FULL SCREEN=NO,
    Part SN:
    C2 =COMMENT/INPUT,NO,FULL SCREEN=NO,
    Date:
    C3 =COMMENT/INPUT,NO,FULL SCREEN=NO,
    Operator Name:
    C4 =COMMENT/INPUT,NO,FULL SCREEN=NO,
    Part OF:
    C5 =COMMENT/INPUT,NO,FULL SCREEN=NO,
    Meas Type:
    F - First Measurement
    R - Rework
    O - Other
    C6 =COMMENT/INPUT,NO,FULL SCREEN=NO,
    Remarks:
    ASSIGN/VAR_FILENAME="G:\CLIENTSXXXXXXXX\\F92435050_ "+SYSTEMDATE("dd'-'MM'-'yy")+"_"+SYSTEMTIME("hh'_'mm")+"_"+C1.INPUT+".PDF "
    COMMENT/OPER,NO,FULL SCREEN=YES,AUTO-CONTINUE=NO,
    ----------------------------------------------------------------------------

    thanks
  • Hello, just a little help with the "Dim myUID" line! how can I put here the part serial number.
    this is how it is on my part program:
    -----------------------------------------------------------------
    C1 =COMMENT/INPUT,NO,FULL SCREEN=NO,
    Part SN:
    C2 =COMMENT/INPUT,NO,FULL SCREEN=NO,
    Date:
    C3 =COMMENT/INPUT,NO,FULL SCREEN=NO,
    Operator Name:
    C4 =COMMENT/INPUT,NO,FULL SCREEN=NO,
    Part OF:
    C5 =COMMENT/INPUT,NO,FULL SCREEN=NO,
    Meas Type:
    F - First Measurement
    R - Rework
    O - Other
    C6 =COMMENT/INPUT,NO,FULL SCREEN=NO,
    Remarks:

    ASSIGN/SERNUM = C1.INPUT

    ASSIGN/VAR_FILENAME="G:\CLIENTSXXXXXXXX\\F92435050_ "+SYSTEMDATE("dd'-'MM'-'yy")+"_"+SYSTEMTIME("hh'_'mm")+"_"+C1.INPUT+".PDF "
    COMMENT/OPER,NO,FULL SCREEN=YES,AUTO-CONTINUE=NO,
    ----------------------------------------------------------------------------

    thanks



    In the script have

    Dim myUID
    MyUID = "SERNUM"

  • hello,

    it works perfectly!!!
    Thanks a lot!!!!
  • hello

    Hello
    I have an error on line 35 ( Set pcapp = createobject("pcdlrn.application"))​, my software is in French, can it come from there?​
    I searched and I found PRDLNR.EXE in "C:\Program Files\Hexagon\PC-DMIS 2021.2 64-bit"

    thx for you're help


  • Do you have more than one PC-DMIS version installed?
    I think I had a problem once where a script didn't work because it looked for one of the other installed PC-DMIS versions.

    The fix was to open the version I was using once as an administrator. After it looked for this version.
    When you then again run another version you need to first run this version again as an administrator once.
  • my apologies in advance, but my use of scripts is extremely limited.
    i would like to set it up so that when a program is done it performs a save as at the end without me needing to be here.
    I have no idea how to implement this script. would like some pointers.
  • where do you put this? at the end of the program?
  • Hello,

    * the script creates a copy of your measurement routine at a desired path.
    Under "========= SETTINGS =================" you can set the path.

    * copy the code from this forum into a file and name it "AutoArchiveFreebie.BAS"
    First line must be "Sub main()"; Last line must be "End Sub" wtihin this file

    * within pcDMIS: insert -> Basic Script -> use the file you just created -> a "script-command" will be created
    the Script-command belongs at the last position in your routine. (If necessary, unmark the command)
  • " under SETTINGS you can set the path."

    settings where?

  • 1.take the code that you saved from this forum and place it in your C:drive, users, public, public documents
    2. open pc dims. click on "insert" then scroll down to "basic script"
    3. navigate to the public docs folder and select the code.

    should look something like this