hexagon logo

Updating the Serial Number field during a PCDMIS run; display updated value in report

This may be more useful to NC users than to anybody else, but here is a sample of code with which you can update the serial number field.

Problem: our parts are ALL serialized. So every time I run the part program, I ask for that serial number. But at that time, the header for my report file has already been generated. In NC, you do NOT have the luxury of being able to just redraw the report so it shows the updated field. It prints the old number. After a redraw, it will print the correct number, but that is not an option in NC.

Partial Solution: use an assigned variable and REPORT it in the report.

But I do not like that solution. I want the ACTUAL serial number field to be updated and shown, not some sort of variable. I want the File Header to show the latest.

Full solution: With the help of Hexagon tech support (Don Ruggieri produced the basic ideas and code), I was able to write the following script:


'This script takes the new serial number and makes it the latest active serial number. Refreshes report so it shows the latest.

Sub main(sn As String) 'bring sn in as ARG1 from PCDMIS

Dim App As Object 
Set App = CreateObject("PCDLRN.Application") 

Dim Part As Object 
Set Part = App.ActivePartProgram 

part.serialnumber=sn    'make the new control number, the serial number
part.refreshpart

part.save               ' save the part program so it has the latest serial number

Dim repwin As Object
Set repwin = part.reportwindow

repwin.refreshreport	'refresh report; now the report shows the latest serial number.

End Sub



In PC DMIS, put in the following (with variable NEWSN having the latest number):

CS1        =SCRIPT/FILENAME= C:\PCDMISW\CHANGESERNUMBER.BAS
            FUNCTION/Main,SHOW=YES,ARG1=NEWSN,,
            STARTSCRIPT/
            ENDSCRIPT/



This is simple and works great in my case.Sunglasses


Jan.
  • Where do you put the first code listed above?
  • I just use an input comment that prompts you to input the new serial number and that will be at the top of your printout. (If you have it set up to.) Seems to work well!
  • Sorry about resurrecting this thread, but I'm not able to get this to work.

    I have two different version of basic scripts. One where the serial number is passed to the script via parameter argument (as shown in this thread). Another where the script extracts the values as follows:
    Set Var = Part.GetVariableValue("SERIALNUM")

    Both programs as available from the forum have the following two statements:

    Set repwin = part.reportwindow
    repwin.refreshreport

    My version of PCDMIS 3.7 MR3 doesn't recognize 'reportwindow' or 'refreshreport'. My pcdbasic 3.6 ref manual doesn't list 'reportwindow' as a property of the partprogram object. Since 'reportwindow' object doesn't exist, it obviously doesn't have a method named 'refreshreport'.

    Without some way of refreshing the report the serial number doesn't show up until after the program finishes executing and the report with the wrong serial number is printed.

    Any ideas?
  • I am not 100% sure, but I think that this only works in V4.0 and later. I think that was something that Jared Hess wrote me at one point....

    Jan.
  • I am not 100% sure, but I think that this only works in V4.0 and later.


    I loaded a copy of PC-DMIS v4.0, opened an MS excel document, used the object browser to verify the above is correct. The object 'ReportWindow' is not available in pre 4.0 releases Disappointed.

    There must be some kind of event I can trigger to get the edit window in report mode to refresh.
  • I am not 100% sure, but I think that this only works in V4.0 and later. I think that was something that Jared Hess wrote me at one point....

    Jan.


    Correct. In v4.0 we put the report data in its own Report window (no longer in the Edit window), so the ReportWindow object was not available prior to v4.0. I'm not certain, but I think there might be an equivalent command to refresh the Edit Window after it's been modified...

    Well, this might work. Here's what I use whenever I add a new command to the Edit window by automation to refresh the EW so I can see the command:

    Dim Part As Object
    Set Part = App.ActivePartProgram
    Part.Refreshpart
    


    Good luck!
  • I tested Part.Refreshpart with Part.Save before and after. No change. For now the only work-around (in v3.7) is to input the new serial number, cancel and restart the program.
  • how to put variable instead of NEWSN......
    and its not taking fond like A569-5
    Neutral face

    This may be more useful to NC users than to anybody else, but here is a sample of code with which you can update the serial number field.

    Problem: our parts are ALL serialized. So every time I run the part program, I ask for that serial number. But at that time, the header for my report file has already been generated. In NC, you do NOT have the luxury of being able to just redraw the report so it shows the updated field. It prints the old number. After a redraw, it will print the correct number, but that is not an option in NC.

    Partial Solution: use an assigned variable and REPORT it in the report.

    But I do not like that solution. I want the ACTUAL serial number field to be updated and shown, not some sort of variable. I want the File Header to show the latest.

    Full solution: With the help of Hexagon tech support (Don Ruggieri produced the basic ideas and code), I was able to write the following script:


    'This script takes the new serial number and makes it the latest active serial number. Refreshes report so it shows the latest.
    
    Sub main(sn As String) 'bring sn in as ARG1 from PCDMIS
    
    Dim App As Object 
    Set App = CreateObject("PCDLRN.Application") 
    
    Dim Part As Object 
    Set Part = App.ActivePartProgram 
    
    part.serialnumber=sn    'make the new control number, the serial number
    part.refreshpart
    
    part.save               ' save the part program so it has the latest serial number
    
    Dim repwin As Object
    Set repwin = part.reportwindow
    
    repwin.refreshreport	'refresh report; now the report shows the latest serial number.
    
    End Sub
    
    


    In PC DMIS, put in the following (with variable NEWSN having the latest number):

    CS1        =SCRIPT/FILENAME= C:\PCDMISW\CHANGESERNUMBER.BAS
                FUNCTION/Main,SHOW=YES,ARG1=NEWSN,,
                STARTSCRIPT/
                ENDSCRIPT/



    This is simple and works great in my case.Sunglasses


    Jan.