How to use virtual int getAllParticleTypeNames(char* particleTypeNames) const = 0;

Alice Sun
Alice Sun Altair Community Member
edited May 15 in Community Q&A

Hi,

To reset the custom particle property in the contact model API v3.6.0., I plan to utilize the resetCustomProperty() function defined in ParticleManagerApi_1_5.

For using resetCustomProperty, I need to provide the particle name. Can I utilize the function virtual int getAllParticleTypeNames(char *particleTypeNames) const to obtain the particle names, and how exactly should I use it?

Thanks

 

Tagged:

Answers

  • Richard Wood_20774
    Richard Wood_20774
    Altair Employee
    edited May 15

    Hi Alice,

    You can just use the string of the particle name in resetCustomProperty( ), if you know the particle type you want, but this is clearly restrictive and not good in the general case and so getting the particle names makes sense here.

    While you can use getAllParticleTypeNames( ), the intended way of using this is through getAllParticleTypeNamesVector( ) instead, which handles the slightly trickier to use getAllParticleTypeNames( ). To get a vector of strings which contains your particle types, first declare an instance of the particle manager and then use the helpers as below. This is a snippet of code I regularly use to do this:

    // Get instance of particle manager<br />NApiCore::IParticleManagerApi_1_5* particleManager = static_cast<NApiCore::IParticleManagerApi_1_5*>(apiManager.getApi(NApiCore::eParticleManager, 1, 5));

    // Get all the particle type names as a vector
    &nbsp; &nbsp; std::vector<std::string> allParticleTypes = NApiParticleManagerHelpers_1_5::getAllParticleTypeNamesVector(particleManager);

    You then you can work with the vector allParticleTypes as you like.

    Cheers,

    Richard