hexagon logo

Need help with my script

First i hope you will excuse my programming skills. Its been 17 years since i learned programming in Java, so this code i made here is parts from other people's programs i put togther for this.

Most of my program work, and do what is was intended for.

My current problem is that when i try to make a string "PRINT_PATH" with information where to save my report.
Then it does not get used in my Print command part. Seems that the PRINT_PATH only have a "0" and not the prober path i made in my script.

Hope this make any sence Slight smile


LØBENR2 =COMMENT/INPUT,NO,'Løbenr.'
ORDRENR2 =COMMENT/INPUT,NO,'Ordrenr.'
ASSIGN/LØBENR1=STR(LØBENR2.INPUT)
ASSIGN/ORDRE1=ORDRENR2.INPUT
ASSIGN/EMNE1="7427270"
ASSIGN/REVISION1="2"
Test_samle =SCRIPT/FILENAME= M:\SCRIPT\SAMLESCRIPT.BAS
FUNCTION/Main,SHOW=YES,ARG1=REVISION1,ARG2=LØBENR1,ARG3=EMNE1,ARG4=ORDRE1,,
STARTSCRIPT/
C1000 =COMMENT/INPUT,NO,'Initialer'
ASSIGN/INI=C1000.INPUT
ASSIGN/PRINT_PATH="O:\QA\TEST\PRL05555\7427270_2_MP_5555-.PDF"
ENDSCRIPT/
$$ NO,***************************** Statestik *************************************************
STATS/OFF
TRACEFIELD/NO_DISPLAY,LIMIT=15 ; : EMNE1.INPUT
TRACEFIELD/NO_DISPLAY,LIMIT=15 ; : REVISION1.INPUT
TRACEFIELD/NO_DISPLAY,LIMIT=15 ; : STR(LØBENR1.INPUT)
TRACEFIELD/NO_DISPLAY,LIMIT=25 ; Ordre : ORDRENR2.INPUT
TRACEFIELD/NO_DISPLAY,LIMIT=15 ; PROCESS : CTP
TRACEFIELD/NO_DISPLAY,LIMIT=15 ; Initialer : STR(INI)
$$ NO,********************************** Sættes ind i ende af program ******************
PRINT/REPORT,EXEC MODE=END,$
TO_FILE=ON,AUTO=PRINT_PATH,$
TO_PRINTER=OFF,$
TO_DMIS_REPORT=OFF,FILE_OPTION=OVERWRITE,FILENAME=,$
REPORT_THEORETICALS=ALL,REPORT_FEATURE_WITH_DIMENSIONS=YES,$
PREVIOUS_RUNS=DELETE_INSTANCES

Sub main(REVISION1 As String, LØBENR1 As String, EMNE1 As String, ORDRE1 As String) 'bring newpn In As ARG1 from PCDMIS
Dim DmisApp As Object
Dim DmisPart As Object
Dim DmisCommands As Object
Dim DmisCommand As Object


Set DmisApp = CreateObject("PCDLRN.Application")
Set DmisPart = DmisApp.ActivePartProgram
Set DmisCommands = DmisPart.Commands
CommandCount = DmisCommands.Count
Set DmisCommand = DmisCommands.Item(CommandCount)
DmisCommands.InsertionPointAfter DmisCommand

Dim C1000
' Set C1000 = "" A Null String
C1000 = ""

Set DmisCommand = DmisCommands.Add(SET_COMMENT, True)
DmisCommand.Marked = True

retval = DmisCommand.PutText ("C1000", ID, 0)
retval = DmisCommand.SetToggleString (3, COMMENT_TYPE, 0)
retval = DmisCommand.PutText ("Initialer", COMMENT_FIELD, 1)
retval = DmisCommand.SetToggleString (1, OUTPUT_TYPE, 0)

Set DmisCommand = DmisCommands.Add(ASSIGNMENT, True)
DmisCommand.Marked = True
retval = DmisCommand.PutText ("INI", DEST_EXPR, 0)
retval = DmisCommand.PutText ("C1000.INPUT", SRC_EXPR, 0)

