Checking for lots of different Types



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 29/08/2011 at 13:51, xxxxxxxx wrote:

    User Information:
    Cinema 4D Version:   12 
    Platform:      
    Language(s) :     C++  ;

    ---------
    Hey guys,
    What's the best way to handle the situation where you need to check for a very long list of different types?

    BaseObject *obj = doc->GetActiveObject();  
    if(obj->IsInstanceOf(polygons, All primitives, All spline primitives, cameras, etc..)) ; 
    

    Could I maybe use an enum for this and put the enum's name in my expression?

    -ScottA



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 29/08/2011 at 14:22, xxxxxxxx wrote:

    maybe something like this ?
    I hope the C++ code is correct.

    template <class T>  
    bool CheckTypes(BaseObject *op, T[] types, size_t number) {  
      for (size_t i = 0; i < number; i++) {  
          if (op->IsInstanceOf(types[i])) {  
              return true;  
          }  
      }  
      return false;  
    }  
      
    int main() {  
      // ...  
      
      CheckTypes(op, {polygons, All primitives, ..}, 12);  
    }
    

    I made the function a template because I don't know of what type the second IsInstanceOf argument is.

    Cheers,



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 29/08/2011 at 14:29, xxxxxxxx wrote:

    I've done something like this myself and all I did was the brute-force approach of copying the object IDs I was interested in into an array (I got the IDs from coffeesymbols.h). It ended up looking like this:

      
    LONG validIDs[] = {5100, 5101, 5102, 5103, 5107, 5109, 5116, 5117, 5118, 5120, 5125, 5126, 5137, 5140, 5142, 1010865,   
                             5150, 5154, 5155, 5156, 1019362, 1019363, 1021433, 5159, 5160, 5161, 5162, 5163, 5164, 5165, 5166,   
                             5167, 5168, 5169, 5170, 5171, 5172, 5173, 5174, 1001091, 5152, 5175, 5176, 5177, 5178, 5179, 5180,   
                             5181, 5182, 5183, 5184, 5185, 5186, 5187, 5188, 5189, 5190, 1007455, 1008796, 1001002};   
    

    Then it's an easy matter of just checking if the ID of an object is in the array. Not exactly subtle but it works.



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 29/08/2011 at 17:24, xxxxxxxx wrote:

    Thanks guys

    -ScottA



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 30/08/2011 at 09:03, xxxxxxxx wrote:

    Howdy,

    If the number of objects you want to omit is smaller than the number you want to allow, it might be easier to simply check if the object is not one you want to omit, because if it isn't, then it will be one you want to allow. 😉

    Adios,
    Cactus Dan


Log in to reply