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
  • There is one minor annoyance with this script that seems to be caused by the new auto-backup feature introduced in 2011 MR1. I get the following error after the script executes:

    Everything still works as intended, you just need to click OK on this error dialogue box. Anyone have a simple solution for making that go away? I would prefer not to turn the function off as I do find it useful most of the time.

    Also, I don't full understand why the .saveas method requires the "Boolean =" syntax. It works this way, and doesn't work without it, so obviously it is supposed to be like that but I don't quite get the logic behind it. I couldn't find any documentation of this method in PC-DMIS. Does anyone have any deeper information about how this works and any pointers on where to look stuff like this up in the future?

    Finally, what is the easiest way to make a script like this into an executable? I assume I need to write it in a different environment that is intended for that purpose. Any recommendations on something that is both simple and, ideally, free? Can the visual basic editor in the Excel or Word compile as an .exe?
Reply
  • There is one minor annoyance with this script that seems to be caused by the new auto-backup feature introduced in 2011 MR1. I get the following error after the script executes:

    Everything still works as intended, you just need to click OK on this error dialogue box. Anyone have a simple solution for making that go away? I would prefer not to turn the function off as I do find it useful most of the time.

    Also, I don't full understand why the .saveas method requires the "Boolean =" syntax. It works this way, and doesn't work without it, so obviously it is supposed to be like that but I don't quite get the logic behind it. I couldn't find any documentation of this method in PC-DMIS. Does anyone have any deeper information about how this works and any pointers on where to look stuff like this up in the future?

    Finally, what is the easiest way to make a script like this into an executable? I assume I need to write it in a different environment that is intended for that purpose. Any recommendations on something that is both simple and, ideally, free? Can the visual basic editor in the Excel or Word compile as an .exe?
Children
No Data