Macro error help

Macro error help

anto_joseph4HH2K
Contributor Contributor
566 Views
6 Replies
Message 1 of 7

Macro error help

anto_joseph4HH2K
Contributor
Contributor

Hi Guys

This PowerMill macro duplicates the active toolpath folder into several new folders, each with a specific name and thickness. It then updates the toolpath thickness in each new folder, adding 0.04 mm extra if the strategy is "Corner Finishing." But I get an error at the line that makes copy of the folder.Can any one help please

 

0 Likes
567 Views
6 Replies
Replies (6)
Message 2 of 7

nguyenthinhvt95
Advocate
Advocate

@anto_joseph4HH2K:
The root of the problem is using $variable inside double quotes. I suggest that you create a new string for the path instead.
STRING temp = ACTIVE_FOLDER()
STRING sourceFolder = replace(temp, 'Toolpath\', '')
STRING LIST targetFolders = { "OP1-CMS-FINISH-0-40", "OP1-CMS-FINISH-0-30", "OP1-CMS-FINISH-0-20", "OP1-CMS-FINISH-0-15", "OP1-CMS-FINISH-0-10","OP1-CMS-FINISH-0-05", "OP1-CMS-FINISH-0-00","OP1-CMS-FINISH-M0-05", "OP1-CMS-FINISH-M0-10", "OP1-CMS-FINISH-M0-15","OP1-CMS-FINISH-M0–20"}

REAL LIST baseThicknesses = { 0.4,0.3, 0.2,0.15, 0.10,0.05, 0.0,-0.05, -0.1,-0.15, -0.2}

INT count = size(targetFolders)
INT i = 0

WHILE $i < $count {
STRING target = targetFolders[$i]
REAL thickness = baseThicknesses[$i]


string full_sourceFolder = "Toolpath\" +  $sourceFolder
string full_target = "Toolpath\" + $target


// COPY FOLDER "Toolpath\$sourceFolder" "Toolpath\$target"
COPY FOLDER $full_sourceFolder $full_target



FOREACH tp IN folder("Toolpath\$target") {
ACTIVATE TOOLPATH $tp.Name
REAL finalThickness = thickness
IF lcase($toolpath.Strategy.Name) == "corner finishing" {
$finalThickness = $finalThickness + 0.04
}
EDIT TOOLPATH THICKNESS $finalThickness
}

$i = $i + 1
}

 

0 Likes
Message 3 of 7

anto_joseph4HH2K
Contributor
Contributor

Hi I still get the Copy folder error

 

anto_joseph4HH2K_1-1748602986820.png

 

0 Likes
Message 4 of 7

a_bako
Enthusiast
Enthusiast

I hope this is working:

 

STRING temp = active_folder()
IF $temp EQ "" {
RETURN
}
STRING sourceFolder = replace(temp, 'Toolpath\', '')
STRING LIST targetFolders = { "OP1-CMS-FINISH-0-40", "OP1-CMS-FINISH-0-30", "OP1-CMS-FINISH-0-20", "OP1-CMS-FINISH-0-15", "OP1-CMS-FINISH-0-10","OP1-CMS-FINISH-0-05", "OP1-CMS-FINISH-0-00","OP1-CMS-FINISH-M0-05", "OP1-CMS-FINISH-M0-10", "OP1-CMS-FINISH-M0-15","OP1-CMS-FINISH-M0–20"}
REAL LIST baseThicknesses = { 0.4 , 0.3 , 0.2 , 0.15 , 0.10 , 0.05 , 0.0 , -0.05 , -0.1 , -0.15 , -0.2}

INT count = size(targetFolders)
INT i = 0

WHILE $i < $count {
STRING target = $targetFolders[$i]
REAL thick = $baseThicknesses[$i]

STRING cmd = "RENAME FOLDER "+'"'+$temp+'" "Temp___Temp"'
DOCOMMAND $cmd

COPY TOOLPATH FOLDER "Toolpath\Temp___Temp"

$cmd = "RENAME FOLDER "+'"Toolpath\Temp___Temp" "'+$sourcefolder+'"'
DOCOMMAND $cmd

$cmd = "RENAME FOLDER "+'"Toolpath\Temp___Temp_1" "'+$target+'"'
DOCOMMAND $cmd


FOREACH tp IN reverse(folder("Toolpath\" + $target)) {
ACTIVATE TOOLPATH $tp
INVALIDATE TOOLPATH $tp
EDIT PAR 'UseAxialThickness' '0'
IF position($tp.Strategy, "_corner") NE -1 {
EDIT PAR 'Thickness' ${$Thick + 0.04}
} ELSE {
EDIT PAR 'Thickness' $Thick
}
EDIT TOOLPATH $tp REAPPLYFROMGUI
}
$i = $i + 1
}

0 Likes
Message 5 of 7

anto_joseph4HH2K
Contributor
Contributor

Hi,it works great except for the last folder is renamed as "OP1-CMS-FINISH-M0–20"

0 Likes
Message 6 of 7

iroda
Participant
Participant

Hi,

My colleague (a_bako) is on holiday. He'll come back to you when he returned next week.

Thank you for your patience.

0 Likes
Message 7 of 7

a_bako
Enthusiast
Enthusiast

It seems there  is an issue in "targetFolders"  list.

Please check the last item of "targetFolders" list. It must be "OP1-CMS-FINISH-M0–20" .

0 Likes