Dim PARTNAME2 As String
PARTNAME2 = EMNE1 + "_" + REVISION1 + "_MP_" + LØBENR1

Dim JOB_PATH As String
JOB_PATH = "O:\QA\TEST"
Dim REPORT_PATH1 As String
REPORT_PATH1 = JOB_PATH + "" + ORDRE1
Dim REPORT_PATH2 As String
REPORT_PATH2 = REPORT_PATH1 + ""
Dim REPORT_NAME As String
REPORT_NAME = PARTNAME2 + "-"
Dim PRINT_PATH1
PRINT_PATH1 = """" + REPORT_PATH2 + REPORT_NAME + ".PDF" + """"

Set DmisCommand = DmisCommands.Add(ASSIGNMENT, True)
DmisCommand.Marked = True

retval = DmisCommand.PutText ("PRINT_PATH", DEST_EXPR, 0)
retval = DmisCommand.PutText (PRINT_PATH1, SRC_EXPR, 0)

DmisPart.PARTNAME=PARTNAME2 'make the new control number, the part number
DmisPart.SERIALNUMBER=LØBENR1
DmisPart.REVISIONNUMBER=REVISION1
DmisPart.statscount=PROCESS1
DmisPart.refreshpart
DmisPart.save ' save the part program so it has the latest part number
Dim repwin As Object
Set repwin = DmisPart.reportwindow
repwin.refreshreport 'refresh report; now the report shows the latest part number.

On Error Resume Next
MkDir REPORT_PATH1

