Jump to content
Mr. Bodo Hasubek

How to access FEntityGroup of Feature Objects in an other Feature

Recommended Posts

Hi all,

 

I wrote a feature that creates a 3D plate of a given thickness from a surface as a solid and calculates for example the mass of the plate and stores it in the double variable Mass.

 

Now I would like to drop a whole bunch of these plates into an FEntityGroup (FObjectList exists only inside features afaik) and give it to another feature that calculates the overall COG of all the plates.

 

Inside this feature I am having trouble to access the elements of my feature objects. A castTo(FFeature::<feature_name>) didn't work for me.

What am I doing wrong?

 

For example I would like to sum up the masses of the plates like that (plates is the FEntityGroup parameter of the feature):

 

while (i<plates.count())

   masses += plates.at(i).castTo(FFeature::SurfaceTo3DPlate).getMass()

   i += 1

endwhile

 

Why does the castTo() not work or what is wrong with it?

 

Thanks a lot,

Bodo

Share this post


Link to post
Share on other sites

Hallo Bodo,

 

the ".castto()" changes the object type. So for example i can change the type of object "A" to a solid when typing "A.casttod(fsolid)".

But for what you want to do you need to set the FEntityGroup as an Argument.

 

Attached you can find a feature that will need an FentityGroup as input and the return a vector that is the sum of all COG of the solids in the group.

 

Greetings

Willy

GetCOG.fdf

Share this post


Link to post
Share on other sites

Hi Bodo,

 

To be honest, I do not know why this fails in your specific case, but in general, this should work. The following feature works for me (FFeature::one creates a single point "p" - see also the attached project):

// pre: FEntityGroup grp with instances of the other feature

// iterate through all feature instances in the group using foreach
foreach (FFeature::one f in grp)
  echo("" + f.getp().getx())  
endfor

// iterate through all feature instances in the group using while (omitting NULL check if the cast succeeds)
unsigned i(0)
double sum(0)
while (i < grp.getCount())
  sum += grp.at(i).castTo(FFeature::one).getp().getx()
  i += 1
endwhile
 echo("" + sum)  
 

So, in general, your approach is the right one.

 

Arne

test.fdb

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...