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: 

How to create a macro that deletes the first letter of the toolpath name??

11 REPLIES 11
SOLVED
Reply
Message 1 of 12
SONGJUNHYUK
751 Views, 11 Replies

How to create a macro that deletes the first letter of the toolpath name??

Hello.

 

I want to make a macro that deletes the first letter of toolpath(that i seleted)  name.

 

Example,

 

toolpath name : abc11, abc22, abc33, abc44, ,,,,,

macro result : bc11, bc22, bc33, bc44, ,,,,,

 

I want to delete the first letter.

 

Can anyone help me to solve this issue?

 

Thank you.

Labels (1)
11 REPLIES 11
Message 2 of 12
kukelyk
in reply to: SONGJUNHYUK

Try this:

FOREACH tp IN FOLDER('toolpath') {
	STRING newname = substring($tp.name, 1)
	IF NOT ENTITY_EXISTS ('toolpath', $newname) {
		RENAME TOOLPATH $tp.name $newname
	} ELSE {
		//do something else
		//ie.
		$newname = new_entity_name('toolpath', $newname)
		RENAME TOOLPATH $tp.name $newname
	}
}
Message 3 of 12
SONGJUNHYUK
in reply to: kukelyk

Thank you so much...........

 

Have a nice day!

Message 4 of 12
O.C.
in reply to: SONGJUNHYUK

How can you do it to only selected toolpaths?

Message 5 of 12
PRAMET-DORMERR
in reply to: kukelyk

PRAMETDORMERR_0-1633242690507.png

 

Message 6 of 12

How to create a macro that deletes the first letter AS PER GIVEN IMAGE

Message 7 of 12
kukelyk
in reply to: O.C.

try this one: (not tested)

FOREACH ent IN explorer_selected_entities() {
	IF $ent.RootType == "toolpath" {
		STRING newname = substring($ent.name, 1)
		IF NOT ENTITY_EXISTS ('toolpath', $newname) {
			RENAME TOOLPATH $ent.name $newname
		} ELSE {
			//do something else
			//ie.
			$newname = new_entity_name('toolpath', $newname)
			RENAME TOOLPATH $ent.name $newname
		}
	}
}
Message 8 of 12
kukelyk
in reply to: PRAMET-DORMERR

You could try this (also not tested):

FOREACH tp IN FOLDER('toolpath') {
	If position($tp.name, " ") != -1 {
		STRING newname = tokens($tp.name)[1]
		IF NOT ENTITY_EXISTS ('toolpath', $newname) {
			RENAME TOOLPATH $tp.name $newname
		} ELSE {
			//do something else
			//ie.
			$newname = new_entity_name('toolpath', $newname)
			RENAME TOOLPATH $tp.name $newname
		}
	}
}

 

Message 9 of 12
PRAMET-DORMERR
in reply to: kukelyk

BEFORE RUN MACRO 

PRAMETDORMERR_0-1633322288019.png

 

 

AFTER RUN MACRO  

PRAMETDORMERR_1-1633322330667.png

SOME LETTER MISSING 

PRAMETDORMERR_2-1633322456390.png

 

Message 10 of 12
PRAMET-DORMERR
in reply to: kukelyk

NOT WORKING

Message 11 of 12
kukelyk
in reply to: PRAMET-DORMERR

Ah, there is a hyphen, try this instead:

String hyphen = "-"
FOREACH tp IN FOLDER('toolpath') {
	If position($tp.name, $hyphen ) != -1 {
		STRING newname = tokens($tp.name, $hyphen )[1]
		IF NOT ENTITY_EXISTS ('toolpath', $newname) {
			RENAME TOOLPATH $tp.name $newname
		} ELSE {
			//do something else
			//ie.
			$newname = new_entity_name('toolpath', $newname)
			RENAME TOOLPATH $tp.name $newname
		}
	}
}
Message 12 of 12
PRAMET-DORMERR
in reply to: kukelyk

is work , great! thank you.

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

Post to forums  

Technology Administrators


Autodesk Design & Make Report