Announcements

The Autodesk Community Forums has a new look. Read more about what's changed on the Community Announcements board.

Macro to rename number of edited programs

b.iric29
Contributor

Macro to rename number of edited programs

b.iric29
Contributor
Contributor

Is there anyone who can help me modify a macro,

I have a macro to renumber the beginning of a NC program, But i need one to renumber the extra numbers that are added on from modifying and copying programs in numerical order so i dont need to do them indivdually. 

 

example.

toolpathnumber.PNG

 

Macro that i have for NC program-

 

int $counter = 100
string $new_name = ""

 

$counter = INPUT "Enter start counter value"

FOREACH $progr IN folder('ncprogram') {

$new_name = $counter + "_" + $progr.name
RENAME NCProgram $progr.name $new_name

$counter = $counter + 1
}

 

thank you

0 Likes
Reply
Accepted solutions (1)
627 Views
5 Replies
Replies (5)

artur.boszczyk
Enthusiast
Enthusiast

here you are. 

 

FUNCTION MAIN() {

 

FOREACH tp IN explorer_selected_entities() {

      IF $tp.RootType == "ncprogram" {

            INT $length = length($tp.Name)

            STRING $newName = $tp.Name

            STRING $LastChar = substring($newName, ($length - 1), 1)

            STRING $SecondLastChar = substring($newName, ($length - 2), 1)

            WHILE $LastChar == "_" OR $SecondLastChar == "_" {

                  $newName = substring($newName, 0, ($length - 1))

                  $length = length($newName)

                  $LastChar = substring($newName, ($length - 1), 1)

                  $SecondLastChar = substring($newName, ($length - 2), 1)

            }

            IF entity_exists(entity('ncprogram', $newName)) AND $tp.Name != $newName {

                  $newName = new_entity_name('Ncprogram', $newName)     

                  STRING LIST T=tokens($newName,'_')                   

                  IF size($T)==3  {

                        $newName=trim($T[0]) +"_" + trim($T[1]) + trim($T[2])

                  }

                 

            }

 

            //$line=replace($line, "Information: No collisions were found","")

 

            RENAME NCPROGRAM $tp $newName

            }

      }

}

0 Likes

b.iric29
Contributor
Contributor

Thanks for quick response, I imported this and it just renumbered everything in my power mill session at the beginning of program.

 

Im trying to :

Select a group of programs in explorer that have been edited and end with the "1_2_2_2_1"

Then run the macro, and have macro eliminate those digits and replace with one digit in numerical order. 

 

Is this possible ?

 

 

0 Likes

artur.boszczyk
Enthusiast
Enthusiast

it should only rename the ones you selected in Explorer, not all of them:

 

explorer_selected_entities()

0 Likes

karan30782
Advocate
Advocate
Accepted solution

Try this one ...............

 

//
//Macro will rename only selected toolpath from the list
// If nothing selected every toolpath in the explorer will be renamed_1
//
//Check if user wants to rename the toolapths
//
string yesorno = "Click YES to renumber toolpaths." + crlf + "Otherwise, the macro will be aborted"
bool yes = 0
$yes = QUERY $yesorno
IF yes {
INT COUNT = 0
string PREFIX = ''
$PREFIX = input "Enter exactly what you would like as the Toolpath name"
EDIT ENTATTRIBUTE TEMPLATE TOOLPATH $PREFIX


// Ask user if all toolpaths are to be renumbered or only a selection
string allorno = "Click YES to renumber only a selection of toolpaths." + crlf + "Otherwise, all toolpaths will be renumbered"
bool yes = 0
$yes = QUERY $allorno
IF yes {
//ASK USER TO SELECT THE TOOLPATHS TO BE RENUMBERED
ENTITY LIST $ToolpathNames = INPUT ENTITY MULTIPLE TOOLPATH "Select toolpaths to RENUMBER"
//
FOREACH $TP in ToolpathNames {
ACTIVATE TOOLPATH $TP.name
$COUNT = $COUNT + 1
STRING NewName = $PREFIX + "_" + $COUNT
RENAME TOOLPATH ; $NewName
}


MESSAGE INFO " Programs renamed successfully "

 

0 Likes

b.iric29
Contributor
Contributor

thank you, this is what I was trying to do.

0 Likes