Skip to content

Instantly share code, notes, and snippets.

@kevinfu2
Created March 29, 2017 02:54
Show Gist options
  • Save kevinfu2/6ecdccf21a8bb47baf5d20b2e1e83448 to your computer and use it in GitHub Desktop.
Save kevinfu2/6ecdccf21a8bb47baf5d20b2e1e83448 to your computer and use it in GitHub Desktop.

Revisions

  1. @Unain Unain created this gist Mar 29, 2017.
    146 changes: 146 additions & 0 deletions customize_p.m
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,146 @@
    DEFINE Atms_extract_basename
    PARAMETER Input_path
    PARAMETER Remove_extension

    LOCAL Input_strlen
    LOCAL Slash_posn
    LOCAL Dot_posn
    LOCAL Substring
    LOCAL Path_sep
    LOCAL Strlen
    LOCAL Basename

    { The direction of the slash can vary depending on how file was loaded }
    { Set the path separator based on which is found in the string. }
    IF (POS Input_path '\')
    LET Path_sep '\'
    ELSE
    LET Path_sep '/'
    END_IF

    {Extract the base name from the full path}
    LET Input_strlen (LEN Input_path)
    LET Slash_posn (POS Input_path Path_sep)
    LET Substring Input_path
    LET Strlen (LEN Substring)
    LOOP
    IF (Slash_posn<>0)
    LET Substring (SUBSTR Substring (Slash_posn + 1) (Strlen - 1))
    LET Strlen (LEN Substring)
    LET Slash_posn (POS Substring Path_sep)
    LET Basename Substring
    ELSE
    LET Basename Substring
    END_IF
    EXIT_IF (Slash_posn=0)
    END_LOOP

    IF (Remove_extension)
    LET Dot_posn (POS Basename '.')
    IF (Dot_Posn<>0) {If no '.' then no extension, just leave as is}
    LET Substring Basename
    LET Strlen (LEN Substring)
    LET Basename ''
    LOOP
    LET Basename (Basename + (SUBSTR Substring 1 Dot_posn))
    LET Substring (SUBSTR Substring (Dot_posn+1) Strlen)
    LET Dot_posn (POS Substring '.')
    LET Strlen (LEN Substring)
    EXIT_IF (Dot_posn=0)
    END_LOOP
    {Remove the last '.'}
    LET Basename (SUBSTR Basename 1 ((LEN Basename)-1))
    END_IF
    END_IF

    LET Atms_file_basename Basename
    {DISPLAY Atms_file_basename}
    END_DEFINE {Atms_extract_basename}
    DEFINE Plot_mode

    EDIT_PART TOP
    INQ_ENV 6
    LET Plot_sc (INQ 4)
    INQ_ENV 7
    LET Plot_width (((X_OF ((INQ 102)-(INQ 101)))*Plot_sc)-0.001)
    LET Plot_height (((Y_OF ((INQ 102)-(INQ 101)))*Plot_sc)-0.001)

    LET Plot_width( ROUND( Plot_width))

    LET Plot_height( ROUND( Plot_height))


    IF (Plot_width>Plot_height)

    WIN_PRT_MGR ORIENTATION LANDSCAPE COPIES 1 END
    ELSE
    LET PLOT_TMP_W Plot_width
    LET Plot_width Plot_height
    LET Plot_height PLOT_TMP_W
    WIN_PRT_MGR ORIENTATION PORTRAIT COPIES 1 END
    END_IF

    IF ((Plot_width > 1179) AND (Plot_width < 1199) AND (Plot_height < 850) and (Plot_height > 830) )
    LET Mode '过大尺寸: ISO A0'
    LET ModeName 'A0'
    END_IF

    IF ( (Plot_width < 850) and (Plot_width > 830) AND (Plot_height < 620) AND (Plot_height > 590))
    LET Mode '过大尺寸: ISO A1'
    LET ModeName 'A1'
    END_IF
    IF ((Plot_width < 620) AND (Plot_width > 590) AND (Plot_height < 430) AND (Plot_height > 410) )
    LET Mode '过大尺寸: ISO A2'
    LET ModeName 'A2'
    END_IF
    IF (( Plot_width < 430) AND (Plot_width > 410) AND (Plot_height < 300) AND (Plot_height > 280))
    LET Mode '过大尺寸: ISO A3'
    LET ModeName 'A3'
    END_IF
    IF ((Plot_width = 297) AND (Plot_height < 220) AND (Plot_height > 200) )
    LET Mode '过大尺寸: ISO A4'
    LET ModeName 'A4'
    END_IF
    IF ((Plot_width < 1496) AND (Plot_width > 1476) AND (Plot_height < 850) AND (Plot_height > 830) )
    LET Mode ('过大尺寸: 自定义: 1 1486 x 841 毫米')
    LET ModeName 'U1'

    END_IF
    IF (Mode = 'NONE')
    {DISPLAY Plot_width}
    {DISPLAY Plot_height}
    LET Mode ('Custom size... ( '+STR(Plot_width)+' mm x '+STR(Plot_height)+' mm )')
    OPEN_OUTFILE 1 APPEND 'size.txt'
    WRITE_FILE 1 Atms_file_basename
    WRITE_FILE 1 Plot_width
    WRITE_FILE 1 Plot_height
    CLOSE_FILE 1
    END_IF
    END_DEFINE


    INQ_ENV 0
    LET Current_fullpath (INQ 304)
    Atms_extract_basename Current_fullpath 1

    PLOTTER_TYPE 'HP4500'
    LET ModeName 'NONE'
    LET Mode 'NONE'
    Plot_mode
    PLOT_DESTINATION DEL_OLD (Atms_file_basename+'-'+ModeName +'.plt')
    PLOT_FORMAT (Mode)

    {OPEN_OUTFILE 1 DEL_OLD 'temp.txt'
    INQ_ENV 22
    LET TMP (INQ 902)
    WRITE_FILE 1 TMP
    LET TMP (INQ 903)
    WRITE_FILE 1 TMP
    CLOSE_FILE 1}
    { plot it }
    {
    This macro ensures that Annotation drawings are printed out with SHEETS
    option and in proper layout (auto detected LANDSCAPE or PORTRAIT).
    }
    Start_plotting_process