Tech Tip: Exporting a method as text programmatically
PRODUCT: 4D | VERSION: 11.4 | PLATFORM: Mac & Win
Published On: May 21, 2009
Exporting a method body as text can be handled programmatically by using macros in 4D.
Here is a sample macro.xml file:
<?xml version="1.0" ecoding="UTF-8" standalone="no" ?> <!DOCTYPE macros SYSTEM "https://www.4d.com/dtd/2007/macros.dtd"> <macros> <macro name="Method_text" method_event="on_save" version="2"> <text> <method>MethodBody("<method_name><method_name />")</method> </text> </macro> </macros> |
In this example, the "method_event=on_save" attribute specifies when the project method named "MethodBody" is to be executed. The "on_save" attribute is triggered only trough the Save Method option in the File menu. To be accessible from 4D, this macro should be saved in the "Macros V2" folder.
The "MethodBody" method handles the capturing of the method's text and sending it to an external text file:
` MethodBody method C_TEXT($methodName;$1) C_TEXT($text) C_TIME($vDocRef) $methodName:=$1 GET MACRO PARAMETER(Full method text;$text) $vDocRef:=Create document("") If(OK=1) SEND PACKET($vDocRef;"Method Name: ") SEND PACKET($VDocRef; $methodName) SEND PACKET($vDocRef; Char(Carriage return)) SEND PACKET($vDocRef; String(50*char(95))) SEND PACKET($vDocRef; String(4*Char(Carriage return))) SEND PACKET($vDocRef;$text) CLOSE DOCUMENT($vDocRef) End if |
<method_name><method_name />
needs changing to
<method_name/>
Also (in v12 at least) I had to change "
Other than that works well - a nice easy way to get methods automatically saved to text out of 4D - allowing them to be included in my git source control :-)
lacks a
With this addition, the macro and the associated method function correctly.