Search object by ID



  • On 31/03/2017 at 02:37, xxxxxxxx wrote:

    Hi All!

    I need to find object(s) that are in the scene by ID instead on the name. I know you can do something like this:
       
    ob = doc.SearchObject('ObjectName')
        
        if ob.GetType() == 1035165:
            print "ID is a match "

    But is it possible to do a direct search to the ID of an object. The reason is that people can change the name of an object but not the ID.

    Thanks!🙂



  • On 31/03/2017 at 04:22, xxxxxxxx wrote:

    The only way I know and I do all the time is iterate over all the hierarchy and checking the value. If it's correct add it to a list.
    In the old blog you have an exemple for doing this kind of stuff. Instead of count just pass a list and append data to her. Since it's list data inside her is consistent.
    https://c4dprogramming.wordpress.com/2012/09/12/recursive-hierarchy-iteration/
    Take care they missed () after GetDown in python exemple.

    If you want a unique things I also personally mark their container with a custom unique id generated for the mesh.
    Like that you could search for an exact object by also checking the container and not only for a type of object wich is pretty useless if you want to select one specific object while you have dozen of them into your scene.



  • On 31/03/2017 at 08:12, xxxxxxxx wrote:

    Thanks! This is very helpful! Still strange that there is not an easier method than this.
    🙂



  • On 31/03/2017 at 08:13, xxxxxxxx wrote:

    Before leaving into weekend, I just want to quickly add that these articles are available on the new blog as well:
    Non-recursive hierarchy iteration
    Recursive hierarchy iteration



  • On 03/04/2017 at 02:36, xxxxxxxx wrote:

    Hi,

    now, I have a bit more time to answer.

    Probably not exactly what you are looking for, but via BaseDocument.GetHighest() you can search for an object by ID, unfortunately only for the "highest", but maybe still better than nothing.

    Then I should also point out, that GetType() might not always be what you want, but there's also IsInstanceOf(), GetClassification() and alike. Of course these won't help with the actual search, but still may be useful to more exactly specify the target of a search. You most likely are aware of this, but as you didn't specify ID exactly, I thought, it would still be worth mentioning. In C++ docs there's a small chapter in the C4DAtom manual on this topic.


Log in to reply