Your Products have been synced, click here to refresh
If you want to save a copy of the program itself you can use a basic script to save the current measuring routine, then save a copy of the measuring routine in some sort of archive folder.
NinjaBadger shared a nice script for that a while back. Here is a link to that post: https://www.pcdmisforum.com/forum/pc-dmis-enterprise-metrology-software/pc-dmis-code-samples/390021-auto-archive-freebie
I created some of my own scripts based on what he shared to save copies of the measuring routine each time we measure a part where I work. This one below can be called at the end of a measuring routine and it will automatically look in the program for operator inputs such as Operator Initials or Serial Number. It will then prompt the operator if they want to save the measuring routine and save a copy of the measuring routine in a separate folder in the same directory as the measuring routine is being executed from. If the operator clicks OK, It will make a folder with the same name as the measuring routine file name with an '(Archive)' suffix. A copy of the .prg and .cad file will be put in that folder with suffixes added to the file names. The suffixes will be the operator inputs separated by dashes "-" and the date/time the file was created. Those files are then made to be 'read-only' so the data is not lost if someone executes one of the archived programs.
' Save_Copy_And_Write_Protect ' ' By Cris_C 9-12-2019 ' ' Credit to NinjaBadger for the original program from which this was created. ' Post Link: https://www.pcdmisforum.com/forum/pc-dmis-enterprise-metrology-software/pc-dmis-code-samples/390021-auto-archive-freebie ' ' This Basic Script it to be called at the end of a measuring routine. ' It Saves the current measuring routine and then copies the .prg and the .cad file ' to a folder in the same directory as the measuring routine. The folder has the same ' name as the measuring routine .prg name with an "(Archive)" suffix. ' The copies are given a suffix made from operator inputs in the program (such as Serial number) and ' The date/time the copy was made. ' The copy of the .prg file and .cad file are then made Read-Only so data is not lost if someone tries ' to re-execute an archived program. Sub main() 'Create objects------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ '-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Dim pcapp As Object Set pcapp = createobject("pcdlrn.application") Dim pcpart As Object Set pcpart = pcapp.activepartprogram Dim Cmd As Object Dim Cmds As Object Dim ComCmd As Object Set Cmds = pcpart.Commands 'Figure out where To copy To/from----------------------------------------------------------------------------------------------------------------------------------------------------------- '-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 'Get the current prg And cad file path Dim prg_source_path Dim cad_source_path prg_source_path = pcpart.fullname cad_source_path = left(prg_source_path,len(prg_source_path)-4) & ".cad" 'Get program Name (without file extension) Dim progname progname = left(pcpart.Name,len(pcpart.Name)-4) 'Define the Archive Path Dim archivepath archivepath = left(pcpart.FullName,len(pcpart.FullName)-len(pcpart.Name)) & progname & "(Archive)" 'Get Additional Information from the CMM Program User inputs. -------------------------------------------------------------------------------------------------------------------- '--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 'Go Through Each of the Commands In the program And Find all the comments. If a comment is an Input comment Then Get the Object And retrieve the user Input. 'take the user Input And concatinate it into one variable. Essentially making a chain of all the user inputs In the order they appear In the program. Dim userinputs For Each Cmd In Cmds If Cmd.IsComment Then Set ComCmd = Cmd.CommentCommand If ComCmd.CommentType = 2 Then userinputs = userinputs & ComCmd.Input & "-" End If End If Next Cmd 'Replace Any characters that will mess up windows If you use them In a file Name. Also some that would be fine but I just don't like To see In a file Name. Dim revisedinputs For count=1 To Len(userinputs) If mid(userinputs,count,1) = "/" Or mid(userinputs,count,1) = "\" Or mid(userinputs,count,1) = "<" Or mid(userinputs,count,1) = ">" Or mid(userinputs,count,1) = ":" Or mid(userinputs,count,1) = "." Or _ mid(userinputs,count,1) = ";" Or mid(userinputs,count,1) = "?" Or mid(userinputs,count,1) = "*" Or mid(userinputs,count,1) = "|" Or mid(userinputs,count,1) = "," Or mid(userinputs,count,1) = """" Then newchar = "#" Else newchar = mid(userinputs,count,1) End If revisedinputs = revisedinputs & newchar Next 'Make sure the inputs are Not too Long For a file Name, Limit it To an arbitrary 30 characters. It leaves lots of space For Long CMM Program names And date And time. revisedinputs = left(revisedinputs,30) 'Complete the saving Name/path And Get ready To propt the user ----------------------------------------------------------------------------------------------------------------- '-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 'Genrate the destination (save) paths prg_dest_path = archivepath & "\" & progname & "(" & revisedinputs & ")_" & format(now(),"YYMMDDHHNNSS") & ".prg" cad_dest_path = archivepath & "\" & progname & "(" & revisedinputs & ")_" & format(now(),"YYMMDDHHNNSS") & ".cad" 'Create the Long String of text that will be used In the OK/Cancel Message box Dim Msg Msg = "The CMM measuring is complete." & chr(13) Msg = Msg & chr(13) Msg = Msg & "Would you like to save the current CMM program and also create a backup with the following name and location?" & chr(13) Msg = Msg & chr(13) Msg = Msg & prg_dest_path & chr(13) Msg = Msg & chr(13) Msg = Msg & "Click OK to save CMM program and make a backup." & chr(13) Msg = Msg & "Click CANCEL to skip the saving/backup operation." & chr(13) 'Create title For mesasge box MsgTitle = "CMM Program Backup Utility" 'Create File System Object For file operations 'Note: This Object is Not documented In the PC-DMIS help file. More details On it can be found On the Microsoft wesite. Try this link: 'https://docs.microsoft.com/en-us/office/vba/language/reference/user-interface-help/filesystemobject-object Dim fso As Object Dim fo As Object Set fso = createobject("scripting.filesystemobject") 'Display the OK/Cancel Message box And save/copy If user clicks OK. If the user clicks OK it will return a 1. ----------------------------------------------------------- '---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- If MsgBox(Msg,1,MsgTitle) = 1 Then 'Save existing program pcpart.save 'Check If the destination folder exists, If Not Then create one If Not fso.folderexists(archivepath) Then Set ofolder = fso.createfolder(archivepath) End If 'Copy the program And the cad file fso.copyfile prg_source_path, prg_dest_path fso.copyfile cad_source_path, cad_dest_path 'Create a file Object pointing To the coppied program And cad file. Then make the program Read-Only. Set fo = fso.GetFile(prg_dest_path) fo.Attributes = 1 Set fo = fso.GetFile(cad_dest_path) fo.Attributes = 1 End If 'Tidy up ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- '---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Set fso = Nothing Set pcpart = Nothing Set pcapp = Nothing Set Cmd = Nothing Set Cmds = Nothing Set ComCmd = Nothing End Sub
CS1 =SCRIPT/FILENAME= C:\USERS\CMM\DESKTOP\AUTOARCHIVE.BAS FUNCTION/Main,SHOW=YES,,, STARTSCRIPT/
I am trying to insert the script into my program. I start to type script and it gives me this line of code:CS1 =SCRIPT/FILENAME= C:\USERS\CMM\DESKTOP\AUTOARCHIVE.BAS FUNCTION/Main,SHOW=YES,,, STARTSCRIPT/Hmmm. This is the same way it appears when I use the script. I don't get an ENDSCRIPT/ line in my edit window. I don't know why NinjaBadger's example has that. At any rate, it still executes properly for me. It might have been something that has changed in the newer software versions.
I noticed that in ninja badger's code he has "ENDSCRIPT/" inserted after his start script but when I try and type "ENDSCRIPT" nothing pops up. Am I doing something wrong here? When I try and run my program, the file doesn't get routed to the selected folder I have in the script unless I press F9 on the line of code and hit the run button to the far right of the screen. Is there a way that I can insert this script code into a program and have it run automatically and send it to my requested directory without having to press F9 to run it each time?I don't know why it wouldn't run automatically when that command is executed in the measuring routine. The only thing I can think of is that when you insert a Basic Script command, PC-DMIS will automatically un-mark it (Skip it during execution). Make sure you have the command Marked. You can toggle it by putting the cursor on the command and hit F3.
Try that
© 2024 Hexagon AB and/or its subsidiaries. | Privacy Policy | Cloud Services Agreement |