End Sub
  • After some trial and error, i got to work.
    It was not the string with path i made.
    The problem was somewhere in the print command. I played around with some of the file options APPEND, owerwrite and Auto.
    Sudenly i got it to work, can't explain what i made different, but it startet to use the variable i used in it, and not some old variable i could not see anymore.

    Maybe the problem is that we use PC dmis 4.3. and maybe there is a glitch somewhere in the print command.
  • Maybe the problem is that we use PC dmis 4.3. and maybe there is a glitch somewhere in the print command.


    Might be time for an upgrade there....

  • Ok need a little more help with my script. I managed to piece my script together from 3 other scripts and it almost work as i would like Slight smile

    The purpose of the script is to handle manual input from operator. Define save path for a PDF report and its name. Header of our report.

    My problem is that i make a small message window where operator should write his initials. I would like to add a loop that go back if the operator not write anyting.

    I can't get the loop to work, allways get an error. anyone that can help me with that ?

    Script:

    Sub main(REVISION1 As String, LØBENR1 As String, EMNE1 As String, ORDRE1 As String) 'Dim DmisApp As Object
    Dim DmisPart As Object
    Dim DmisCommands As Object
    Dim DmisCommand As Object
    
    
      Set DmisApp = CreateObject("PCDLRN.Application")
      Set DmisPart = DmisApp.ActivePartProgram
      Set DmisCommands = DmisPart.Commands
      CommandCount = DmisCommands.Count
      Set DmisCommand = DmisCommands.Item(CommandCount)
      DmisCommands.InsertionPointAfter DmisCommand
    
    Dim C1000
      C1000 = ""
    
      Set DmisCommand = DmisCommands.Add(SET_COMMENT, True)
        DmisCommand.Marked = True
    
        retval = DmisCommand.PutText ("C1000", ID, 0)
         retval = DmisCommand.SetToggleString (3, COMMENT_TYPE, 0)
        retval = DmisCommand.PutText ("Initialer", COMMENT_FIELD, 1)
         retval = DmisCommand.SetToggleString (1, OUTPUT_TYPE, 0)
    
      Set DmisCommand = DmisCommands.Add(ASSIGNMENT, True)
        DmisCommand.Marked = True
         retval = DmisCommand.PutText ("INI", DEST_EXPR, 0)
         retval = DmisCommand.PutText ("C1000.INPUT", SRC_EXPR, 0)
    
    Dim PARTNAME2 As String
     PARTNAME2 = EMNE1 + "_" + REVISION1 + "_MP_" + LØBENR1
    
    Dim JOB_PATH As String
     JOB_PATH = "O:\\QA\\TEST"
    Dim REPORT_PATH1 As String
     REPORT_PATH1 = JOB_PATH + "\\" + ORDRE1
    Dim REPORT_PATH2 As String
     REPORT_PATH2 = REPORT_PATH1 + "\\"
    Dim REPORT_NAME As String
     REPORT_NAME = PARTNAME2 + "-"
    Dim PRINT_PATH1
     PRINT_PATH1 = """" + REPORT_PATH2 + REPORT_NAME + ".PDF" + """"
    
         Set DmisCommand = DmisCommands.Add(ASSIGNMENT, True)
         DmisCommand.Marked = True
    
         retval = DmisCommand.PutText ("PRINT_PATH", DEST_EXPR, 0)
         retval = DmisCommand.PutText (PRINT_PATH1, SRC_EXPR, 0) 
    
    DmisPart.PARTNAME=PARTNAME2    'make the new control number, the part number
    DmisPart.SERIALNUMBER=LØBENR1
    DmisPart.REVISIONNUMBER=REVISION1
    DmisPart.statscount=PROCESS1
    DmisPart.refreshpart 
    DmisPart.save               ' save the part program so it has the latest part number
    Dim repwin As Object
    Set repwin = DmisPart.reportwindow
    repwin.refreshreport 'refresh report; now the report shows the latest part number.
    
    On Error Resume Next
        MkDir REPORT_PATH1
    
    End Sub


    Test program:
    LØBENR2    =COMMENT/INPUT,NO,'Løbenr.'
    ORDRENR2   =COMMENT/INPUT,NO,'Ordrenr.'
                ASSIGN/LØBENR1=STR(LØBENR2.INPUT)
                ASSIGN/ORDRE1=ORDRENR2.INPUT
                ASSIGN/EMNE1="7427270"
                ASSIGN/REVISION1="2"
    Test_samle =SCRIPT/FILENAME= M:\SCRIPT\SAMLESCRIPT.BAS
                FUNCTION/Main,SHOW=YES,ARG1=REVISION1,ARG2=LØBENR1,ARG3=EMNE1,ARG4=ORDRE1,,
                STARTSCRIPT/
    C1000      =COMMENT/INPUT,NO,Initialer
                ASSIGN/INI=C1000.INPUT
                ASSIGN/PRINT_PATH="O:\\QA\\TEST\\PRL02222\\7427270_2_MP_2222-.PDF"
    $$ NO,***************************** Statestik *************************************************
                STATS/OFF
                TRACEFIELD/NO_DISPLAY,LIMIT=15 ;  : EMNE1.INPUT
                TRACEFIELD/NO_DISPLAY,LIMIT=15 ;  : REVISION1.INPUT
                TRACEFIELD/NO_DISPLAY,LIMIT=15 ;  : STR(LØBENR1.INPUT)
                TRACEFIELD/NO_DISPLAY,LIMIT=25 ; Ordre : ORDRENR2.INPUT
                TRACEFIELD/NO_DISPLAY,LIMIT=15 ; PROCESS : CTP
                TRACEFIELD/NO_DISPLAY,LIMIT=15 ; Initialer : STR(INI)
    $$ NO,********************************** Sættes ind i ende af program ******************
                PRINT/REPORT,EXEC MODE=END,$
                  TO_FILE=ON,AUTO=PRINT_PATH,$
                  TO_PRINTER=OFF,$
                  TO_DMIS_REPORT=OFF,FILE_OPTION=OVERWRITE,FILENAME=,$
                  REPORT_THEORETICALS=ALL,REPORT_FEATURE_WITH_DIMENSIONS=YES,$
                  PREVIOUS_RUNS=DELETE_INSTANCES
  • Use a label directly above C1000. Then do a contentcheck for INI or C1000.INPUT and if the content is empty, have the program return to the label until it passes the contentcheck.
  • I tried with different kinds of loops. Most of the time i get the error that name must be uniqe.

    Now i tried this "if" statement, but it does not seems to work. My content check does not work.

    Anyone can help`?

    Label1:
    
    Dim C1000
     'Set C1000 = ""          A Null String 
        C1000 = ""
    
      Set DmisCommand = DmisCommands.Add(SET_COMMENT, True)
        DmisCommand.Marked = True
    
        retval = DmisCommand.PutText ("C1000", ID, 0)
         retval = DmisCommand.SetToggleString (3, COMMENT_TYPE, 0)
        retval = DmisCommand.PutText ("Initialer", COMMENT_FIELD, 1)
         retval = DmisCommand.SetToggleString (1, OUTPUT_TYPE, 0)
    
      Set DmisCommand = DmisCommands.Add(ASSIGNMENT, True)
        DmisCommand.Marked = True
         retval = DmisCommand.PutText ("INI", DEST_EXPR, 0)
         retval = DmisCommand.PutText ("C1000.INPUT", SRC_EXPR, 0)
    
    If DmisCommand.GetText(SRC_EXPR,0)  = "" Then 
      MessageBox.Show("HALLO")  ' test to see if i get inside statement
      GoTo  Label1
    End If
    
  • ?? You add two commands to your PC-DMIS program, then you read what you added in the second command, what are you expecting?

    The commands are not executed just by adding them (as far as I know), and the above is not the correct way to test user input (which probably hasn't had a chance to be given yet). What vpt meant above was to produce PC-DMIS code like below, and execute it.

    L_C1000    =LABEL/
    C1000      =COMMENT/INPUT,NO,FULL SCREEN=NO,
                Enter your value:
                IF/C1000.INPUT == ""
                GOTO/L_C1000
                END_IF/
    


    But beware! It seems PC-DMIS evaluates the empty string to 0, so the above doesn't work, at least not in 2017 R2 SP3. I need to change the IF to

                IF/C1000.INPUT == "0"
    


    to make it work. This will make it impossible to use this code to input the value 0!
  • I am sorry if my questions dont make sense. I don't have any experience in programming VB, only in Java i learned 15 years ago.

    I try to make a script that can handle several things, because its easier to add call to a script in many programs and then later make changes in that script to affect all programs and not need to enter every program to change things.

    In my script i made a window where operator need to input his Initials, and if he forgets to do that then window opens again.

    This is the where i make the window in the script.

    Dim C1000
     'Set C1000 = ""          A Null String 
        C1000 = ""
    
      Set DmisCommand = DmisCommands.Add(SET_COMMENT, True)
        DmisCommand.Marked = True
    
        retval = DmisCommand.PutText ("C1000", ID, 0)
         retval = DmisCommand.SetToggleString (3, COMMENT_TYPE, 0)
        retval = DmisCommand.PutText ("Initialer", COMMENT_FIELD, 1)
         retval = DmisCommand.SetToggleString (1, OUTPUT_TYPE, 0)
    
      Set DmisCommand = DmisCommands.Add(ASSIGNMENT, True)
        DmisCommand.Marked = True
         retval = DmisCommand.PutText ("INI", DEST_EXPR, 0)
         retval = DmisCommand.PutText ("C1000.INPUT", SRC_EXPR, 0)
    


    Now i need help make that check in the script to reopen window if intials(c1000) is empty.

    I am not sure exacatly what i am doing and have tried several things, but nothing works for me.

  • If you absolutely must generate PC-DMIS code, then generate the ones I showed and it should work. It works when running in plain PC-DMIS, without using a script to generate the commands.

    If you write it in PC-DMIS code first, you can save that as Basic and see how it should be done from a script (maybe, not everything works when saved as Basic...).
  • It worked, thanks for the help Slight smile

    As i said i have no experience with this and i can see i need to change the way i look at things.
  • Well, what your script is doing is adding an inputbox to your PC-DMIS program. This window will show every time you run the program, even if you delete the SCRIPT above.

    It sounds like you are looking to CALL the script and have the script show the inputbox and the handling of the input. The code you have ADDS the inputbox to your program.