Community
PowerMill Forum
Welcome to Autodesk’s PowerMill Forums. Share your knowledge, ask questions, and explore popular PowerMill topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Global function output

3 REPLIES 3
Reply
Message 1 of 4
MitchPflederer
112 Views, 3 Replies

Global function output

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"

Labels (1)
3 REPLIES 3
Message 2 of 4

use:

 

MACRO "C:\folderwithmacros\AnOther.mac"

 

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

Message 3 of 4
icse
in reply to: MitchPflederer

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"
}
Message 4 of 4
Sean571
in reply to: MitchPflederer

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

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report