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.
  • Josh,
    Here is what I need, and I would guess many others as well:

    - Execute program

    - Prompt the operator to input the serial number.
    This could be an input comment, as I currently use, a tracefield, or something else altogether. The point is that it is something that pops up on the screen right in your face and forces you to input the serial number before you can continue.

    - Program finishes

    - Automatically save the program to a user defined path with the serial number appended to the file name. There should be an option to save CAD as reference. The path, append options, and CAD as reference could be set in a configuration file as is used for PCD2XL.

    That's all.

    As for PCD2XL, please add in the ability to export comments and tracefields so we are not limited to only the fields built in to the file header. You could just have an input box in the configuration file were you could type in variable names, tracefield IDs, or comment ID's that would then be exported along with everything else.

    The current function of the file header is crazy. There is no way that any serious production operation would be content to simply trust that the operator will remember to change the serial number in the file header before hitting play. This type of critical ID information that is absolutely necessary for traceability MUST have an option for an entry method that forces the operator to enter it before they can continue the program.
  • ...there are users that don't give a ***** about the serialnumber as well, so don't enforce it to be entered each and every time a program is executed.
  • ...there are users that don't give a ***** about the serialnumber as well, so don't enforce it to be entered each and every time a program is executed.


    Agreed. Any function like this must be an option. Just as there is now an option to add a print report command that can append an incremental number or string depending on how you set it up. I am simply recommending a Save-as command that could be added the same way. An input comment works just fine for inputing the serial number. My only point is that anything like this that gets added should not be designed so that it will only be able to use a serial number input from the file header. It must be flexible enough to allow for referencing variables and tracefields. PCD2XL currently does not have this flexibility and it is a real pain for us. Operators forget to put the serial number in the header, then we get multiple excel sheets with the same serial number on them and need to go back through the program run log to figure out which part was run when and assign the correct serial number to it. For industires that do require 100% traceability of critical parts (aerospace, Powergen, etc.) this is a big problem.
  • Josh, I don't want to see an "auto-save-as" feature that can't be toggled off.


    dph51,
    Of course it should be toggled on/off. It should also never occur during other operations (the auto-save flaw of 2009 & 2010 versions).

    FYI, 2011 MR1's document recovery works like this: each time you save it also creates a backup copy too so if you lose the original you can recover from your last save point.
  • Josh,
    Here is what I need, and I would guess many others as well:

    - Execute program

    - Prompt the operator to input the serial number.
    This could be an input comment, as I currently use, a tracefield, or something else altogether. The point is that it is something that pops up on the screen right in your face and forces you to input the serial number before you can continue.

    - Program finishes

    - Automatically save the program to a user defined path with the serial number appended to the file name. There should be an option to save CAD as reference. The path, append options, and CAD as reference could be set in a configuration file as is used for PCD2XL.

    That's all.


    What you are asking for is exactly how I think it should work too. It's also pretty close to how we've got the script working, minus the CAD-as-ref.
    I am going to put in an Enhancement Request for this.


    As for PCD2XL, please add in the ability to export comments and tracefields so we are not limited to only the fields built in to the file header. You could just have an input box in the configuration file were you could type in variable names, tracefield IDs, or comment ID's that would then be exported along with everything else.

    The current function of the file header is crazy. There is no way that any serious production operation would be content to simply trust that the operator will remember to change the serial number in the file header before hitting play. This type of critical ID information that is absolutely necessary for traceability MUST have an option for an entry method that forces the operator to enter it before they can continue the program.


    I agree about the file header. I don't use it or recommend it. #1 as you point out it's daft for operator-functionality, and #2 it is a known bug that the tracefields that can populate it during program execution always lag one execution behind because the header is written before they run.

    For the PCD2XL we'll save that for another thread.
  • This script is great! Thanks DeSalo and everyone else that worked on it!
  • excellent, thanks, I will make good use of this...
  • #2 it is a known bug that the tracefields that can populate it during program execution always lag one execution behind because the header is written before they run.


    I use a script that refreshes the report at the end of the program. This allows the header to be updated with my tracefield values from the current execution.
  • As for PCD2XL, please add in the ability to export comments and tracefields so we are not limited to only the fields built in to the file header. You could just have an input box in the configuration file were you could type in variable names, tracefield IDs, or comment ID's that would then be exported along with everything else.



    You can export Tracefields...

    Tick the Use Stat/ON Stat/OFF option (or similar), then tick Use Tracefield, then untick Use Stat/ON Stat/OFF.