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: 

Macro for activate and rename toolpath.

6 REPLIES 6
SOLVED
Reply
Message 1 of 7
pet.kovacsYHFUD
1359 Views, 6 Replies

Macro for activate and rename toolpath.

Hi.

I just started getting acquainted with macro programming.

I would like to write a macro for activate the toolpath and change the name.

The essence of macro is activate the first toolpath, change the name to the used tool name + any name I can enter in a pop-up window. When this is done go for the next toolpath, activate it and change the name as previously.

Can anyone help me to solve this issue?
Thank you. 

Labels (2)
6 REPLIES 6
Message 2 of 7
Sean570
in reply to: pet.kovacsYHFUD

FUNCTION MAIN() {
    // Reset any local variables
    reset localvars
    // Turn off graphics, Dialogs, and error messages
    GRAPHICS LOCK
    DIALOGS MESSAGE OFF
    DIALOGS ERROR OFF

    // Loop through all toolpaths
    FOREACH tp IN folder('toolpath') {
        // grab user input with a popup
        string userInput = INPUT "Enter name for toolpath"

        // Change toolpath name
        CALL ChangeName(tp, userInput)
    }

    // Turn graphics, Dialogs, and error messages back on
    GRAPHICS UNLOCK
    DIALOGS MESSAGE ON
    DIALOGS ERROR ON
}

FUNCTION ChangeName(Entity tp, string userInput) {
	// create a dummy name for the toolpath
    string tempName = "1"

    // Check that dummy name doesn't already exist
    IF ENTITY_EXISTS('toolpath', $tempName) {
        $tempName = NEW_ENTITY_NAME('toolpath', tempName)
    }
    
    // rename toolpath the temp name
    RENAME TOOLPATH $tp.name $tempName

    // Start building the new toolpath name by grabbing the tool name
    STRING newName = $tp.tool.Name

    // Add the user input to the end of the new name
    $newName = $newName + " " + $userInput

    // check if the new name exists
    IF ENTITY_EXISTS('toolpath', newName) {
        $newName = NEW_ENTITY_NAME('toolpath', newName)
    }

    // rename toolpath the new name
    RENAME TOOLPATH $tp.name $newName	
}

This should work for you

Message 3 of 7

Try this out:

FOREACH $tp IN folder('Toolpath') {
	ACTIVATE TOOLPATH $tp
	STRING $NewName = $tp.Tool.Name
	STRING $PopUp = INPUT "Enter Name"
	$NewName = $NewName + "_" + $PopUp
	
	IF entity_exists(entity('Toolpath', $NewName)) {
		$NewName = new_entity_name('Toolpath', $NewName)
		}
	RENAME TOOLPATH $tp $NewName
	}
Message 4 of 7

That was fast. 🙂 
Thank you all!

Message 5 of 7

Another variant to play with....

Message 6 of 7
avijitpahari28
in reply to: cfastNJWK6

Can it possible to also add toolpath description 

Message 7 of 7
cfastNJWK6
in reply to: avijitpahari28

Absolutely!

 

FOREACH $tp IN folder('Toolpath') {
	ACTIVATE TOOLPATH $tp
	STRING $NewName = $tp.Tool.Name
	STRING $PopUp = INPUT "Enter Name"
	$NewName = $NewName + "_" + $PopUp
	
	IF entity_exists(entity('Toolpath', $NewName)) {
		$NewName = new_entity_name('Toolpath', $NewName)
		}
	RENAME TOOLPATH $tp $NewName
    EDIT TOOLPATH $tp DESCRIPTION $NewName
	}

 

 

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

Post to forums  

Technology Administrators


Autodesk Design & Make Report