I'm new to API creation. Currently working on a logic to create a group only with freeedge elements.
I'm planning to use
app.feElementFreeEdge ( elemSetID, bParabolicEdges, bLineElem, nFreeCount, nFreeData ).
As a step one, i moved all the elements based on type to group and assigned those elements to elemset.
In step 2, i have the following, but i do not know how to move forward with the output (nfreecount, nfreedata). I appreciate any kind of help
Solved! Go to Solution.
In step 2 you need to get elements from nfreedata, add to set and put in group.
nfreedata has format = (element1, node1A, node2A, element2, node2A, node2B, ...). It means you need to get every third element:
For i = 0 To nfreecount-1 freeElements(i) = nfreedata(i*3) Next
Full example look like this. Bas file is attached:
Tested on small model:
One important moment. I copy all ids first to new array freeElements and then insert into set using AddArray for better performance.
Awesome Yarko. Thanks a lot for the macro. I really appreciate your help
I have a one more request. I'm kind of clueless with this one.
Idea behind this macro is to add only the quad elements with an angle of more than 0 degrees between their planar faces (xy plane) to a group. My ideas..
Determine all the 4 nodes in the quad element. For each of those nodes in the element check to see if they are common to any other elements. -> i dont know how to do this. node.getallarray does not figure elements common to the node. Please recommend any function which can do that.
If a node(n) is common to 3 elements...Check the normals between those elements and see if they match...if they match, send them to a group...if not, move to the next node in that element.
I think my write up is confusing. To put in a simple manner, i'm trying to group the elements on both the sides of a T-joint or L-Joint
Very neat macro.
One quick question to understand the usage...
Do we need this line ---> redim freeelements(nfreedata) ? The first declaration (Dim freelements() as long) should just work fine, right? or Could you please explain the use of this line?
I'll react to your last sentence: trying to group elements on both sides of a T/L joint. This is commonly called 'feature detection' (widely documented on the internet), and is not directly achievable via free edges alone. As you indicate, there is a notion of angle to be measured somewhere.
However the FEMAP developpers have added a very cool function a few versions back, in the Group > Generate command: FEMAP can break 2D models into groups based on angles between adjacent elements AND take into account non-manifold edges (such as T edges). In the API look at 3.13.5 feGroupGenerate2: the "breakAngle" is used to create groups based on this "geometric discontinuity" + the brkNonManifold.
So you're facing 2 approaches:
- you stick with your concept: identifying nodes common to 3 elements. Which means that for X junctions your code wont work for instance... Oh and your code complexity is quite high, which isnt great (many operations for each node on many elements...).
To answer your question about checking "how many elements use a node" you need a set and the AddRule method:
Dim set1 as femap.set
Set set1 = app.feSet
number of elements using this node is set1.count
Rules are a very powerful concept in FEMAP. Checkout the set object and Help > API > 220.127.116.11 Group Selection Rules. These enable you to "select certain entities according to a rule". For example "ELEM_BYNODE" means "I want to fill this set with all elements using this node".
The concept goes one step further with the AddSetRule method: it's the same but applied to a set. So set1.AddRule(set2.id, FGD_ELEM_BYNODE) = "I want to fill this set1 with all elements using any node from this set2". VERY useful
- you generalize the concept. Here are (my suggections for) the steps of your code:
1) isolate 2D elements
2) groupGenerate2 with a breakAngle defined or specified by user
This will generate new groups, so I would recommend tracking the creation of these new groups. Use the trackdata object (thanks FEMAP developpers! API > Help > 4.11)
3) for each newly created group, find free edges, i.e. do as Yarko showed. Voila! you're left with all elements which have an edge on a geometric feature
So something like:
'elSet contains the initial elements you want to deal with 'for example all 2D elements Dim track As femap.TrackData, newGrSet As femap.Set Set track = App.feTrackData Set newGrSet = App.feSet Dim finalFreeEdgeElSet As femap.Set Set finalFreeEdgeElSet = App.feSet Dim brkAngle As Double brkAngle = 18 track.Start(FT_GROUP) App.feGroupGenerate2(elset.ID,True,0,0,0,brkAngle,False,True,False,0) track.Stop track.Created(newGrSet.ID) While newGrSet.Next elset.Clear elset.AddGroup(FT_ELEM,newGrSet.CurrentID) App.feElementFreeEdge(elset.ID,False,False,l1,v1,v2) 'then yarko's concept 'add free edge elems to finalFreeEdgeElSet Wend 'create a final group with all free edge els
PS: regarding ReDim freeelements(nfreedata): it is necessary because 1) VB6 does not automatically dimension arrays to the size you need and 2) VB6 does not allow you to dimension an array to a variable size, i.e. a size defined by a code variable (nfreedata here). so Dim freelements(39) as long is OK for example, but not Dim freelements(nFreeData) as long. So indeed both steps need to be written. Redim is a dynamic statement.
1) Small question: you develop your tools in Femap Api programming window or use some external environment (visual studio for example)?
2) Explanation about freeElements(nfreedata):
'this line decrate array with 0 dimenion. Dim freeElements() As Long 'this line resize array to count of free edge elements ReDim freeElements(nfreecount)
It not possible to declare array freeElements(nfreecount) - gives an error. It expects contant. E.g freeElements(10) will work but we don't know amount of elements, we get that from femap.
3) As I understood you would like to recognize welds in your model. We did recognition of welds in our commercial software. We used element normals to check what angle is between elements:
I will check what is available in API to check angles.
I completely agree with Astrium_tls about:
Oh and your code complexity is quite high, which isnt great (many operations for each node on many elements...).
If you would like to get elements for every nodes using Femap functions it will work very slow.
We use following functions to get nodes and elements using one call to femap: GetAllArray.
Then we arrange it in structures and use own angle checking procedures to have nice performance.
So it's better to follow AP advice.
Thanks for detailed explanation and information. I will start coding per your direction & suggestions. I will update my progress.
I really appreaciate your help!
Thanks a lot,
Yarko, Thanks for your input.
I do agree with the complexity of checking every single element.
You & Astrium saved my time. I will proceed per Astrium's direction and keep you guys updated.
Appreciate your help.