Global function output

Global function output

MitchPflederer
Advocate Advocate
639 Views
3 Replies
Message 1 of 4

Global function output

MitchPflederer
Advocate
Advocate

Can i run a macro(sub) within a macro(main) and get the output variable of the macro(sub)? like this...

 


function Main(){
macro sub.mac 

string data = data_from_sub

PRINT $data

}

 

 

then my standalone macro 

function Main(OUTPUT string data_from_sub){

string data_from_sub = "hello world"

0 Likes
640 Views
3 Replies
Replies (3)
Message 2 of 4

amin13751387
Enthusiast
Enthusiast

use:

 

MACRO "C:\folderwithmacros\AnOther.mac"

 

to run a macro from another one. change address as your macro

0 Likes
Message 3 of 4

icse
Advisor
Advisor

you could do it like this:

 

first file with the main macro:

include "yourfunctionspath\functions.inc"

function main() {
	//main mac 
	string $data_from_sub = ""
	call myExternFunction($data_from_sub)
	
	message info &data_from_sub
}

 

the second file with the method called in the first one:

function myExternFunction(output string $data_from_sub) {
	$data_from_sub = "data"
}
0 Likes
Message 4 of 4

Sean571
Advocate
Advocate

I like to use project variables if I am passing data from one macro to the next, but usually this is when I have separate macros that are not sub macros. If I wanted to do a sub macro call, but pass data back, I'd just rewrite the sub macro as a function in the main macro or do as @icse suggested.

But that said, project variables will work with sub macros like this:

 

// Main macro
FUNCTION Main() {

    macro sub.mac

    // safety check to make sure sub macro ran properly
    if not member($Project._keys, "Data") {
        message info "data from sub macro not found."
    } else {
        message info $Project.Data
    }
}

 

 

 

// Sub Macro
FUNCTION Main() {

    string data_from_sub = "data"

    // Create project variable if it doesn't exist
    IF NOT Member($Project._keys, "Data") {
        EDIT USERPAR project NAME "Data"
        EDIT USERPAR project  TYPE 'String'
        CREATE USERPAR project
    }

    $project.Data = $data_from_sub

}

 


And if you don't want tons of project variables or don't need them after using them then you can always delete it after use with this:

 

EDIT USERPAR project SELECT "Data"
DELETE USERPAR project SELECTED

 

 

Sean Wroblewski
Applications Engineer

0 Likes