Femap API code, Groups from Layers
Femap API code, Groups from Layers
(OP)
Hi All,
First I'd like to say hello to everyone. This is my first post here.
Would you kindly advise what is wrong with this piece of code?
Working with Femap 11.
I try to create groups based on information from layers. I started from surfaces and found incomprehensible problem at once.
API creates groups but somehow it summing up surfaces IDs from previous step. Looks like clear function is ignored but no. IDs listed in each step are correct.
For single layer (no loop) api works correctly. Thank in advance.
Tadeusz
Sub Main
Dim App As femap.model
Set App = feFemap()
Dim layer_ As femap.layer
Set layer_ = App.feLayer
Dim group_ As femap.Group
Set group_ = App.feGroup
Dim surfOnLayer_set As femap.Set
Set surfOnLayer_set = App.feSet
Dim layerName As String
Dim layerID As Long
Dim group_ID As Long
While layer_.Next 'go throgh all layers
If (layer_.ID <> 1) And (layer_.ID <> 9999) Then ' exluding these
'take layer
layer_.Get(layer_.ID)
layerName = layer_.title
App.feAppMessage(FCM_NORMAL, "Working on layer :" & Str(layer_.ID) &"=>" & " " & layerName )
surfOnLayer_set.Clear()
surfOnLayer_set.AddEntitiesOnLayer( -(layer_.ID), FT_SURFACE) ' collect surfaces in the set
' time to create group
group_ID = group_.NextEmptyID
group_.Get(group_ID)
group_.title = layerName
group_.SetAdd(FT_SURFACE, surfOnLayer_set.ID) ' add surfaces from the set
group_.Put(group_ID)
End If
Wend
End Sub
First I'd like to say hello to everyone. This is my first post here.
Would you kindly advise what is wrong with this piece of code?
Working with Femap 11.
I try to create groups based on information from layers. I started from surfaces and found incomprehensible problem at once.
API creates groups but somehow it summing up surfaces IDs from previous step. Looks like clear function is ignored but no. IDs listed in each step are correct.
For single layer (no loop) api works correctly. Thank in advance.
Tadeusz
Sub Main
Dim App As femap.model
Set App = feFemap()
Dim layer_ As femap.layer
Set layer_ = App.feLayer
Dim group_ As femap.Group
Set group_ = App.feGroup
Dim surfOnLayer_set As femap.Set
Set surfOnLayer_set = App.feSet
Dim layerName As String
Dim layerID As Long
Dim group_ID As Long
While layer_.Next 'go throgh all layers
If (layer_.ID <> 1) And (layer_.ID <> 9999) Then ' exluding these
'take layer
layer_.Get(layer_.ID)
layerName = layer_.title
App.feAppMessage(FCM_NORMAL, "Working on layer :" & Str(layer_.ID) &"=>" & " " & layerName )
surfOnLayer_set.Clear()
surfOnLayer_set.AddEntitiesOnLayer( -(layer_.ID), FT_SURFACE) ' collect surfaces in the set
' time to create group
group_ID = group_.NextEmptyID
group_.Get(group_ID)
group_.title = layerName
group_.SetAdd(FT_SURFACE, surfOnLayer_set.ID) ' add surfaces from the set
group_.Put(group_ID)
End If
Wend
End Sub





RE: Femap API code, Groups from Layers
Your problem is that you clear the set but not the group! Think of the group as a "set of sets", or rather a double vector with a rule on one side, and a list of IDs on the other.
You never clear you group therefore the surfaces are cumulated in it.
The easiest way to do this is to re-set it each time, cf code below.
AP
Sub Main
Dim App As femap.model
Set App = feFemap()
Dim layer_ As femap.layer
Set layer_ = App.feLayer
Dim group_ As femap.Group
Dim surfOnLayer_set As femap.Set
Set surfOnLayer_set = App.feSet
While layer_.Next 'go throgh all layers
If (layer_.ID <> 1) And (layer_.ID <> 9999) Then ' exluding these
App.feAppMessage(FCM_NORMAL, "Working on layer :" & Str(layer_.ID) &"=>" & " " & layer_.title )
surfOnLayer_set.Clear
surfOnLayer_set.AddEntitiesOnLayer( -layer_.ID, FT_SURFACE) ' collect surfaces in the set
'time to create group
Set group_ = App.feGroup
group_.title = layer_.title
group_.SetAdd(FT_SURFACE, surfOnLayer_set.ID) ' add surfaces from the set
group_.Put(group_.NextEmptyID)
End If
Wend
End Sub
RE: Femap API code, Groups from Layers