create a macro nc program

create a macro nc program

lamtuyphong11
Contributor Contributor
822 Views
15 Replies
Message 1 of 16

create a macro nc program

lamtuyphong11
Contributor
Contributor
  • Please help me create a macro nc program. I want to add a program of the same name together. Thank you for watching2.png1.png

      

0 Likes
823 Views
15 Replies
Replies (15)
Message 2 of 16

icse
Collaborator
Collaborator

do you whant somthing similar to this:

https://forums.autodesk.com/t5/powermill-forum/help-for-rename-toolpath/m-p/12181831#M29087 

 

but instead of adding it to folders add it to nc Programm?

 

what if the nc programm does not exist? should it be created automaticly?

Message 3 of 16

icse
Collaborator
Collaborator
string list $subFolders = get_folders('Toolpath')
int $index = input choice $subFolders 'Select Folder'


int $prefix = 1

string $ncName = ''

dialogs message off
foreach $tp in folder($subFolders[$index]) {

	if position($tp.Name, $prefix) == 0 {
		$ncName = $tp.Name		
		if not entity_exists('ncprogram', $ncName) {
			create ncprogram ${ncName}			
		}		
		$prefix = $prefix +1
	}
	
	if entity_exists('ncprogram' , $ncName) and position($tp.Name, $prefix - 1) == 0 {
		edit ncprogram ${ncName} insert toolpath ${tp.name} last
	}
}
dialogs message on
0 Likes
Message 4 of 16

lamtuyphong11
Contributor
Contributor

CO-CHUOI-KY-TU.png

 Thank you very much for your help. Can you convert it similarly but add a letter character in front?.

0 Likes
Message 5 of 16

icse
Collaborator
Collaborator

When the ladder should be added? I Edited the macro so it adds the 'G' after the toolpath is added

string list $subFolders = get_folders('Toolpath')
int $index = input choice $subFolders 'Select Folder'


int $prefix = 1

string $ncName = ''

dialogs message off
foreach $tp in folder($subFolders[$index]) {

	if position($tp.Name, $prefix) == 0 {
		$ncName = $tp.Name		
		if not entity_exists('ncprogram', $ncName) {
			create ncprogram ${ncName}			
		}		
		$prefix = $prefix +1
	}
	
	if entity_exists('ncprogram' , $ncName) and position($tp.Name, $prefix - 1) == 0 {
		edit ncprogram ${ncName} insert toolpath ${tp.name} last
		string $newName = 'G' + $tp.name
		if entity_exists('toolpath', $newName) {
			$newName = new_entity_name('toolpath', $newName)
		}
		rename toolpath ${tp.name} ${newName}
	}
}
dialogs message on
0 Likes
Message 6 of 16

lamtuyphong11
Contributor
Contributor

Can you keep the characters from the toolpath list on nc? characters are available below.

0 Likes
Message 7 of 16

icse
Collaborator
Collaborator
string list $subFolders = get_folders('Toolpath')
int $index = input choice $subFolders 'Select Folder'


int $prefix = 1

string $ncName = ''

dialogs message off
foreach $tp in folder($subFolders[$index]) {

	string $newName = 'G' + $tp.name
	if entity_exists('toolpath', $newName) {
		$newName = new_entity_name('toolpath', $newName)
	}
	rename toolpath ${tp.name} ${newName}
	
	if position($tp.Name, $prefix) == 1 {
		$ncName = $tp.Name		
		if not entity_exists('ncprogram', $ncName) {
			create ncprogram ${ncName}			
		}		
		$prefix = $prefix +1
	}
	
	if entity_exists('ncprogram' , $ncName) and position($tp.Name, $prefix - 1) == 1 {
		edit ncprogram ${ncName} insert toolpath ${tp.name} last

	}
}
dialogs message on
0 Likes
Message 8 of 16

lamtuyphong11
Contributor
Contributor

Thank you for helping me. But I need something more complicated. I want all the tools in the toolpath list to go to NC but the toolpath name remains the same. and add together when the preceding series overlaps. For example: B1-R2 and B1+1 combine together on nc program. thank you!

0 Likes
Message 9 of 16

icse
Collaborator
Collaborator

I Dont get what you whant....

Why the prefix is now 'A', 'B'? can the prefix be more than 1 letter eg "ABC"?

Should the macro do the renaming of the toolpaths or not?

is it just to add them in the nc programm?

 

Can you explain your end goal with this?(in detail)

0 Likes
Message 10 of 16

lamtuyphong11
Contributor
Contributor

Sorry for not making the problem clear to you. I want all toolpaths to be on the nc. but their names do not change. If any toolpath has additional tools, add them together: for example, C1-6r3 and C1+1, then combine them. together or H3-4r2 and H3+1 with H3+2, then add these 3 tools together on the nc program. If the previous chain is the same and the tool is shared then add them together, here the maximum value is H3 If you use the same tool 4r2, then use the same tool on nc program.Thank you !

0 Likes
Message 11 of 16

nguyenthinhvt95
Advocate
Advocate

@lamtuyphong11 : I just edit a little bit @icse's Macro, hope it 's work.

(Hi Phong em thử lại với macro này nhé, hy vọng hoạt động)

 

@icse: the prefix he want sometimes is text, sometime is number so I use substring  to compare and add nc program.

 

 

DELETE NCPROGRAM ALL

string list $subFolders = get_folders('Toolpath')
int $index = input choice $subFolders 'Select Folder'

//Create nc program
string $ncName = ''
dialogs message off
foreach $tp in folder($subFolders[$index]) {
int posit = position($tp.name,"-")
if posit != -1 {
string $prefix = substring($tp.name, 0 , $posit)
$ncName = $tp.Name
if not entity_exists('ncprogram', $ncName) {
create ncprogram ${ncName}
}
// add toolpath into nc program
foreach $tp_temp in folder($subFolders[$index]) {
if substring($tp.name, 0 , $posit) == substring($tp_temp.name, 0 , $posit) {
if $entity('Toolpath', $tp.Name).Tool.name == $entity('Toolpath', $tp_temp.Name).Tool.name {
EDIT NCPROGRAM ; APPEND TOOLPATH $tp_temp.name
}
}
}
}
}

 
 
 
 
 

 

 

Message 12 of 16

icse
Collaborator
Collaborator
string list $subFolders = get_folders('Toolpath')
int $index = input choice $subFolders 'Select Folder'



string $ncName = ''
string $preToolName = ''

dialogs message off

foreach $tp in folder($subFolders[$index]) {
		
	if $tp.Tool.Name != $preToolName {
		$ncName = $tp.Name		
		if not entity_exists('ncprogram', $ncName) {
			create ncprogram ${ncName}			
		}	
		$preToolName = $tp.Tool.Name
	}
	
	if entity_exists('ncprogram' , $ncName) and $tp.Tool.Name == $preToolName {
		edit ncprogram ${ncName} insert toolpath ${tp.Name} last
	}
}
dialogs message on
0 Likes
Message 13 of 16

nguyenthinhvt95
Advocate
Advocate

@lamtuyphong11 

DELETE NCPROGRAM ALL

string list $subFolders = get_folders('Toolpath')
int $index = input choice $subFolders 'Select Folder'


//Create nc program
string $ncName = ''
dialogs message off
foreach $tp in folder($subFolders[$index]) {
int posit = position($tp.name,"-")
if posit != -1 {
string $prefix = substring($tp.name, 0 , $posit)
$ncName = $tp.Name
if not entity_exists('ncprogram', $ncName) {
create ncprogram ${ncName}

}
}
}

 

// add toolpath into nc program

//--------------------------------------------------------------------------------------------

FOREACH $prog IN folder('ncprogram') {
int k = 0
ACTIVATE NCProgram $prog.name
//add main toolpath
EDIT NCPROGRAM ; APPEND TOOLPATH $prog.name
int posit = position($prog.name,"-")
string $prefix = substring($prog.name, 0 , $posit)

foreach $tp in folder($subFolders[$index]) {

// add sub toolpath if exists
WHILE k < 50 {
String tp_check = $prefix + "+" + $k
IF ENTITY_EXISTS('toolpath', $tp_check) {
EDIT NCPROGRAM ; APPEND TOOLPATH $tp_check
//edit ncprogram $prog insert toolpath $tp_check last
}
$k= $k + 1
}


}
}

 

 

 

 

 

 

 

Message 14 of 16

nguyenthinhvt95
Advocate
Advocate
Message 15 of 16

lamtuyphong11
Contributor
Contributor

Thank you for helping me

0 Likes
Message 16 of 16

lamtuyphong11
Contributor
Contributor

Quá ok a ơi

0 Likes