renumber tools

renumber tools

Anonymous
Not applicable
1,436 Views
14 Replies
Message 1 of 15

renumber tools

Anonymous
Not applicable

Hellou !
I have a macro that rearranges the tools that are repeated in the magazine because I have a limitation of 23 tools on the machine.
Today this macro replaces all the tools, even those that are in use, I would like it to rename only those tools that are not being used at the moment; Here is example:

Tools in the database                current macro         HOW I WOULD LIKE

T1 ESF 1                                             T4 ESF 1                                               T1 ESF 1

T2 ESF 2                                              T5 ESF 2                                               T2 ESF 2

T3 ESF 3                                               T6 ESF 3                                               T3 ESF 3

T4 ESF 4                                               T7 ESF 4                                               T4 ESF 4

T10 broca 4,2                                     T1 BROCA 4,2                                    T5 BROCA 4,2

T10 broca 5                                        T2 BROCA 5                                        T6 BROCA 5

T10 broca 6                                         3 BROCA 6                                        T7 BROCA 7

 

…In other words, do not touch the used positions, use empty positions

 

//
// Macro de réorganisation des numéro outils selon limitation magasin
//   Cherche au départ à  modifier les Numéro outils
//   Une fois le magasin rempli va créer un nouveau programme et redémare la numérotation
//   Normalement si ce n'est pas nécessaire ne change pas le numéro de l'outil
//  
//   Limite : les numéros d'outil devrait être tous inférieur aux emplacments disponible pour éviter des erreurs de traitement
//           
//
function main() {
    ECHO OFF DCPDEBUG UNTRACE COMMAND ACCEPT
 // Magasin Size
 INT $SizeMag = 23
 // $SizeMag = INPUT "Entrer la taille du magasin Machine"

 STRING $Name = ''
 STRING $TNameEquiv = ''
 STRING $TName = ''

 INT LIST $Magazin = {}
 STRING LIST $MagazinName = {}
    STRING $Selected_Ncprogram = ''
 
 INT $Nb = 1
 INT $NbT = 0
 INT $T_Nb = 0
 INT $PosM =0
 BOOL $Fnd = FALSE
 BOOL $AddNCProg = FALSE
 
 IF entity_exists(entity('ncprogram','')) {
  $Selected_Ncprogram = entity('ncprogram','').name
 } ELSE {
     MESSAGE ERROR "Aucun programme actif"
  MACRO ABORT
 }
 
 STRING $Msg = "Reorganisation Programme NC : $Selected_Ncprogram Limite : $SizeMag"
    PRINT $Msg
 
 STRING $NewName = $Selected_Ncprogram
 
    ACTIVATE NCPROGRAM $Selected_Ncprogram
 
 FOREACH item IN components(entity('ncprogram',$Selected_Ncprogram)) {
    $Name = $item.name
    ACTIVATE TOOLPATH  $Name
   
    ENTITY $Tp = ENTITY('toolpath',$Name)
       ENTITY $Tl = $Tp.Tool
   
    $TName = $Tl.name
    ACTIVATE TOOL $TName
   
    // Récupération Numéro outil du parcours
    $T_Nb =  $Tool.Number.Value
    // $Tool.Number.UserDefined
   
    /// Si Maqueur de création d'un nouveau fichier NC programme
    /// Change la position des pacours
    IF $AddNCProg == TRUE { 
   EDIT NCPROGRAM  $Selected_Ncprogram TOOLPATH $Name DELETE
   EDIT NCPROGRAM  $NewName APPEND TOOLPATH $Name 
    } ELSE {
   // Mode Analyse des parcours
   // si le numéro est supérieur à la taille ou Nulle
     IF $T_Nb > $SizeMag OR $T_Nb==0 {
      // Recherche emplacement libre   
      CALL RechercheNBLibre(Magazin,$Nb)
     
      $Msg = "Modif A numéro parcours $Name ( $TName ) : $T_Nb  ->  $Nb"
      PRINT $Msg
     
      // Change le numéro
      EDIT TOOL $TName NUMBER COMMANDFROMUI $Nb YES
      $T_Nb = $Nb
   }
  
   // Recherche le Num Outil dans le magasin
   CALL RechercheNB(Magazin, $T_Nb , $PosM)
   
   //--------------------//
      //    Si pas trouvé   //
   //--------------------//
   IF $PosM==0 {
      // rajoute le numéro au magasin
      $NbT = add_last(Magazin, $Tl.number)
      $NbT = add_last(MagazinName, $TName)
     
   //--------------------//
      //     Si Trouvé      //
   //--------------------//
     } ELSE {
    // Si le numéro a été trouvé
    // test si même outil
    
    $TNameEquiv  = $MagazinName[$PosM-1]
    
    IF $TNameEquiv == $TName {
     $Msg = "Même N° $T_Nb  & même outil $TNameEquiv -  $TName Ok!"
     PRINT $Msg   
    } ELSE {
     $Msg = "Même N° $T_Nb  outil différents ->  $TNameEquiv -  $TName !"
     PRINT $Msg
     // Recherche emplacement libre
     CALL RechercheNBLibre(Magazin,$Nb)
     IF $Nb < $SizeMag {
      $Msg = "Modif B numéro parcours $Name ( $TName ) : $T_Nb  ->  $Nb "
      PRINT $Msg
      
      // Change le numéro
      EDIT TOOL $TName NUMBER COMMANDFROMUI $Nb YES
      $T_Nb = $Nb
            
      $NbT = add_last(Magazin,  $T_Nb)
      $NbT = add_last(MagazinName, $TName)
      $Msg = "Ajout B parcours $Name outil $TName ( $T_Nb )"
      PRINT $Msg
     } ELSE {
         $Msg = "Dépassement taille Magasin ( $Nb / $SizeMag ) !"
          PRINT $Msg
      $NbT  = $SizeMag + 1
     }
    }
   }
   IF $NbT <= $SizeMag {
      $Msg = "Ajout pour parcours $Name outil $TName  ( id $NbT ) | N° $T_Nb"
      PRINT $Msg
   } ELSE {
    IF $AddNCProg == FALSE {
     // Creation Nouveau Nom de fichier programme
     CALL NouveauNom($NewName)
     
     CREATE NCPROGRAM $NewName EDIT NCPROGRAM ; QUIT FORM NCTOOLPATH
     NCTOOLPATH CANCEL FORM ACCEPT NCTOOLPATHLIST FORM ACCEPT NCTOOLLIST
     ACTIVATE NCPROGRAM $NewName
     $AddNCProg = TRUE
     MESSAGE WARN "CREATION Nouveau Parcours : $NewName"
    }
    // Rajoute les parcours aux nouveau programme NC
    EDIT NCPROGRAM  $Selected_Ncprogram TOOLPATH $Name DELETE
    EDIT NCPROGRAM  $NewName APPEND TOOLPATH $Name
   }
  }
 }
 // Si on a du ajouter les parcours
 IF $AddNCProg == TRUE {
     // Action récursive sur nouveau NCProgramm
  MACRO RenumeroterOutilNCProg.mac
 } ELSE {
  // Fin de Macro
  RETURN
 }
}
///////////////////////////////////////////////////
// Recherche d'un nouveau nom pour le programme CN
Function NouveauNom(
   OUTPUT STRING NewName
)
{
 // Recherche Nouveau Nom
 DO {
  $NewName= $NewName + "_1"
 } WHILE entity_exists('ncprogram',$NewName)
}
// Recherche si le numéro outil est dans la base
Function RechercheNB(
   INT LIST Magazin
   INT Nb
   OUTPUT INT Found
)
{
INT $Pos = 0
$Found = 0
 FOREACH Id IN Magazin {
     $Pos = $Pos + 1
  IF $Nb == $Id {
   $Found = $Pos
   RETURN
  }
 }
}
// Recherche un emplacment libre
Function RechercheNBLibre(
   INT LIST Magazin
   OUTPUT INT New
)
{
INT $Nb = 0
INT $PosM=0
   DO {
    $Nb = $Nb + 1
    CALL RechercheNB(Magazin, $Nb , $PosM)
      } WHILE $PosM  > 0
   $New=$Nb
}

 

 

 

