Search object by partial name [SOLVED]
On 11/07/2015 at 13:47, xxxxxxxx wrote:
with this code, I find an select, only object by name Cube.
def main() :
> name = "Cube"
> obj = doc.SearchObject(name)
if __name__ == "__main__":
if I wanted to find all objects by partial Cube in name?, example: AlphaCube or CubeBetha or AlphaCubeBetha?
On 12/07/2015 at 04:02, xxxxxxxx wrote:
you might use a hierarchy traversal(or lampda with a key) and check if the desired name is in the object´s name. Therefore a string could be treated pretty much like an array...
import c4d def GetNextObject(op) : if op==None: return None if op.GetDown() : return op.GetDown() while not op.GetNext() and op.GetUp() : op = op.GetUp() return op.GetNext() def HierarchyLoop(op,name) : collection =  while op: if name in op.GetName() : collection.append(op) op = GetNextObject(op) return collection def main() : op = doc.GetFirstObject() name = "Cube" allObjectsWithName = HierarchyLoop(op,name) print allObjectsWithName if __name__=='__main__': main()
On 13/07/2015 at 04:39, xxxxxxxx wrote:
I assume, Martin's code already solved your problem.
Nothing much to add, but for completeness sake:
There's actually a function, that can search for an object with he closest matching name: SearchObjectInc() Unfortunately it returns only one object, so it's useful in very specific cases, only.
On 26/08/2015 at 09:35, xxxxxxxx wrote:
Is this thread solved?
On 26/08/2015 at 10:48, xxxxxxxx wrote: