Macro for isolate hole depth

Macro for isolate hole depth

mrouleau
Contributor Contributor
1,480 Views
4 Replies
Message 1 of 5

Macro for isolate hole depth

mrouleau
Contributor
Contributor

Hello PowerUser

 

I have a macro that I found on the old delcam forum. The macro isolate the diameter and create a new feature set with the diameter

But I want to isolate the depth of EACH feature set.

 

To have something  like:

Ø0.250 X 1.000

Ø0.250 X 2.000

Ø0.250 X 3.000

Ø0.312 X 1.000

Ø0.312 X 2.000

 

 

Here's the original who separate the diameter

 

//
//
//
//
//
Real $FDia = 0.0
Real $FDiaOld = 0.0
String $maxItemsA = ""
String $maxItemsB = ""
String $Prefix = ""
String $CurrName = ""
String $NewName = ""

//
//String $FeatName = ""
//$FeatName = project_pathname (1)


BOOL $err = 1
INT $Counter = 0
EXPLORER SELECT Featureset "Featureset\$FeatureSetName" NEW
RENAME Featureset 1 "MICHEL"
    DO {
        $FDia = 0.0
        //Choisir l'entitée
        If $Counter == "4" {
            Print "Break here..."
        }
        ACTIVATE Featureset "MICHEL"
        $maxItemsA =  entity('featureset','MICHEL').num_items
        //Print Featureset "Featureset\MICHEL.num_items
        //$maxItemsA =  entity('featureset','MICHEL').num_items
        //Print $message
        FORM FEATURESELECT
        EDIT SELECTION DELETE
        EDIT SELECTION TYPE DIAMETER
 
        //DIALOGS MESSAGE OFF
        //DIALOGS ERROR OFF
        
        EDIT SELECTION STORE '$Counter' NEW
        //EDIT SELECTION STORE '1' NEW
        EDIT SELECTION ADD EDIT SELECTION APPLY
        EDIT SELECTION APPLY
        FEATURESELECT CANCEL
        //
        //Maintenant on copie les trous selectionnés à un nouveau FeatureSet
        //
        COPY FEATURESET "MICHEL" SELECTED
        ACTIVATE Featureset "MICHEL_1"
        //
        // Trouver le nombre d'items dans "MICHEL_1"
        // Si le nombre est le même que dans "MICHEL" le programme arrête
        //
        $maxItemsB =  entity('featureset','MICHEL_1').num_items
        
            IF $maxItemsA == $maxItemsB {
                $err = 0
            } ELSE {
                //
                // Store/Print le diamètre de chaque trou
                // Créé une liste vide des REAL
                //
                REAL LIST Diams = {}
                FOREACH f_dia in components(entity('featureset','MICHEL_1')) {
                    // Ajoute le diamètre à la liste
                    $FDia =  f_dia.diameter
                    
                    String s = add_last(Diams, f_dia.diameter)
                    
                }
                
                DIALOGS MESSAGE ON
                DIALOGS ERROR ON
                //
                //Crée une liste qui va retenir tous les noms des diamètre utilisés Jusqu'ici
                //REAL LIST DiamsTotal = {}
                //String s = add_last(DiamsTotal, $FDia)
                //
                $NewName = $Prefix + "Holes-Dia_" + $FDia +"mm"
                //******************************************
                // Vérifier si le nom du featureset existe déjà
                FOREACH fset IN folder('featureset') {
                    $CurrName = $fset.name
                    IF $NewName == $CurrName {
                        //
                        
                        String $prompt = "The name " + $NewName + "  Existe déjà! Vous devez rajouter un préfix"
                        MESSAGE ERROR $prompt
                        $Prefix = INPUT "Entrer un préfix"
                    }

                }
            }
                //
                //
                //*****************************************
                $NewName = $Prefix + "Ø" + $FDia +" arrière"
                IF $FDia != "0.0" {
                    RENAME Featureset "MICHEL_1"  $NewName
                }

        $Counter = $Counter + 1
        
    } WHILE $err
    $FDiaOld = $FDia
    //Ramener l'entité à son nom original
    DIALOGS MESSAGE OFF
    DIALOGS ERROR OFF
    EXPLORER SELECT Featureset "Featureset\MICHEL" NEW
    RENAME Featureset "MICHEL" $FeatureSetName
    DELETE Featureset "MICHEL_1"
    DIALOGS MESSAGE ON
    DIALOGS ERROR ON
Return

 

 

 

 

Tank you

0 Likes
Accepted solutions (1)
1,481 Views
4 Replies
Replies (4)
Message 2 of 5

kukelyk
Advisor
Advisor

Try this:

(I did not test it)