0 Likes
1,437 Views
14 Replies
Replies (14)
Message 2 of 15

5axes
Advisor
Advisor

??? this macro doesn't rename any tool , it just change the toolnumber in a NCprogram according to the limits of the magazin.  I know it because I wrote it  and I'm using it for my own needs. And normally it doesn't change a Tool number if you don't need to change it ...   The only limitation is written in the heading lines :

 

//   Limite : les numéros d'outil doivent être tous inférieur aux emplacements disponible pour éviter des erreurs de traitement

That means in good english : the default tool number must be smaller than the magazin size , otherwise and especialy if it's the case on the first tool, the macro will change the tool number to 1 for the first tool and then it will be oblige to change every tool number. But in a normal use of this macro you should not have to change the number if it's not necessary. 

0 Likes
Message 3 of 15

Anonymous
Not applicable

Hello 5axes!
Yes it was you who wrote the macro in another forum! and I'm limiting the size of the magazine, but I did the test again and it renumbers the tools that are in use it should renumber by numbers that are not being used at the moment

0 Likes
Message 4 of 15

5axes
Advisor
Advisor

You should add to your post a small sample project, because it's not normal and you are certainly in a situation which creates such result.

0 Likes
Message 5 of 15

Anonymous
Not applicable



 

0 Likes
Message 6 of 15

