How to use Knowledge Expert to automatically name holes according to specification

96 views
Skip to first unread message

srikanth vadapalli

unread,
Oct 17, 2013, 5:28:19 AM10/17/13
to catiat...@googlegroups.com

Introduction



I will explain how to use Knowledge Expert Rules to automatically set the names of holes according to specification.

By default holes are named generically. 

 

In this example each hole is to be assigned a unique name in each body according to it's specification. 

For example the simple 15mm diameter 50mm deep Hole.3 is to be renamed  "HOLE_D15x50.1". 

The two M16 Threaded holes are to  be renamed "M16x1.5x50.1" and "M16x1.5x50.2". 

The For-Each statement


Expert Rules work by inspecting the objects types specified in the "For Each" statement.  In this case I want to look for every hole in each body. The "For Each" statement then needs to look for Bodies. in KBE language the type for a Body is call BodyFeature. 

For Each: PB:BodyFeature

Finding The Holes


To find the holes inside a body a Query function is used. The Query function operates on a feature. It takes two arguments and returns a List of child features found inside the inspected feature.  

The first argument of the Query function is the type name to look for. That will be "Hole". 

The second argument is the qualifier statement. The qualifier statement a logical expression in which attributes of a candidate feature can be inspected. If the statement evaluates as true for the child feature being inspected, the child feature is included in the returned list. For this first rule I want only want simple holes that are not threaded. The Hole type have attributes "HoleType" which is a string and "Threaded" which is a Boolean. So my Query statement will look like this:

let holes (List)

holes = PB ->Query("Hole","x.Threaded==false and x.HoleType == \"Simple\"")


Counting and Naming the holes



Description of algorithm:

  • There will be two lists. One for keeping track of names and one for keeping track of how many for each name.
  • The holes are looped through.
  • A name is proposed for the hole.
  • The list of existing names is checked
  • If the name is not found the name is added to the former list and the count 1 is added to the latter. 
  • If the name is found, the corresponding item in the counts list is incremented by 1.
  • Once the name and count are determined for the hole it is renamed and the loop goes on to the next hole.

Here is the code for the rule:

(For Each: PB:BodyFeature)

let names(List)
let counts (List)
let holes (List)
let hole (Hole)
let name (String)
let indx (Integer)
let cnt (Integer)

/* get all simple, non-threaded holes */
holes = PB ->Query("Hole","x.Threaded==false and x.HoleType == \"Simple\"")

for hole inside holes
{    
/* propose a name */
    name = "D" + ToString( hole.Diameter ) + "x" + ToString(hole.Depth)

/* remove mm and in from the name (inch or metric do it twice because it's in there twice ) */
    name = ReplaceSubText(name,"mm","")
    name = ReplaceSubText(name,"mm","")
    name = ReplaceSubText(name,"in","")
    name = ReplaceSubText(name,"in","")

/* check if the name is in the names list */
    indx = names->IndexOf(name,1)

/* it is there so increment the count */
    if indx > 0
    {
        cnt = counts->GetItem(indx)
        cnt = cnt + 1
        counts->SetItem(cnt,indx)
    }
/* it is not there so add it to the list */
    else
    {
        names->Append(name)
        cnt = 1
        counts->Append(cnt)
    }
/* rename the hole */
    hole.Name = "HOLE_" + name + "." + ToString(cnt)
}

Naming a Threaded hole



Naming threaded holes is much the same except the Query statement will look for threaded holes:

holes = PB ->Query("Hole","x.Threaded==true and x.HoleType == \"Simple\"")

And the Thread Description attribute will be used. 

The Thread Description attribute of a hole is not shown in the Language Browser panel.






 But it can seen in the formula editor as a sub-parameter of the hole. 





To get this attribute, we can use the GetAttributeString function.

So the name statement becomes 

name =  hole->GetAttributeString("`Thread Description`") + "x" + ToString(hole.Depth)

Results

This is what the rulebase looks like




Solving the rulebase on the part the holes are renamed as expected



Discussion



The renaming could also be done using standard KWA Rules. But it would take one rule per Body.  Using Knowledge Expert (KWE) the rulebase doesn't have to be inside of the part being renamed. It can be solved on any part using "Use Only"  from a catalog.
 
Reply all
Reply to author
Forward
0 new messages