//
//
//
//
//
Real $FDepth = 0.0
Real $FDepthOld = 0.0
String $maxItemsA = ""
String $maxItemsB = ""
String $Prefix = ""
String $CurrName = ""
String $NewName = ""

//
//String $FeatName = ""
//$FeatName = project_pathname (1)


BOOL $err = 1
INT $Counter = 0
EXPLORER SELECT Featureset "Featureset\$FeatureSetName" NEW
RENAME Featureset 1 "MICHEL"
    DO {
        $FDepth = 0.0
        //Choisir l'entitée
        If $Counter == "4" {
            Print "Break here..."
        }
        ACTIVATE Featureset "MICHEL"
        $maxItemsA =  entity('featureset','MICHEL').num_items
        //Print Featureset "Featureset\MICHEL.num_items
        //$maxItemsA =  entity('featureset','MICHEL').num_items
        //Print $message
        FORM FEATURESELECT
        EDIT SELECTION DELETE
        // EDIT SELECTION TYPE DIAMETER
        EDIT SELECTION TYPE DEPTH
 
        //DIALOGS MESSAGE OFF
        //DIALOGS ERROR OFF
        
        EDIT SELECTION STORE '$Counter' NEW
        //EDIT SELECTION STORE '1' NEW
        EDIT SELECTION ADD EDIT SELECTION APPLY
        EDIT SELECTION APPLY
        FEATURESELECT CANCEL
        //
        //Maintenant on copie les trous selectionnés à un nouveau FeatureSet
        //
        COPY FEATURESET "MICHEL" SELECTED
        ACTIVATE Featureset "MICHEL_1"
        //
        // Trouver le nombre d'items dans "MICHEL_1"
        // Si le nombre est le même que dans "MICHEL" le programme arrête
        //
        $maxItemsB =  entity('featureset','MICHEL_1').num_items
        
            IF $maxItemsA == $maxItemsB {
                $err = 0
            } ELSE {
                //
                // Store/Print le diamètre de chaque trou
                // Créé une liste vide des REAL
                //
                REAL LIST Diams = {}
                FOREACH feat in components(entity('featureset','MICHEL_1')) {
                    // Ajoute le diamètre à la liste
                    $FDepth =  feat.depth
                    
                    String s = add_last(Diams, feat.depth)
                    
                }
                
                DIALOGS MESSAGE ON
                DIALOGS ERROR ON
                //
                //Crée une liste qui va retenir tous les noms des diamètre utilisés Jusqu'ici
                //REAL LIST DiamsTotal = {}
                //String s = add_last(DiamsTotal, $FDepth)
                //
                $NewName = $feat.name + "_" + $Prefix + "Holes-Depth_" + $FDepth +"mm"
                //******************************************
                // Vérifier si le nom du featureset existe déjà
                FOREACH fset IN folder('featureset') {
                    $CurrName = $fset.name
                    IF $NewName == $CurrName {
                        //
                        
                        String $prompt = "The name " + $NewName + "  Existe déjà! Vous devez rajouter un préfix"
                        MESSAGE ERROR $prompt
                        $Prefix = INPUT "Entrer un préfix"
                    }

                }
            }
                //
                //
                //*****************************************
                $NewName = $fset.name + $Prefix + "_Depth_" + $FDepth +" arrière"
                IF $FDepth != "0.0" {
                    RENAME Featureset "MICHEL_1"  $NewName
                }

        $Counter = $Counter + 1
        
    } WHILE $err
    $FDepthOld = $FDepth
    //Ramener l'entité à son nom original
    DIALOGS MESSAGE OFF
    DIALOGS ERROR OFF
    EXPLORER SELECT Featureset "Featureset\MICHEL" NEW
    RENAME Featureset "MICHEL" $FeatureSetName
    DELETE Featureset "MICHEL_1"
    DIALOGS MESSAGE ON
    DIALOGS ERROR ON
Return
0 Likes
Message 3 of 5

mrouleau
Contributor
Contributor

macro.jpg

 

nice try, but i'm still stock.

Tank for the time

0 Likes
Message 4 of 5

kukelyk
Advisor
Advisor
Accepted solution

Replace 81th line:

$NewName = $feat.name + "_" + $Prefix + "Holes-Depth_" + $FDepth +"mm"

With:

$NewName = $Prefix + "Holes-Depth_" + $FDepth +"mm"

*edited post:

AND if needed

Replace 99th line: 

 $NewName = $fset.name + $Prefix + "_Depth_" + $FDepth +" arrière"

With:

 $NewName = $Prefix + "_Depth_" + $FDepth +" arrière"

 

0 Likes
Message 5 of 5

mrouleau
Contributor
Contributor

WOW work great, just with a little modification of one ligne.

Still little problem with the rename, but for the rest does exatly what I want

you rock kukelykmacro.jpg

0 Likes