Replace axis value in toolpath

Replace axis value in toolpath

j.lacrasse
Advocate Advocate
1,024 Views
9 Replies
Message 1 of 10

Replace axis value in toolpath

j.lacrasse
Advocate
Advocate

Hello all,

I reached my macro limit at this point and I'd like some guidance.
What I'd like to achieve is replacing my axis value (B and C) in my toolpath and change is with a new one whitout having to tell the macro which value to replace.

 

What I do is, I setup my machine tool and my origin, that I start the macro.
My toolpath looks like : #1 - T25 - COMP SEMI Ø1.0085 B90 C30 OP33

 

DIALOGS ERROR OFF
DIALOGS MESSAGE OFF

//STRING $New_Name = ""
ENTITY LIST Toolpaths = INPUT ENTITY MULTIPLE TOOLPATH "Choose toolpaths to rename B and C axis"

STRING ARRAY $Axes[] = {"B","C"}
INT LIST $Axes_Choices = INPUT CHOICE MULTIPLE $Axes "Choose which axes to add in the toolpath"

STRING Old_Name = INPUT "Que voulez-vous remplacer?"
//STRING New_Name = INPUT "Par quoi voulez-vous le remplacer?"

FOREACH $tp IN $Toolpaths {
ACTIVATE TOOLPATH $tp.Name
REAL axisB = round(machine().B, 4)
REAL axisC = round(machine().C, 4)
STRING New_AxisB = "B" + "$axisB"
STRING New_AxisC = "C" + "$axisC"

FOREACH $Axes IN $Axes_Choices {
IF $Axes == 0 {
STRING NewNameB = replace(Name, '$Old_Name', '$New_AxisB')
RENAME TOOLPATH ; $NewNameB
} ELSEIF $Axes == 1 {
STRING NewNameC = replace(Name, '$Old_Name', '$New_AxisC')
RENAME TOOLPATH ; $NewNameC
}
}
}
DIALOGS ERROR ON
DIALOGS MESSAGE ON

MESSAGE INFO "TOOLPATHS MODIFIED"

 

Cheers,

J.lacrasse

J.Lacrasse
0 Likes
Accepted solutions (1)
1,025 Views
9 Replies
Replies (9)
Message 2 of 10

rafael.sansao
Advisor
Advisor

Userparameters should be a good idea.

The only problem is the toolpaths that already contain B and C in the name.

 

ENTITY LIST Toolpaths = INPUT ENTITY MULTIPLE TOOLPATH "Choose toolpaths to rename B and C axis"
FOREACH $tp IN $Toolpaths {
	ACTIVATE TOOLPATH $tp.name
	STRING TP_NAME = $tp.Name
	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
		$TP_NAME = $TP_NAME + " " + $New_AxisB
	}
	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
		$TP_NAME = $TP_NAME + " " + $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"

Rafael Sansão

OptiNC - www.optinc.tech

EESignature

0 Likes
Message 3 of 10

j.lacrasse
Advocate
Advocate

Hi Rafael,

It seems to work great. But... I'd like the B and C to be written before all my OP. 

All my toolpaths end with OP1, OP2, etc...

Lastly, if there is any A,B or C axis already in my toolpath name, how can I erase/replace with the new axis without erasing something else?

Sincerely,

J.Lacrasse

J.Lacrasse
0 Likes
Message 4 of 10

rafael.sansao
Advisor
Advisor

Try this:

ENTITY LIST Toolpaths = INPUT ENTITY MULTIPLE TOOLPATH "Choose toolpaths to rename B and C axis"

FOREACH $tp IN $Toolpaths {
	ACTIVATE TOOLPATH $tp.name
	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 $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"

Rafael Sansão

OptiNC - www.optinc.tech

EESignature

0 Likes
Message 5 of 10

j.lacrasse
Advocate
Advocate

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
0 Likes
Message 6 of 10

rafael.sansao
Advisor
Advisor

The first section of the macro clears the old values and inserts the user parameters for control.

	ACTIVATE TOOLPATH $tp.name
	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 $tp.name != $TP_NAME {
		RENAME TOOLPATH ; $TP_NAME
		CONTINUE
	}

The second section of the macro uses the user parameters to override the exists values.

	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
	}	

Both sections are required!

User parameters will only exist if you run this macro. If you use another macro to rename the toolpaths, you must delete the user parameters (using this other macro)

 

Rafael Sansão

OptiNC - www.optinc.tech

EESignature

0 Likes
Message 7 of 10

j.lacrasse
Advocate
Advocate

Hi Rafael,

 

could you tell me why it doesn't work than?

Cheers,

J.Lacrasse 

 

 

J.Lacrasse
0 Likes
Message 8 of 10

j.lacrasse
Advocate
Advocate

 

 

 

J.Lacrasse
0 Likes
Message 9 of 10

rafael.sansao
Advisor
Advisor
Accepted solution

The toolpath is not renamed because you changed the name manually.
To force data updates, try this:

ENTITY LIST Toolpaths = INPUT ENTITY MULTIPLE TOOLPATH "Choose toolpaths to rename B and C axis"

FOREACH $tp IN $Toolpaths {
	ACTIVATE TOOLPATH $tp.name
	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 $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 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
	}
}
MESSAGE INFO "TOOLPATHS MODIFIED"

Rafael Sansão

OptiNC - www.optinc.tech

EESignature

0 Likes
Message 10 of 10

j.lacrasse
Advocate
Advocate

Hi @rafael.sansao

Thank you very much for your help.

Cheers,

J.Lacrasse

J.Lacrasse
0 Likes