Drilling Method & Macro

Drilling Method & Macro

5axes
Advisor Advisor
4,464 Views
11 Replies
Message 1 of 12

Drilling Method & Macro

5axes
Advisor
Advisor

It seems that I have more questions than answers today Smiley Frustrated

 

I am looking for examples of creation or manipulation of drilling method with the macro language. I'm looking in particular away to list all the PROCESS and STRATEGY defines in a drilling method.

DrillingMethod.jpg

 

We can visualize the info with the variable $Method.xml (PRINT $ Method.xml) .. But how to access these informations (simply) ?

 

@kukelyk, @ondrej.mikulec  ?  Any experience with such type of code ?

0 Likes
Accepted solutions (3)
4,465 Views
11 Replies
Replies (11)
Message 2 of 12

kukelyk
Advisor
Advisor

Do You mean building up a new method thru macro?

Or editing an imported (ptf) method?

Is it possible to store template in xml? And do You want to parse xml with macro?

0 Likes
Message 3 of 12

5axes
Advisor
Advisor

The request is to Edit An existing method.

 

And for that the first step is analyse the list of process and strategy already define in this method.   The only access to the list is via the variable $Method.xml  of prehap's an other solution  ( component , member ??? )  I don't know. If the only solution would be to parse the XML code , I want to do it via Macro function. 

 

Have you already done something like that ?

0 Likes
Message 4 of 12

5axes
Advisor
Advisor

Begining of solution:

 

//---------------------------------------------------------------------------------------------------
// Macro à lancer depuis un menu utilisateur toolpath.xml
//
// Analyse Drilling Method
//
//---------------------------------------------------------------------------------------------------
// <?xml version="1.0" ?>
//<menupage>
//   <button command='MACRO "Liste_Methode" "%s"' label="Liste Methode" multiple_selection="allowed"/>
//</menupage>
//---------------------------------------------------------------------------------------------------
// Variable $Selected_Toolpath parcours d'outil sélectionné
//---------------------------------------------------------------------------------------------------
Function Main(
STRING $Selected_Toolpath
)
{
// Variable
STRING $Msg = ''

ECHO OFF DCPDEBUG UNTRACE COMMAND ACCEPT

ENTITY $Ent=$entity('toolpath',$Selected_Toolpath)
STRING $PNAME = $Ent.NAME
ACTIVATE TOOLPATH $PNAME FORM TOOLPATH

BOOL $Op_ON = FALSE
STRING $Methode_Name =''
STRING $Op_Name =''

// test si le parcours est bien un parcours Method
if $Ent.strategy == 'method' {

        $Msg = "Drilling Method  : " + $PNAME
    	PRINT $Msg
		
		// Get the XMl DEFINITION
		STRING XML_Def = $Method.xml
		STRING LIST $XMLLigne = TOKENS($XML_Def, crlf)
		
		// FOREACH LINE
		FOREACH $Ligne IN $XMLLigne { 
		    // NEw Method
		    IF POSITION($Ligne,'method name') > 0 {
			    CALL Extract_XML_Name($Ligne,1,$Methode_Name)
				PRINT $Methode_Name
				EDIT METHOD PROCESS $Methode_Name CHOOSE NEW
			}
		    IF POSITION($Ligne,'<drill_operation>') > 0 {
				$Op_ON=TRUE
			}
		    IF POSITION($Ligne,'</drill_operation>') > 0 {
				$Op_ON=FALSE
			}
			// IN Operation
		    IF POSITION($Ligne,'string_value name="label"') > 0 AND $Op_ON  {
			    CALL Extract_XML_Name($Ligne,3,$Op_Name)
				$Msg = "   |-  " + $Op_Name
				PRINT $Msg
				EDIT METHOD PROCESS $Methode_Name STRATEGY $Op_Name CHOOSE NEW
				MACRO PAUSE $Methode_Name + CRLF + $Op_Name
			}
		}
} 

}
/////////////////////////////////////////////////////////////////////////////////
//                        Sous programmes
/////////////////////////////////////////////////////////////////////////////////
//-----------------------------------------------------------------------------------------------
// Extract Name XML
//----------------------------------------------------------------------------------------------
FUNCTION Extract_XML_Name(
	STRING $XML_Ligne
	INT $Pos 
	OUTPUT STRING $NAme
	)
{
    STRING $XML_L = REPLACE($XML_Ligne,'"','|')
	STRING LIST $XMLTag = TOKENS($XML_L, '|')
	$NAme = $XMLTag[$Pos]
}
Message 5 of 12

5axes
Advisor
Advisor
Accepted solution

New Update ...

 

XML Solution seems to work .. New release of the macro . 

 

A) List the Methods, Operations, Tool  

B) Check if the tool exists in the current project

C) Update the Feedrate / Sindle   with the roughing.general conditions define in the tool conditions

 

Methode.jpg

 

//---------------------------------------------------------------------------------------------------
// Macro à lancer depuis un menu utilisateur toolpath.xml
//
// Analyse Drilling Method
//
//---------------------------------------------------------------------------------------------------
// <?xml version="1.0" ?>
//<menupage>
//   <button command='MACRO "Liste_Methode" "%s"' label="Liste Methode"/>
//</menupage>
//---------------------------------------------------------------------------------------------------
// Variable $Selected_Toolpath parcours d'outil sélectionné
//---------------------------------------------------------------------------------------------------
Function Main(
STRING $Selected_Toolpath
)
{
// Variable
STRING $Msg = ''
STRING $Cmd = ''
STRING $filename = "C:\temp\Methode.txt"

ECHO OFF DCPDEBUG UNTRACE COMMAND ACCEPT

ENTITY $Ent=$entity('toolpath',$Selected_Toolpath)
STRING $PNAME = $Ent.NAME
ACTIVATE TOOLPATH $PNAME FORM TOOLPATH

BOOL $Op_ON = FALSE
STRING $Methode_Name =''
STRING $Op_Name =''
STRING $Op_Tool=''
// Log File
TRACEFILE OPEN $filename 

// test si le parcours est bien un parcours Method
if $Ent.strategy == 'method' {
        
        $Msg = "Drilling Method  : " + $PNAME
    	PRINT $Msg
		
		// Get the XMl DEFINITION
		STRING XML_Def = $Method.xml
		STRING LIST $XMLLigne = TOKENS($XML_Def, crlf)
		
		// FOREACH LINE
		FOREACH $Ligne IN $XMLLigne { 
		    // NEw Method
		    IF POSITION($Ligne,'method name') > 0 {
			    CALL Extract_XML_Name($Ligne,1,$Methode_Name)
				PRINT $Methode_Name
			}
			// NEw Drill Operation
		    IF POSITION($Ligne,'<drill_operation>') > 0 {
				$Op_ON=TRUE
			}
			// IN Operation
		    IF POSITION($Ligne,'string_value name="label"') > 0 AND $Op_ON  {
			    CALL Extract_XML_Name($Ligne,3,$Op_Name)
				$Msg = "   |-  " + $Op_Name
				PRINT $Msg
			}
			// Outil
		    IF POSITION($Ligne,'string_value name="Tool"') > 0 AND $Op_ON  {
			    CALL Extract_XML_Name($Ligne,3,$Op_Tool)
			}
			
			// OPERATION AT THE END OF THE OP DEFINITION	
		    IF POSITION($Ligne,'</drill_operation>') > 0 {
				$Msg = "        +- ( " + $Op_Tool + " )"
				PRINT $Msg
				
				IF ENTITY_EXISTS('Tool',$Op_Tool) {
				    ENTITY $Tl=entity('Tool',$Op_Tool)
					REAL $S = (1000 * $Tl.CuttingSpeed.roughing.general) / (3.141516*$Tl.diameter)
					REAL $F = $S * $Tl.FeedPerTooth.roughing.general * $Tl.diameter * $Tl.NumberOfFlutes
					IF  $S >0 OR $F > 0 {
						$Msg = "        +- ( S" + ROUND($S,0) + " F" + ROUND($F,0) + ")"
						PRINT $Msg
						
						EDIT METHOD PROCESS $Methode_Name CHOOSE NEW
					    EDIT METHOD PROCESS $Methode_Name STRATEGY $Op_Name CHOOSE NEW
					    $Cmd = "EDIT METHOD ; PROCESS ; STRATEGY ;  STRING 'FeedRate.Cutting.Value' '" + ROUND($F,0)  + "'"
					    DOCOMMAND $Cmd
					    $Cmd = "EDIT METHOD ; PROCESS ; STRATEGY ;  STRING 'SpindleSpeed.Value' '" + ROUND($S,0) + "'"
					    DOCOMMAND $Cmd
					}
				} ELSE {
					MESSAGE INFO "Outil non existant : $Op_Tool" 
					    $Msg = "         +-  !!!! Outil non existant :" + $Op_Tool
						PRINT $Msg
				}			
				$Op_ON=FALSE
		}
		
		DRILL CANCEL
		METHOD CANCEL
	} 

	TRACEFILE CLOSE
	MACRO PAUSE "Fichier " + $filename
	// OLE FILEACTION 'open' $filename
} // Fin du IF

}
/////////////////////////////////////////////////////////////////////////////////
//                        Sous programmes
/////////////////////////////////////////////////////////////////////////////////
//-----------------------------------------------------------------------------------------------
// Extract Name XML
//----------------------------------------------------------------------------------------------
FUNCTION Extract_XML_Name(
	STRING $XML_Ligne
	INT $Pos 
	OUTPUT STRING $MName
	)
{
    STRING $XML_L = REPLACE($XML_Ligne,'"','|')
	STRING LIST $XMLTag = TOKENS($XML_L, '|')
	$MName = $XMLTag[$Pos]
}
Message 6 of 12

