Macro to create NC code

Macro to create NC code

newbie123abc
Enthusiast Enthusiast
4,175 Views
28 Replies
Message 1 of 29

Macro to create NC code

newbie123abc
Enthusiast
Enthusiast

Hi everybody,

 

I usually create NC code for active toolpath by right click on it and then choose command "Create Individual NC Program". Now, I would like to make a macro to do this. This is my macro (active toolpath is 6000):

 

EXPLORER SELECT Toolpath "Toolpath\6000" NEW
CREATE NCPROGRAM "6000" EDIT NCPROGRAM "6000" APPEND TOOLPATH "6000" DEACTIVATE NCPROGRAM

 

I would like to active another toolpath like 6001 and run this macro for creating NC code file with name 6001, could you please fix it for me ?

 

Thank you very much ! 

 

 

0 Likes
4,176 Views
28 Replies
Replies (28)
Message 21 of 29

newbie123abc
Enthusiast
Enthusiast

Wonderful, it worked. Thank you so much @kukelyk

0 Likes
Message 22 of 29

newbie123abc
Enthusiast
Enthusiast

Hi @kukelyk,

 

Your macro worked very well, but I still have a small issue. If the time is over 1 hour, the time will be exported to excel file wrong (if less than 1 hour, it's right). For example: total time is 1:13:14 but the value in excel file is 0.0925231481481481. Could you please help me to fix it again ? Thank you very much !

0 Likes
Message 23 of 29

kukelyk
Advisor
Advisor
Accepted solution

replace:

STRING secs = STRING(INT((($Time-INT($Time%60))/60)))

with

STRING secs = STRING(INT( ($Time - INT($hours)*60 - INT($mins) ) *60 ))
Message 24 of 29

newbie123abc
Enthusiast
Enthusiast

Hi @kukelyk,

 

With this macro, can I get the NC.csv file at the dynamic path ? My project will be saved like picture below and I would like to save NC.csv in B folder. Could you please help me ? Thank you very much !

 

pic.jpg

0 Likes
Message 25 of 29

kukelyk
Advisor
Advisor
STRING project_dir =project_pathname(0)
STRING folder_contains_project_folder  = dirname(replace (project_pathname(0), "/","\"))
Message 26 of 29

newbie123abc
Enthusiast
Enthusiast

Hi @kukelyk,

 

Thank you for your help. I put your command in the first line of the macro like that, but it exported NC.csv to my desktop screen. Could you help me to use your command in the right way ? Thank you very much !

 

//
// Macro to export NC data to Excel
//
// Open File
STRING project_dir =project_pathname(0)
STRING folder_contains_project_folder = dirname(replace (project_pathname(0), "/","\"))
FILE OPEN "NC.csv" FOR WRITE AS "output"
// Cycle through the NC programs
REAL sumtime = 0
FOREACH ncp IN folder('NCProgram') {
REAL ncptime = 0
// Create an empty list
STRING List names = {}
// Output NC Program name
STRING nome = "NC Program:," + ncp.Name
FILE WRITE $nome TO "output"
// Output Header for Toolpath data
STRING header = "Toolpath Name, Tool Name, Toolpath Length"
FILE WRITE $header TO "output"
// loop over the components in the nc program
FOREACH item IN components(ncp) {
// Check that it is a toolpath
IF item.RootType == 'nctoolpath' {
REAL Time = $entity('toolpath',$item.name).statistics.LeadsandLinks.Times.plunge + $entity('toolpath',$item.name).statistics.LeadsandLinks.Times.ramp+ $entity('toolpath',$item.name).statistics.LeadsandLinks.Times.rapid
$Time = $Time + $entity('toolpath',$item.name).statistics.LeadsandLinks.Times.others + $entity('toolpath',$item.name).statistics.cuttingmoves.Times.arcs + $entity('toolpath',$item.name).statistics.cuttingmoves.Times.linear
STRING tpTime = ''
STRING hours = STRING(INT($Time/60))
IF INT($hours) < 10 {
$hours = '0' + $hours
}
STRING mins = STRING(INT($Time%60))
IF INT($mins) < 10 {
$mins = '0' + $mins
}
STRING secs = STRING(INT((($Time-INT($Time%60))*60)))
IF INT($secs) < 10 {
$secs = '0' + $secs
}
$tpTime = $hours + ":" + $mins + ":" + $secs
$ncptime = $ncptime + $Time
$sumtime = $sumtime + $Time
// Use MEMBER to check that we have not seen this name before
IF NOT member(names, item.Name) {
// Add name to list
bool ok = add_last(names, item.Name)
// Output data for current toolpath
STRING line = item.Name + "," + item.Toolname.value + "," + $tpTime
FILE WRITE $line TO "output"
}
}
}
// Write an empty line
STRING empty_line = " "
FILE WRITE $empty_line TO "output"
}
// Close File
FILE CLOSE "output"

0 Likes
Message 27 of 29

kukelyk
Advisor
Advisor
Accepted solution

Try this way:

//
// Macro to export NC data to Excel
//
// Open File
STRING csv_file = dirname(dirname(dirname(replace (project_pathname(0), "/","\")))) + "\B\NC.csv"
FILE OPEN $csv_file FOR WRITE AS "output"
//etc.
Message 28 of 29

Arondevillier
Participant
Participant

Hello Sir,

I need help with path setting, I need to save different folders output NC...we have different M/c's so it has many folders with different names..ex:- makino, Fanuc,Roaders..Is there any way solve this... please help me with this 

0 Likes
Message 29 of 29

ramaprasad_narayan
Enthusiast
Enthusiast

Hi all,

 

i need help to create a macro for Setup sheet printing and snapshoot.

 

but i couldn't find an option for select all in "NC Programs" to record it

 

Thank you

0 Likes