5axes
Advisor
Advisor

Ok ..

First of all the macro works as it is suppose to work because it' not only a change of the tool number , but if the number of tool exceed the place in the magasin it split the ncprogram into different NCprogram. That's why If i need to change a Toolnumber I always start from a low number.

 

0 Likes
Message 7 of 15

5axes
Advisor
Advisor

 

 

Ok ..

First of all the macro works as it is suppose to work because it' not only a change of the tool number , but if the number of tool exceed the place in the magasin it split the ncprogram into different NCprogram. That's why If i need to change a Toolnumber I always start from a low number.

 

 

0 Likes
Message 8 of 15

5axes
Advisor
Advisor

 

 

Ok ..

 

First of all the macro works as it is suppose to work because it' not only a change of the tool number , but if the number of tool exceed the place in the magasin it split the ncprogram into different NCprogram. That's why If i need to change a Toolnumber I always start from a low number.

Result1.jpg

 

 

But .. we can improve it.

 

Result2.jpg 

This is the new result with a Magasin list initialisation. I’m not exactly sure of the result. But it seem's to work also when It split the NCprogram into two.

 

 

We will have a problem if a tool number cannot be change for a tool placed in the first position of the ncprogram. In this case the result will be a split in unnecessary small NCprogram. But In this case I don’t have a solution except to go back to the first version.

 

 

 

 

 

0 Likes
Message 9 of 15

Anonymous
Not applicable

ok, but it will be we can do as I need

0 Likes
Message 10 of 15

5axes
Advisor
Advisor

Nothing to do with your request but I have notice that some of your holder have a strange definition in your project. If you want to modify these holders , I have a Macro also for That :

 

EditHolder.gif

  First of all change Your Holder in one tool definition like that

Replace.jpg

Then you can run the following macro , it will change every holder of your project which have the same name :

//
// Met à jour le porte outil pour tous les outils du projet
// Sauvegarde le porte-outil de reference ( porte outil outil actif)  dans un fichier DGK tempo
// Remplace ensuite les portes-outils avec le même nom
//

INT $Counter = 0
STRING $Msg = ''
STRING $ToolName = ''

STRING $HoldernameToReplace = entity('tool','').HolderName

STRING ShowPlease = "Voulez-vous mettre à jour tous les porte-outils  :" + $HoldernameToReplace

BOOL $carryon = 0
$carryon = QUERY $ShowPlease					
if $carryon {
					
EXPORT TOOLHOLDER ; FILESAVE "C:\TEMP\HolderTempo.dgk"
YES

$Msg = "Holder : " + $HoldernameToReplace
PRINT $Msg

INT $Nb = 0
FOREACH tl IN FOLDER('tool') {
   $ToolName = $tl.name
   STRING $HName = $tl.HolderName
   IF $HName==$HoldernameToReplace {
     EDIT TOOL $ToolName HOLDER_CLEAR
     EDIT TOOL $ToolName IMPORT_HOLDER FILE "C:\TEMP\HolderTempo.dgk"
     EDIT TOOL $ToolName HOLDER_NAME $HoldernameToReplace
     YES
     $counter = $counter + 1
   }
}

DELETE FILE "C:\TEMP\HolderTempo.dgk"

MESSAGE INFO "Remplacement de $counter porte-outil(s)"
}
0 Likes
Message 11 of 15

Anonymous
Not applicable

Thanks a lot 5 axes, for the macro was very good, but I did not understand, the support macro

0 Likes
Message 12 of 15

5axes
Advisor
Advisor

By the "support macro" you means the previous one, to update your holder in your tool List ?

0 Likes
Message 13 of 15

Anonymous
Not applicable

yes!

0 Likes
Message 14 of 15

5axes
Advisor
Advisor

In your sample project you have a lot of tool, and on my point of view some holders doesn't have a correct design.  You can have for some of them a very complexe definition , and some are correct. But you have define the holder cone, so if one day you decide to use the machine simulation you will see that it's not correct :outils2.jpg

 

 So the idea is to use a macro to modifiy every holder based on a correct design . If I take the example of the "BROCA" tools which used the holder "MANDRIL"  it's in this case 40 tool to modify. It's a long and ungrateful job. So if one day you decide to clean your Tool library you can use this macro.

 

Step 1 : Activate one tool to modify

Step 2 : Modify the holder but keep the same name for the holder

Step 3 : Launch the macro , every tool with the same Holder name will be modify with the new design.

Note : A Temporary  DGK file is created in the C:\temp folder, so modify the macro if you don't have this folder on your PC.

 

 

 

 

 

0 Likes
Message 15 of 15

Anonymous
Not applicable

Thanks 5 axes, now I understood the macro very good

0 Likes