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.
Parents
  • 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
    
Reply
  • 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
    
Children
No Data