hexagon logo

Scripting Help for auto Save-as

Trying to get going on some scripting and automation. Very new to this so any and all help most appreciated. The following code gives this error :

---------------------------
PC-DMIS Basic Scripting Engine
---------------------------
Error on line: 9 - OLE Automation object does not have a default value
---------------------------
OK
---------------------------

Can someone help me get this simple script running?

Sub Main ()
Dim App As Object
Dim Part As Object
Set App = CreateObject ("PCDLRN.Application")
Set Part = App.ActivePartProgram
Dim Serial As Object
Set Serial = Part.GetVariableValue("V1")
Dim NewName$
NewName = Part.Path & Part.PartName & "_" & Serial & ".PRG"
retval = Part.SaveAs(NewName)
' Cleanup
Set Part = Nothing
Set App = Nothing
End Sub


I believe this code was originally posted in a different (and probably much better) form by VPT.se. I'm trying to learn how to do this sort of thing by modifying it.

Thanks for any help.
  • I changed the code to strpath=L:\CMM\ and I get a sytnax error message
  • DaSalo is correct, just change this:

    strPath = Part.Path


    ...to whatever path you want to save it to.

    strPath = "C:\myprograms\"


    ...will save it to C:\myprograms\RESULTS

    If you don't want the "RESULTS" part, just delete as following:

    strNewName = strPath & "RESULTS\" & strNoExt & "_" & Serial.StringValue & ".prg"


    ...to...

    strNewName = strPath & strNoExt & "_" & Serial.StringValue & ".prg"
  • Thanks I wasnt using the "" "" around the path and now it works.
  • I love the Autosave script, much thanks to Craiger and VPT.SE for developing it.

    I found out how to get around the wierd error that pops up when you use it 2011 MR1 - you have to edit the registry and turn OFF the File Recovery feature that runs seamlessly and effectively in the background.

    CAUTION NEWBIES DO NOT FOOK AROUND IN THE REGISTRY IT IS A DANGEROUS PLACE

    FileMan category, the DocumentRecovery entry. Set to False.



    ~~~~~~~~~~~~~~


    And here's a new verision of AutoSaveAs I made for a customer running BladeRunner.
    As BladeRunner already prompts the operator to enter a serial #, it's unnecessary to do that again in a PC-DMIS program (many blades need to run an additional PC-DMIS program to obtain non-aerofoil-specific dimensions on their mounting features).


    Sub Main()
    '________________________________________________________________________________________________________________________________________________
    '''' Automated File-Save As script for PC-DMIS non-blade-dimensional inspection program used in Blade Runner Applications
    
    '''' For PCDMIS v2011 MR1, Registy Setting "DocumentRecovery" needs to be set to False
    
    '''' Need to assign variable named SERNO in PC-DMIS program to collect Serial Number
    '________________________________________________________________________________________________________________________________________________
    
    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
    
    Dim Length as Integer
    Dim serialine As String
    Dim serial As String
    serial = ""
    
    Open "C:\BladeRunner\Header.TXT" for Input as #1
         Line Input #1, partline
         Line Input #1, datetimeline
         Line Input #1, serialine
    Close #1
    
    'MsgBox(serialine)
    
    Length = Len(serialine)
    'MsgBox(Length)
    If Length > 14 Then
    serial = Mid(serialine, 14, Length-14)
    'MsgBox(serial)
    End If
    
    
    If serial <> "" Then
      newname = PCDPartProgram.Path & PCDPartProgram.PartName & "_" & serial & ".PRG"
    'MsgBox(newname)
      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("""" + serial + """", SRC_EXPR, 0)
          Cmd.ReDraw
       End If
    End If
    Next Cmd
    
    
    ' Cleanup
    Set PCDPartProgram = Nothing
    Set PCDPartPrograms = Nothing
    Set PCDApp = Nothing
    End Sub
    
  • Thanks for sharing!

    I hope you don't charge $$$ when using freeware scripts posted by users...
  • Thanks for sharing!

    I hope you don't charge $$$ when using freeware scripts posted by users...


    That BAS got sent to a customer who called and requested our help, we whipped it up and sent it to him free of charge.


    !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!


    I just had a brainstorm.

    What if PC-DMIS had this serial-number-auto-save-as for a built-in function? Would that be awesome?
  • That BAS got sent to a customer who called and requested our help, we whipped it up and sent it to him free of charge.


    :-D

    I just had a brainstorm.

    What if PC-DMIS had this serial-number-auto-save-as for a built-in function? Would that be awesome?


    Well, it seems that it is something that many users would benefit from, so I'd say yes. "Awesome" would be a working PC-DMIS with no bugs, so I guess if this was added, it would just be "great".
  • Please not an auto-save-as, but a method to save-as ! Sheesh, enough challenges working with this as it is!
  • Please not an auto-save-as, but a method to save-as ! Sheesh, enough challenges working with this as it is!


    ????
    Please clarify
  • Josh, I don't want to see an "auto-save-as" feature that can't be toggled off.