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'm going to answer my own question now that I've done some more work on this:

    This problem described above is because the reference to "Serial" in line 9 does not explicitly define the type of value to use from "Serial". It seems that the value type for a referenced object like that needs to be expicitly defined. The allowed types are .type, .commandvalue, .doublevalue, .stringvalue, .longvalue, .pointvalue. Each of these will yield a different value and will be appropriate in different circumstances. The above code should work if I substitute "Serial.StringValue" in place of "Serial" in line 9. I haven't actually tried it because I ended up writing some different code combining some other ideas found on this forum.

    Here is what I ended up with. This seems to work very well for my needs and hopefully will be helpful to someone else as well:

    Sub Main
    
    ' This Script will Append the serial number entered In the C1 Input comment In the PC-DMIS program
    ' To the part program Name And save the file into a folder named "RESULTS" that resides
    ' In the same directory As the part program. It will Then resave As the original part program Name In
    ' the original directory, ready To be executed again.
    '---------------------------------------------------------------
    ' Create a Folder In the same directory As the Part Program called "RESULTS"
    
    ' Insert this code at beginning of PC-DMIS program:
    
    ' C1 =COMMENT/Input, NO, FULL SCREEN=NO,
    '        Enter Part Serial Number
            
    '        ASSIGN/SER_NUM=(C1.Input)
    '-------------------------------------------------------------
    
    
    Dim App As Object
    Dim Part As Object
    Dim Serial As Object
    Dim strCrntName As String
    Dim strPath As String
    Dim strPrgName As String
    Dim strNewName As String
    Dim strNoExt As String
    Dim bolPassFail As Boolean
    Dim FindDot
    
    Set App = CreateObject ("PCDLRN.Application")
    Set Part = App.ActivePartProgram
        Set Serial = Part.GetVariableValue ("SER_NUM")
            strCrntName = Part.FullName
            strPath = Part.Path
            strPrgName = Part.Name
                FindDot = InStr(1, strPrgName, ".")
            strNoExt = Left(strPrgName, FindDot - 1)
            strNewName = strPath & "RESULTS\" & strNoExt & "_" & Serial.StringValue & ".prg"
    
    bolPassFail = Part.SaveAs (strNewName)
    bolPassFail = Part.SaveAs (strCrntName)
    
    End Sub


    The code here is an adaptation of code written and posted to this forum by vpt.se and Craiger_NY.
Reply
  • I'm going to answer my own question now that I've done some more work on this:

    This problem described above is because the reference to "Serial" in line 9 does not explicitly define the type of value to use from "Serial". It seems that the value type for a referenced object like that needs to be expicitly defined. The allowed types are .type, .commandvalue, .doublevalue, .stringvalue, .longvalue, .pointvalue. Each of these will yield a different value and will be appropriate in different circumstances. The above code should work if I substitute "Serial.StringValue" in place of "Serial" in line 9. I haven't actually tried it because I ended up writing some different code combining some other ideas found on this forum.

    Here is what I ended up with. This seems to work very well for my needs and hopefully will be helpful to someone else as well:

    Sub Main
    
    ' This Script will Append the serial number entered In the C1 Input comment In the PC-DMIS program
    ' To the part program Name And save the file into a folder named "RESULTS" that resides
    ' In the same directory As the part program. It will Then resave As the original part program Name In
    ' the original directory, ready To be executed again.
    '---------------------------------------------------------------
    ' Create a Folder In the same directory As the Part Program called "RESULTS"
    
    ' Insert this code at beginning of PC-DMIS program:
    
    ' C1 =COMMENT/Input, NO, FULL SCREEN=NO,
    '        Enter Part Serial Number
            
    '        ASSIGN/SER_NUM=(C1.Input)
    '-------------------------------------------------------------
    
    
    Dim App As Object
    Dim Part As Object
    Dim Serial As Object
    Dim strCrntName As String
    Dim strPath As String
    Dim strPrgName As String
    Dim strNewName As String
    Dim strNoExt As String
    Dim bolPassFail As Boolean
    Dim FindDot
    
    Set App = CreateObject ("PCDLRN.Application")
    Set Part = App.ActivePartProgram
        Set Serial = Part.GetVariableValue ("SER_NUM")
            strCrntName = Part.FullName
            strPath = Part.Path
            strPrgName = Part.Name
                FindDot = InStr(1, strPrgName, ".")
            strNoExt = Left(strPrgName, FindDot - 1)
            strNewName = strPath & "RESULTS\" & strNoExt & "_" & Serial.StringValue & ".prg"
    
    bolPassFail = Part.SaveAs (strNewName)
    bolPassFail = Part.SaveAs (strCrntName)
    
    End Sub


    The code here is an adaptation of code written and posted to this forum by vpt.se and Craiger_NY.
Children
No Data