hexagon logo

SaveAs2 Function

There is a function available in the object library called "SaveAs2" which is supposed to allow you to save the part program with CAD as reference. I can't seem to get this to work. It saves the part program just fine but it also saves the CAD no matter what value I pass in the second argument. Has anyone else had any luck with this?

Function SaveAs2(Name As String, CadAsReference As Boolean) As Boolean
Member of PCDLRN.PartProgram
Saves the part program with the provided name. CadAsReference allows to save the CAD as reference to the original one
  • I've never used Imoprt>CAD By Reference before, but I assumed when you imported by reference the it would be a link to the original .CAD file, instead of a copy of it.


    I'd therefore assume this function does the same (except with saving). The CadAsReference argument is boolean so has to be true or false, I'm guessing if you do True, the .CAD file will be very small and simply act as a link to the original.

    Does that make sense?
  • It makes sense, and is what I expected, but that isn't what it does. I have tried passing True, False, -1,0. All give me the same result which is a saved copy of both .PRG and full sized .CAD.
  • Does the function always return true? Was the model originally imported byref?
  • Does the function always return true? Was the model originally imported byref?

    Have just tried this and .cad file is 1Kb.

    Works for me, what version are you running?
  • Can you post the code of how you passed the value to get it to work?

    I'm using 2013MR1 SP5. This script runs at the end of the program as the last action. I've added the Kill line to delete the CAD since I wasn't able to get the byref to work. It sounds like this might actually work better since I don't want the 1kb CAD file either. I just want no CAD file. Still curious why I couldn't get it to work.

    Dim App As Object
    Dim Part As Object
    Dim Cmds As Object
    Dim Cmd As Object
    
    '======================================================================================================================='------------------------------------------------
    
    'This Sub Initializes PC-DMIS
    'Change History:
    'A (JS,8/24/14) : Code from A. Mavrov from PC-DMIS forum
    '
    '
    '
    '------------------------------------------------
    Sub Initialize()
    
    Set App = CreateObject("PCDLRN.Application")
        If App Is Nothing Then
            MsgBox "PC-DMIS initialization error!",48, "Error!"
            Exit Sub
        Else
            Set Part = App.ActivePartProgram
            If Part Is Nothing Then
                MsgBox "Part Program not opened!", 48, "Error!"
                Exit Sub
            Else
                Set Cmds = Part.Commands
                If Cmds Is Nothing Then
                    MsgBox "Pointer to commands not valid!", 48, "Error!"
                    Exit Sub
                End If
            End If
        End If
    
    End Sub
    
    '======================================================================================================================='------------------------------------------------
    
    'This Sub Saves the Active Part Program To the Name And Path Passed. CAD is Deleted.
    'Change History:
    'A (JS,9/01/14) : Creation
    '
    '
    '
    '------------------------------------------------
    Sub PCDSaveAs(Path As String)
    
    Dim Bln As Boolean
    
    Bln = Part.SaveAs2(Path,True)
    
    Kill Path & ".CAD" 
    
    End Sub
    
    
    '======================================================================================================================='------------------------------------------------
    
    'This Sub Saves the Active Part Program To the Name And Path Passed in from PC-DMIS. CAD is deleted.
    'Change History:
    'A (JS,9/01/14) : Creation
    '
    '------------------------------------------------
    Sub Main(Path As String)
    
    Call Initialize()
    Call PCDSaveAs(Path)
    
    'Cleanup
    Set Cmd = Nothing
    Set Cmds = Nothing
    Set Part = Nothing
    Set App = Nothing
    
    End Sub
  • I didn't call it as a function, i.e without it returning a value.

    Part.saveas2 path, true



    My script for auto archiving programs actually just saves the program, then I just copy to a different location therefore I don't get the.cad
  • sorry to be late to this discussion. I just recently learned this is a known issue, being corrected as we speak. I suspect there is nothing wrong with your code.