Hi Rafael, Wonderful macro.
Only thing that didn't work is if the toolpath\userpameter existed, it just wouldn't replace the old axis with the new one. Is it ok to : If Member(etc...)?
And I guess I could remove the last part of the macro which is :
STRING Old_AxisB = $entity('toolpath';$tp.name).UserParameters.B_Axis
STRING Old_AxisC = $entity('toolpath';$tp.name).UserParameters.C_Axis
IF $Old_AxisB != $New_AxisB {
$TP_NAME = replace($TP_NAME, $Old_AxisB, $New_AxisB)
${entity('toolpath';$tp.name).UserParameters.B_Axis} = $New_AxisB
}
IF $Old_AxisC != $New_AxisC {
$TP_NAME = replace($TP_NAME, $Old_AxisC, $New_AxisC)
${entity('toolpath';$tp.name).UserParameters.C_Axis} = $New_AxisC
}
IF $tp.name != $TP_NAME {
RENAME TOOLPATH ; $TP_NAME
}
So here is your macro with my mods.
DIALOGS ERROR OFF
DIALOGS MESSAGE OFF
ENTITY LIST Toolpaths = INPUT ENTITY MULTIPLE TOOLPATH "Choose toolpaths to rename B and C axis"
FOREACH $tp IN $Toolpaths {
ACTIVATE TOOLPATH $tp.name
SIMULATE TOOLPATH ;
STRING TP_NAME = $tp.Name
STRING LIST Tokens = tokens($tp.Name, " ")
INT S_TOKEN = SIZE($Tokens) - 1
REAL axisB = round(machine().B, 4)
REAL axisC = round(machine().C, 4)
STRING New_AxisB = "B" + $axisB
STRING New_AxisC = "C" + $axisC
IF NOT Member($tp.userparameters._keys,"B_Axis") {
EDIT USERPAR toolpath_strategy $tp.name TYPE 'String'
EDIT USERPAR toolpath_strategy $tp.name NAME "B_Axis"
CREATE USERPAR toolpath_strategy $tp.name
${entity('toolpath';$tp.name).UserParameters.B_Axis} = $New_AxisB
IF $S_TOKEN >= 3 {
IF POSITION($Tokens[$S_TOKEN-1], "A") > -1 OR POSITION($Tokens[$S_TOKEN-1], "B") > -1 OR POSITION($Tokens[$S_TOKEN-1], "C") > -1 {
$TP_NAME = replace($TP_NAME, " " + $Tokens[$S_TOKEN-1], "")
}
IF POSITION($Tokens[$S_TOKEN-2], "A") > -1 OR POSITION($Tokens[$S_TOKEN-2], "B") > -1 OR POSITION($Tokens[$S_TOKEN-2], "C") > -1 {
$TP_NAME = replace($TP_NAME, " " + $Tokens[$S_TOKEN-2], "")
}
IF POSITION($Tokens[$S_TOKEN-3], "A") > -1 OR POSITION($Tokens[$S_TOKEN-3], "B") > -1 OR POSITION($Tokens[$S_TOKEN-3], "C") > -1 {
$TP_NAME = replace($TP_NAME, " " + $Tokens[$S_TOKEN-3], "")
}
}
}
IF NOT Member($tp.userparameters._keys,"C_Axis") {
EDIT USERPAR toolpath_strategy $tp.name TYPE 'String'
EDIT USERPAR toolpath_strategy $tp.name NAME "C_Axis"
CREATE USERPAR toolpath_strategy $tp.name
${entity('toolpath';$tp.name).UserParameters.C_Axis} = $New_AxisC
IF POSITION($Tokens[$S_TOKEN], "OP") > -1 {
$TP_NAME = replace($TP_NAME, " " + $Tokens[$S_TOKEN], "") + " " + $New_AxisB + " " + $New_AxisC + " " + $Tokens[$S_TOKEN]
} ELSE {
$TP_NAME = $TP_NAME + " " + $New_AxisB + " " + $New_AxisC
}
}
IF Member($tp.userparameters._keys,"B_Axis") {
${entity('toolpath';$tp.name).UserParameters.B_Axis} = $New_AxisB
IF $S_TOKEN >= 3 {
IF POSITION($Tokens[$S_TOKEN-1], "A") > -1 OR POSITION($Tokens[$S_TOKEN-1], "B") > -1 OR POSITION($Tokens[$S_TOKEN-1], "C") > -1 {
$TP_NAME = replace($TP_NAME, " " + $Tokens[$S_TOKEN-1], "")
}
IF POSITION($Tokens[$S_TOKEN-2], "A") > -1 OR POSITION($Tokens[$S_TOKEN-2], "B") > -1 OR POSITION($Tokens[$S_TOKEN-2], "C") > -1 {
$TP_NAME = replace($TP_NAME, " " + $Tokens[$S_TOKEN-2], "")
}
IF POSITION($Tokens[$S_TOKEN-3], "A") > -1 OR POSITION($Tokens[$S_TOKEN-3], "B") > -1 OR POSITION($Tokens[$S_TOKEN-3], "C") > -1 {
$TP_NAME = replace($TP_NAME, " " + $Tokens[$S_TOKEN-3], "")
}
}
}
IF Member($tp.userparameters._keys,"C_Axis") {
${entity('toolpath';$tp.name).UserParameters.C_Axis} = $New_AxisC
IF POSITION($Tokens[$S_TOKEN], "OP") > -1 {
$TP_NAME = replace($TP_NAME, " " + $Tokens[$S_TOKEN], "") + " " + $New_AxisB + " " + $New_AxisC + " " + $Tokens[$S_TOKEN]
} ELSE {
$TP_NAME = $TP_NAME + " " + $New_AxisB + " " + $New_AxisC
}
}
IF $tp.name != $TP_NAME {
RENAME TOOLPATH ; $TP_NAME
CONTINUE
}
STRING Old_AxisB = $entity('toolpath';$tp.name).UserParameters.B_Axis
STRING Old_AxisC = $entity('toolpath';$tp.name).UserParameters.C_Axis
IF $Old_AxisB != $New_AxisB {
$TP_NAME = replace($TP_NAME, $Old_AxisB, $New_AxisB)
${entity('toolpath';$tp.name).UserParameters.B_Axis} = $New_AxisB
}
IF $Old_AxisC != $New_AxisC {
$TP_NAME = replace($TP_NAME, $Old_AxisC, $New_AxisC)
${entity('toolpath';$tp.name).UserParameters.C_Axis} = $New_AxisC
}
IF $tp.name != $TP_NAME {
RENAME TOOLPATH ; $TP_NAME
}
}
MESSAGE INFO "TOOLPATHS MODIFIED"
DIALOGS ERROR ON
DIALOGS MESSAGE ON
Last thing,
How to paste my macro in here with the right format? Should I post it as a picture?
Sincerely,
J.Lacrasse
J.Lacrasse