Macro : Auto sorting holes by diameter into separate feature sets

Anonymous

Macro : Auto sorting holes by diameter into separate feature sets

Anonymous
Not applicable

Does anyone have a macro that can automate the process of extracting, sorting and grouping holes by diameter into separate named hole feature sets? Or how I would create a maco to achieve this?

 

Any help would be greatly appreciated.

0 Likes
Reply
Accepted solutions (1)
1,618 Views
6 Replies
Replies (6)

TK.421
Advisor
Advisor

@Sean570  is this similar to yours


the numbers never lie
0 Likes

Anonymous
Not applicable
Accepted solution

STRING LIST $mymodels = extract(FOLDER('model'),'name')
INT c = INPUT CHOICE $mymodels "SELECT MODEL"
STRING selectedmodel = $mymodels[$C]
EDIT MODEL ALL DESELECT ALL
EDIT MODEL $selectedmodel INTERACTIVE
EDIT MODEL $selectedmodel SELECT ALL

TOOLBAR COMMANDBAR RAISE

CREATE FEATURESET ;
EXPLORER SELECT Featureset "Featureset\1" NEW
ACTIVATE FEATURESET "1" EDIT FEATURECREATE TYPE HOLE EDIT FEATURECREATE CIRCULAR ON EDIT FEATURECREATE FILTER HOLES EDIT FEATURECREATE TOPDEFINE ABSOLUTE EDIT FEATURECREATE BOTTOMDEFINE ABSOLUTE FORM CANCEL FEATURE FORM CREATEHOLE
EDIT FEATURECREATE HOLES COMPOUND OFF
EDIT FEATURECREATE HOLES FIXED ON
EDIT FEATURECREATE HOLES DIRECTION DOWN
EDIT FEATURECREATE MULTAX ON
EDIT FEATURECREATE HOLES OPEN OFF
EDIT FEATURECREATE HOLES CAPPED INCLUDE
EDIT FEATURECREATE HOLES EDITONAPPLY NO
EDIT FEATURECREATE CREATEHOLES
EDIT FEATURESET ; DESELECT ALL
FORM FEATURESELECT
EDIT SELECTION TYPE DRAFT_ANGLE
EDIT SELECTION FILTER DRAFT_ANGLE MIN " 10"
EDIT SELECTION APPLY
FEATURESELECT CANCEL
DELETE FEATURESET SELECTED
FEATURESELECT CANCEL
FORM CANCEL CREATEHOLE

 

BOOL $err = 0
$err = ERROR $entity("Featureset","").Name

IF $err {
MESSAGE WARN "ACTIVATE A FEATURESET"
RETURN
}

ENTITY $sourceFeatureset = $entity("Featureset","")

EDIT FEATURESET ; DESELECT ALL

REAL LIST diameters = {}

FOREACH $f IN components($sourceFeatureset) {

IF NOT member($diameters,$f.Diameter) {
INT $i = add_last($diameters,$f.Diameter)
}
}

FOREACH $d IN $diameters {

STRING $featuresetName = "DIAMETER "+$d

IF NOT $entity_exists("Featureset",$featuresetName) {
CREATE FEATURESET $featuresetName
}

ACTIVATE FEATURESET $sourceFeatureset
EDIT FEATURESET ; DESELECT ALL

FOREACH $f IN components($sourceFeatureset) {

IF $f.Diameter == $d {
EDIT FEATURESET ; SELECT $f.Name
}
}

EDIT FEATURESET $featuresetName INSERT FEATURESET ; LAST
}

DELETE Featureset "1"

TOOLBAR COMMANDBAR LOWER

EXPLORER SELECT Featureset ROOT
DEBUG EXPLORER KEY RIGHT

Sean570
Advocate
Advocate

Mine is actually not similar to this at all; however, I decided to quick make one that would sort the holes out.

This takes the active featureset and puts all the holes in separate featuresets named after the diameter. 

 

FUNCTION MAIN() { 

    // Remember the name of the currently active featureset
    STRING ActiveFeatureset = ''
    IF ENTITY_EXISTS($entity('featureset', '')) {
        $ActiveFeatureset = $entity('featureset','').name
    } ELSE {
        MACRO PAUSE "Please activate a featureset."
    }

    // Sort active featureset by diameter
    EDIT FEATURESET $ActiveFeatureset SORT "diameter"

    // Initiate some variables
    REAL LastFeatDia = 0
    STRING LastFeatName = ""
    STRING newfset = ""
    STRING fsetName = ""
    STRING ActiveFeat = ""

    // Loop through active featureset creating new featuresets upon encountering a different diameter
    // If diameter is the same as the last diameter, add to that featureset
    FOREACH $feat IN components($entity('featureset','')) {
        EDIT FEATURESET ; DESELECT ALL
        EDIT FEATURESET ; SELECT $feat.name
        REAL dia = $feat.Diameter
        $ActiveFeat = "Featureset\"+$ActiveFeatureset+"\"+$feat.name
        IF $LastFeatDia == $dia {
            ACTIVATE Featureset $fsetName
            EDIT FEATURESET $newfset MOVE_FEATURE ITEM $ActiveFeat AFTER $LastFeatName
        } ELSE {
            $newfset = "Featureset\"+$dia+" Holes"
            $fsetName = $dia+" Holes"
            $LastFeatName = $feat.name
            IF ENTITY_EXISTS($entity('featureset', $fsetName)) {
                $fsetName = NEW_ENTITY_NAME('featureset', $fsetName)
            }
            CREATE FEATURESET $fsetName
            EDIT FEATURESET $newfset MOVE_FEATURE ITEM $ActiveFeat FIRST
        }
        $LastFeatDia = $dia
        ACTIVATE Featureset $ActiveFeatureset
    }

    // Delete original featureset
    DELETE FEATURESET $ActiveFeatureset
}

Check it out and let me know if it's what you need.

Anonymous
Not applicable

Thank you all for your input certainly have saved me a fair bit of time manually sorting holes. 

My final question is if it possible to sort them into different feature sets of a certain size range, I get the occasional model where the holes are ever so slightly different sizes by +/-0.001 mm for example so they seem to end up in their own feature sets when in reality they should be considered the same size. 

 

If it can be done that would be great but not to worry much if that is asking too much from you guys 😊

0 Likes

siwalker
Contributor
Contributor

Hi just came across this thread looking for a similar thing. As the user above asked, how would you go about sorting the holes into feature sets with certain diameter ranges, rather than into their precise diameter?

0 Likes

kevin.hammond3WX4X
Advocate
Advocate

Hi,

Use something like this, create a featureset, leave it named as 1.

create a macro using code below, this will select features based on Min size - Max size, then copy the selection to a new featureset, which your can then rename accordingly, this can be re-created for as many size ranges as you need.

 

 

EXPLORER SELECT Featureset "Featureset\1" NEW
ACTIVATE Featureset "1"
FORM FEATURESELECT
EDIT SELECTION CLEAR EDIT SELECTION APPLY
EDIT SELECTION FILTER TOLERANCE "0.001"
EDIT SELECTION FILTER DIAMETER MIN " 8.10"
EDIT SELECTION FILTER DIAMETER MAX " 8.10"
EDIT SELECTION APPLY
FEATURESELECT CANCEL
COPY FEATURESET "1" SELECTED

 

 

Hope this helps

Regards Kevin