Tapatalk

How to modify a file on load with user input and replaces using a macro?

How to modify a file on load with user input and replaces using a macro?

2
NewbieNewbie
2

    Nov 25, 2015#1

    So I have multiple files that I need to run the same process on. I was thinking about making a macro that runs as you open these files.

    Here is what I need to do & below is an example file:
    1. I need to delete any feed rate commands that come after lines that end with (T_LEFT) or (T_RIGHT). Here is a couple examples. I need to delete what is in red. The numbers after the "F" change

      N140TC_LASERCORR_ON(T_LEFT); 1
      N150G01X1.6269F110; 1

      N360TC_LASERCORR_ON(T_RIGHT); 3
      N370G01X1.7216Y5.0398F180; 3

      These lines will look like this after:

      N140TC_LASERCORR_ON(T_LEFT); 1
      N150G01X1.6269; 1

      N360TC_LASERCORR_ON(T_RIGHT); 3
      N370G01X1.7216Y5.0398; 3
    2. In the area that is shown below, I need to do a couple things:
      1. First, I need to prompt the user to replace the text "PROGRAM NUMBER" with the customers name. I'd like to do this with a dialog box with user input if possible.
      2. Also, I would like to add a line between N10; & N20; that looks like this N15; (xxxxxxxxxxxxxxxxxx)
        The xxxxxxxxxxxxxxx would be filled in with another user prompt that asks for the part number and revision level.
      3. Lastly, I would like to add a material description user prompt where they can say what kind of material it is.

        So this is what the starting product looks like before the macro.

        START_TEXT
        N10; ("PROGRAM NUMBER: LLL")
        N20; (THICKNESS : .104)
        N30; (BLANK SIZE : 96. X 48.)
        N40; (YIELD PER BLANK : 1 PART)
        N50; (ESTIMATED TIME : 0 MIN. 11 SEC.)

        This is what it looks like after the macro with the user inputs (ADDITIONS IN GREEN):

        START_TEXT
        N10; ("MICROSOFT: LLL")
        N15; (1234567 LVL 1)
        N20; (THICKNESS : .104 STAINLESS)
        N30; (BLANK SIZE : 96. X 48.)
        N40; (YIELD PER BLANK : 1 PART)
        N50; (ESTIMATED TIME : 0 MIN. 11 SEC.)

    Code: Select all

    BD
    SET_INCH
    C
    BEGIN_EINRICHTEPLAN_INFO
    C
    ZA,MM,18
    MM,AT,1,  10,1,1,,'Machine'                          ,,'',T
    MM,AT,1,  20,1,1,,'Type'                             ,,'',Z
    MM,AT,1,  30,1,1,,'Control'                          ,,'',T
    MM,AT,1,  40,1,1,,'Variant'                          ,,'',Z
    MM,AT,1,  50,1,1,,'Company'                          ,,'',T
    MM,AT,1,  60,1,1,,'Program number (without P!)'      ,,'',T
    MM,AT,1,  70,1,1,,'Programmer'                       ,,'',T
    MM,AT,1,  80,1,1,,'Date'                             ,,'',T
    MM,AT,1,  90,1,1,,'Job Name'                         ,,'',T
    MM,AT,1, 100,1,1,,'Number of Program Runs'           ,,'',Z
    MM,AT,1, 110,1,1,,'Sheet Name'                       ,,'',T
    MM,AT,1, 120,1,1,,'Memory Requirement'               ,,'',Z
    MM,AT,1, 130,1,1,,'Material-ID'                      ,,'',T
    MM,AT,1, 140,1,1,,'Sheet Weight'                     ,,'lbs',Z
    MM,AT,1, 150,1,1,,'Machining Time'                   ,,'min',Z
    MM,AT,1, 160,1,1,,'Remark'                           ,,'',T
    MM,AT,1, 170,1,1,,'Flag Automated'                   ,,'Bool',Z
    MM,AT,1, 180,1,1,,'Reserved'                         ,,'Bool',Z
    C
    ZA,DA,1
    DA,'Trumpf Laser',1,'Sin 840D',1,
    *   ' LLL',
    *   'LLL',
    *   ' LLL',
    *   '11.25.2015',' ',0,
    *   'C:\FabriWIN_2\NCFiles\fabriwin.nc',
    *   ,' LLL',
    *    61.6,,'',0,1
    C
    ENDE_EINRICHTEPLAN_INFO
    C
    BEGIN_SHEET_TECH
    C
    ZA,MM,7
    MM,AT,1,  10,1,1,,'Table Identifier'                 ,,'',T
    MM,AT,1,  20,1,1,,'Sheet Dimension X'                ,,'in',Z
    MM,AT,1,  30,1,1,,'Sheet Dimension Y'                ,,'in',Z
    MM,AT,1,  40,1,1,,'Sheet Thickness'                  ,,'in',Z
    MM,AT,1, 200,1,1,,'TRUMPF-ID'                        ,,'',Z
    MM,AT,1, 220,1,1,,'Sheet Dimension X real'           ,,'in',Z
    MM,AT,1, 230,1,1,,'Sheet Dimension Y real'           ,,'in',Z
    C
    ZA,DA,1
    DA,'SHT-1',96.,48.,.104,1,96.,48.
    C
    ENDE_SHEET_TECH
    C
    BEGIN_SHEET_LOAD
    C
    ZA,MM,16
    MM,AT,1,  10,1,1,,'Table Identifier'                 ,,'',T
    MM,AT,1,  70,1,1,,'Trumpf-ID'                        ,,'',Z
    MM,AT,1, 500,1,1,,'Loading Device'                   ,,'',Z
    MM,AT,1, 520,1,1,,'Suction Cup Group 1'              ,,'',Z
    MM,AT,1, 530,1,1,,'Suction Cup Group 2'              ,,'',Z
    MM,AT,1, 540,1,1,,'Suction Cup Group 3'              ,,'',Z
    MM,AT,1, 550,1,1,,'Suction Cup Group 4'              ,,'',Z
    MM,AT,1, 580,1,1,,'Double Sheet Detector'              ,,'Bool',Z
    MM,AT,1, 590,1,1,,'Peel Off'                           ,,'Bool',Z
    MM,AT,1, 620,1,1,,'Sheet Stop'                       ,,'',Z
    MM,AT,1, 630,1,1,,'Measure Sheet Position'           ,,'',Z
    MM,AT,1, 640,1,1,,'Measurement Range X'              ,,'in',Z
    MM,AT,1, 650,1,1,,'Measurement Range Y'              ,,'in',Z
    MM,AT,1, 660,1,1,,'Calibration'                      ,,'Bool',Z
    MM,AT,1, 690,1,1,,'Pallet Change Type'               ,,'',Z
    MM,AT,1, 700,1,1,,'Measuring Corner'               ,,'',Z
    C
    ZA,DA,1
    DA,'SHL-1',1,1,0,0,0,0,0,0,1,0,0,0,1,1,1
    C
    ENDE_SHEET_LOAD
    C
    BEGIN_LTT_CALLS
    C
    ZA,MM,1
    MM,AT,1,  10,1,1,,'Table Identifier'                 ,,'',T
    C
    ZA,DA,1
    DA,'11017'
    C
    ENDE_LTT_CALLS
    C
    BEGIN_PROGRAMM
    C
    ZA,MM,4
    MM,AT,1,  10,1,1,,'Program number'                   ,,'',T
    MM,AT,1,  20,1,1,,'Program type'                     ,,'',T
    MM,AT,1,  30,1,1,,'Remark'                           ,,'',T
    MM,AT,1,  40,1,1,,'Processing time'                  ,,'min',Z
    C
    ZA,DA,1
    DA,'LLL','HP','',
    START_TEXT
    N10; ("PROGRAM NUMBER: LLL")
    N20; (THICKNESS       : .104)
    N30; (BLANK SIZE      : 96. X 48.)
    N40; (YIELD PER BLANK : 1 PART)
    N50; (ESTIMATED TIME  : 0 MIN. 11 SEC.)
    N60G70
    N70F3300
    N80TC_POS_LEVEL(2.)
    N90TC_SHEET_TECH("SHT-1")
    N100TC_SHEET_LOAD("SHL-1")
    N110; GOTOF ENTRY_LASER
    N120G00X1.7104Y1.6446; 1
    N130TC_LASER_ON(1,"11017",10,200); 1
    N140TC_LASERCORR_ON(T_LEFT); 1
    N150G01X1.6269F110; 1
    N160Y1.3866; 1
    N170X1.7939; 1
    N180Y1.9026; 1
    N190X1.6269; 1
    N200Y1.6446; 1
    N210X1.7104; 1
    N220TC_LASER_OFF(2); 1
    N230;ENTRY_LASER:
    N240;( CUT 2 )
    N250G00X1.555Y4.8787; 2
    N260TC_LASER_ON(1,"11017",10,200); 2
    N270TC_LASERCORR_ON(T_LEFT); 2
    N280G01Y4.7462; 2
    N290G03J.1325; 2
    N300G01Y4.8712; 2
    N310TC_LASER_OFF(2); 2
    N320;ENTRY_LASER:
    N330;( CUT 3 )
    N340G00X1.9001Y5.1685; 3
    N350TC_LASER_ON(1,"11017",10,100); 3
    N360TC_LASERCORR_ON(T_RIGHT); 3
    N370G01X1.7216Y5.0398F180; 3
    N380X1.5738Y5.2447; 3
    N390G03X1.4039Y5.2762I-.1014J-.0731; 3
    N400G02X.6551Y5.1325I-.549J.8382; 3
    N410G03X.57Y5.1196I-.0249J-.1225; 3
    N420G01X.1324Y4.8791; 3
    N430G03X.1712Y4.7624I.0301J-.0548; 3
    N440G01X.77Y4.8466; 3
    N450G02X.9286Y4.7345I.0197J-.1403; 3
    N460G02X.8098Y4.5846I-.1387J-.0121; 3
    N470G01X.2269Y4.5027; 3
    N480G03X.1776Y4.4175I.0087J-.0619; 3
    N490G02X.3119Y4.0775I-31.1753J-12.5131; 3
    N500G03X.3277Y4.0676I.0146J.0057; 3
    N510G02X.411Y3.8303I.0105J-.1296; 3
    N520G03X.4051Y3.8118I.0087J-.0129; 3
    N530G02X1.0434Y.7298I-9.358J-3.5452; 3
    N540G03X1.0746Y.7I.0312J.0014; 3
    N550G01X1.2425; 3
    N560Y.1625; 3
    N570G03X1.305Y.1I.0625; 3
    N580G01X1.7596; 3
    N590G03X1.7909Y.1312J.0313; 3
    N600G01Y.5488; 3
    N610G02X1.8221Y.58I.0313; 3
    N620G01X2.2021; 3
    N630G03X2.2334Y.6112J.0313; 3
    N640G01Y.7; 3
    N650X2.3979; 3
    N660G03X2.4286Y.7371J.0313; 3
    N670G02X1.9662Y4.0017I33.152J6.3608; 3
    N680G03X1.9513Y4.0159I-.0156J-.0014; 3
    N690G02X1.9232Y4.2713I.0057J.1299; 3
    N700G03X1.9347Y4.2881I-.0041J.0151; 3
    N710G02X1.881Y4.8043I33.0802J3.7021; 3
    N720G03X1.8695Y4.8349I-.0622J-.006; 3
    N730G01X1.7421Y5.0114; 3
    N740TC_LASER_OFF(2); 3
    N750G00
    N760M30
    STOP_TEXT
    ENDE_PROGRAMM
    ED
    

    6,685587
    Grand MasterGrand Master
    6,685587

      Nov 25, 2015#2

      The task was described excellent and therefore it was easy to code the macro for you. Here is the macro code:

      Code: Select all

      InsertMode
      ColumnModeOff
      HexOff
      Top
      UltraEditReOn
      Find MatchCase RegExp "^((T_^{LEFT^}^{RIGHT^});*^p*^)F[0-9]+;"
      Replace All "^1;"
      Find MatchCase "PROGRAM NUMBER"
      IfFound
      GetString "Please enter customer name:"
      EndIf
      Find MatchCase RegExp "%N20"
      IfFound
      Key HOME
      "N15; ("
      GetString "Please enter part number and revision level:"
      ")
      "
      Find MatchCase ")"
      IfFound
      Key LEFT ARROW
      " "
      GetString "Please enter material description:"
      
      I explain the UltraEdit regular expression Replace All using a tagged regular expression as this is most likely the only part difficult to understand for you.

      The search string is: ^((T_^{LEFT^}^{RIGHT^});*^p*^)F[0-9]+;

      ^(...^) ... tags the string found by the expression inside for re-use during each replace referenced by ^1. This is done to keep the text searched for finding the right Fxxx strings unmodified.

      ^{...^}^{...^} ... is an OR expression in UltraEdit syntax.

      * ... any character except newline characters 0 or more times. On first occurrence in search string the asterisk matches everything up to end of line containing either (T_LEFT) or (T_RIGHT).

      ^p ... DOS/Windows line termination, i.e. carriage return and line-feed.

      * ... on next line match 0 or more characters except newline characters up to last F followed by a number. So * in UltraEdit syntax is greedy. It does not stop matching on first occurrence of Fxxx, it stops left to last occurrence of Fxxx.

      By the way: Non-greedy would be the expression ?++ instead of *.

      [0-9]+ ... a digit 1 or more times.

      All other characters in search expression are interpreted literally which means must be found in file.

      And %N20 means find string N20 at beginning of a line in UltraEdit regular expression syntax.

      You can enclose the entire code in IfExtIs "EXT" (first line of macro code) and EndIf (last line of macro code) to let this macro code run only on files with file extension EXT (case-insensitive).

      And perhaps you want to replace

      Code: Select all

      Find MatchCase "PROGRAM NUMBER"
      IfFound
      GetString "Please enter customer name:"
      EndIf
      by

      Code: Select all

      Find MatchCase "PROGRAM NUMBER"
      IfNotFound
      ExitMacro
      EndIf
      for not prompting the user for any input if a file was opened which contains already a customer name (and part number, revision level and material description) and therefore PROGRAM NUMBER does not exist anymore in file.

      The UltraEdit regular expression Find and Replace All can be also moved to end of macro code if you first want to check for PROGRAM NUMBER.
      Best regards from an UC/UE/UES for Windows user from Austria

      2
      NewbieNewbie
      2

        Dec 01, 2015#3

        Worked like a charm. Next time your near Detroit, I owe you a drink. Thanks also for the lesson, very helpful. :D