5axes
Advisor
Advisor

Step By Step

 

Analyse one selected method :

  • Looking for exiting tool in the current project , if there is no existing tool with the same name search in the current Tool Library to avoid  the creation of replacement tool on the drilling method execution.
  • Liste the selection criteria of the processes
  • And create a log File.

 

I still have an issue in some case , if the method contain information like the "edit history" of a toolpath added to a process. In this case the  variable $Method.xml is not complet. One test at the begining try to detect this error. The only solution in this case is to edit the original *.ptf file and delete manually these type of informations. If someone can find a solution It will be cool to post here the solution.

 

Regards,

 

0 Likes
Message 7 of 12

danmic7JH66
Advocate
Advocate

Correct me if I'm wrong but doesn't Powermill already check if the tool in the method exists and then if it doesn't, searches the database for a matching tool? That's how all of my drilling methods are set up.

0 Likes
Message 8 of 12

5axes
Advisor
Advisor

hello @danmic7JH66

 

Yes you are right ... The drilling method use the name of the tool registered in the process. Then it use the tool of the current Project if the tool with the same name exists, If it's not the case check in the Tool Library  if the tool exists. If it's positive import this tool.

And if no tool match with the given name , then a new tool is created with the same name but with a dummy definition. So you need to modify this tool.

 

If it's a complex drilling method a lot of tool can be automatically added to your project. And as the name of the tool match with your usual name it's hard to know directly if it's an imported tool , a new created. And If you have spend a lot of time to create these drilling methods and you decide to change a tool , or just the designation of the tool it's a night mare to valide all these methods.

 

 

So the goal of the previous code is to check before to launch the method if every tool needed to run the method are A) present in the project or B) Exists in the Library .

 

It's just an example code. The final idea is to have a marco that allows me to have a complete analysis of the tools / conditions of selection / cutting conditions to get to validate more quickly these cr.p methods Smiley Mad

 

 

 

0 Likes
Message 9 of 12

danmic7JH66
Advocate
Advocate

Ah, ok I understand now.

0 Likes
Message 10 of 12

5axes
Advisor
Advisor
Accepted solution

Step by Step  still a small step

 

New version with new analyze :

  • Test if space  are present at the beging or end of the tool name 
  • Test if machining conditions are fixed in operation
  • Test if tool diameter and tool diameter in operation are different
  • Displays the Drill finishing conditions of the tool if they are defined
Message 11 of 12

5axes
Advisor
Advisor
Accepted solution

2019  and someone have change the format of the $Method.xml data Smiley Sad

So a huge work to validate these macros Smiley Sad Smiley Sad

Message 12 of 12

rafael.feier
Participant
Participant
Read the xml code previously is the only way to access and edit a drilling method via macro?

My only need is to edit some selection criteria for one or more processes of an existing method. For example, I would like to add a maximum depth value filter...

I'm still hoping for a simpler solution and would appreciate you sharing your experience with this topic.

0 Likes