Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations KootK on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Femap API code, Groups from Layers

Status
Not open for further replies.

TadeuszSz

Marine/Ocean
Feb 26, 2015
5
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
 
Replies continue below

Recommended for you

Hi,

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
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor