Difference between revisions of "Macro"

From ArcoWiki
Jump to: navigation, search
 
(5 intermediate revisions by 2 users not shown)
Line 1: Line 1:
 
'''Macro''' are sub-routines that allow to compact a sequence of instructions in a single command.<br/>
 
'''Macro''' are sub-routines that allow to compact a sequence of instructions in a single command.<br/>
 
The macro command can be in the main program or in an external file.<br/>
 
The macro command can be in the main program or in an external file.<br/>
If the macro commands are in the program, they have to be written at the beginning of it.<br/>
+
 
 +
== ==
 +
If the macro description is inside the [[DMIS]] program, it should be written at the beginning of it but, in any case, prior to the execution of the Macro command itself.<br/>
  
 
<code><span style="color: green; text-decoration: none;">$$ Example of a MACRO declaration</span><br/></code>
 
<code><span style="color: green; text-decoration: none;">$$ Example of a MACRO declaration</span><br/></code>
Line 24: Line 26:
  
 
<code><span style="color: green; text-decoration: none;">$$ Recall to execute the macro</span><br/></code>
 
<code><span style="color: green; text-decoration: none;">$$ Recall to execute the macro</span><br/></code>
::<code>CALL/M(foro),12.5,12.5,(foro1)</code>
+
::<code>CALL/M(foro),12.5,12.5,foro1</code>
  
 
::<code><span style="color: green; text-decoration: none;">$$ instructions</span><br/></code>
 
::<code><span style="color: green; text-decoration: none;">$$ instructions</span><br/></code>
 
::<code><span style="color: green; text-decoration: none;">$$ instructions</span><br/></code>
 
::<code><span style="color: green; text-decoration: none;">$$ instructions</span><br/></code>
  
 +
To make invisible the macro in the management panel is necessary insert before name the instruction MSLOCAL_
  
 +
<code><span style="color: green; text-decoration: none;">$$ Example of a invisible MACRO declaration</span><br/></code>
 +
 +
::<code>M(MSLOCAL_foro)=MACRO/off_x,off_y,'nome_ci'</code>
 +
 +
::<code><span style="color: green; text-decoration: none;">$$ instructions</span><br/></code>
 +
::<code><span style="color: green; text-decoration: none;">$$ instructions</span><br/></code>
 +
 +
::<code>ENDMAC</code>
 
== ==
 
== ==
Using the ‘EXTFIL’ command, tha macros are recalled from the specified external file.
+
If the macro is located in an external file (for example to make sure that the macro can be shared between more programs), then the macro file shall be inserted in the program using the procedure to  [[Include an External Macro File]] at the beginning of the program using an ‘EXTFIL’ command.
 +
In this case the macros are recalled from the specified external file.
  
 
<code><span style="color: green; text-decoration: none;">$$ Use of an external file containing macro declaration</span><br/></code>
 
<code><span style="color: green; text-decoration: none;">$$ Use of an external file containing macro declaration</span><br/></code>
Line 37: Line 49:
  
  
The external macro file has “.DML” extension, begins with <code>DMISMD/</code> and ends with <code>ENDFIL/</code>.<br/>
+
The [[External Macro File|external macro file]] has “.DML” extension, begins with <code>DMISMD/</code> and ends with <code>ENDFIL/</code>.<br/>
 
Inside of the file, the syntax is the same as a regular [[DMIS]] program.
 
Inside of the file, the syntax is the same as a regular [[DMIS]] program.
  
Line 54: Line 66:
 
::<code>ENDMAC</code>
 
::<code>ENDMAC</code>
 
<code>ENDFIL</code>
 
<code>ENDFIL</code>
 +
 +
[[it:Macro]]
 +
[[zh-cn:宏]]
 +
[[pt:Macro]]
 +
[[de:Makro]]
 +
[[es:Macro]]
 +
[[en:Macro]]
  
 
[[Category:Dmis_Tutorial]]
 
[[Category:Dmis_Tutorial]]

Latest revision as of 13:48, 6 April 2021

Macro are sub-routines that allow to compact a sequence of instructions in a single command.
The macro command can be in the main program or in an external file.

If the macro description is inside the DMIS program, it should be written at the beginning of it but, in any case, prior to the execution of the Macro command itself.

$$ Example of a MACRO declaration

M(foro)=MACRO/off_x,off_y,'nome_ci'
DECL/LOCAL,DOUBLE,r_foro,z_mis
r_foro=ASSIGN/6.25
z_mis=ASSIGN/-2.5
F(@nome_ci) = FEAT/CIRCLE, INNER, CART, off_x, off_y, z_mis, 0, 0, 1, r_foro*2
MEAS/CIRCLE, F(@nome_ci), 4
GOTO/off_x, off_y, 7
PTMEAS/CART, off_x+r_foro, off_y, z_mis, -1, 0, 0
PTMEAS/CART, off_x, off_y+r_foro, z_mis, 0, -1, 0
PTMEAS/CART, off_x-r_foro, off_y, z_mis, 1, 0, 0
PTMEAS/CART, off_x, off_y-r_foro, z_mis, 0, 1, 0
GOTO/off_x, off_y, 7
ENDMES
$$ End of Macro Declaration
ENDMAC
$$ instructions
$$ instructions

$$ Recall to execute the macro

CALL/M(foro),12.5,12.5,foro1
$$ instructions
$$ instructions

To make invisible the macro in the management panel is necessary insert before name the instruction MSLOCAL_

$$ Example of a invisible MACRO declaration

M(MSLOCAL_foro)=MACRO/off_x,off_y,'nome_ci'
$$ instructions
$$ instructions
ENDMAC

If the macro is located in an external file (for example to make sure that the macro can be shared between more programs), then the macro file shall be inserted in the program using the procedure to Include an External Macro File at the beginning of the program using an ‘EXTFIL’ command. In this case the macros are recalled from the specified external file.

$$ Use of an external file containing macro declaration

EXTFIL/DMIS,'c:\cim\MACRO.dmi'


The external macro file has “.DML” extension, begins with DMISMD/ and ends with ENDFIL/.
Inside of the file, the syntax is the same as a regular DMIS program.


$$ Declaration of different Macro in an external file
DMISMD/'module_name'

$$ First Macro declaration
M(macro_1)=MACRO/passedtext
TEXT/OPER,CONCAT('You passed the following text to the macro: ',passedtext)
ENDMAC
$$ Second Macro declaration
M(macro_2)=MACRO/num1,num2
DECL/DOUBLE,sumres
sumres=ASSIGN/num1+num2
EXT/OPER,CONCAT('The sum of the 2 numbers is: ',STR(sumres))
ENDMAC

ENDFIL