finding same materials on an object [SOLVED]
-
On 23/02/2015 at 00:18, xxxxxxxx wrote:
Hi Cracs
I try to find and deleta double material-Tags.
So first I think it would be good to bild a list with all materials and then delete all double materials.
But I get get an error when using the set-instruction.
"TypeError: unhashable type: 'c4d.TextureTag'"
Can anybody be so kind and tell me why tis happens and what I can do to solve the Problem?def delete_double_materials(doc) : print 'delete_double_materials START' o_list = get_all_objects_by_type(doc,c4d.Opolygon) for obj in o_list: taglist = obj.GetTags() matlist = [] print 'Das Objekt hat ' + str(len(taglist)) + ' Tags' for tag in taglist: if tag.GetType() == c4d.Ttexture: matlist.append(tag) if len(matlist) > 1: matlist_sauber = list(set(matlist)) #matlist_sauber = dict(map(lambda i: (i,1),matlist)).keys() print matlist_sauber
Thanks a lot
-
On 23/02/2015 at 17:02, xxxxxxxx wrote:
From a quick Google search. It looks like you can't have a set of lists. Are you just trying to print the list? From my understanding of pythons list() is that it makes a list. If that is the case you don't need to do that as matlist is already a list.
print matlist
-
On 24/02/2015 at 00:13, xxxxxxxx wrote:
Hi Shawn,
no I will do more. It's just a test that I collected the materials.
What I realy whant to do is to delete all double materials if there are some on a object.
But for this, I thing , I have to collect all equal materials.
After collecting the unique MatTags I would delete all MatTags whitch are not in the List.But the Problem is, that cleaneang for the List.
I allways get the Message: "unhashables type: c4d.TextureTag"It origins from:
matlist_sauber = list(set(matlist))
Ronald
-
On 24/02/2015 at 09:32, xxxxxxxx wrote:
Hi Ronald,
You'll certainly have to implement something different. To start, here's the documentation for set() in Python, which clearly states you must use hashable elements:
The definition of hashable elements in Python is at this link:
Python hashable elements definition
You'll have to identify data values that allow for comparison and which identify the duplicates to each other but distinguish them from all other elements. Perhaps the name or index value of the tags in question? Since you're the only person familiar with your data set, I'll leave the identification of the appropriate data up to you.
Joey Gaspe
SDK Support Engineer -
On 04/03/2015 at 07:51, xxxxxxxx wrote:
Hi Ronald,
I'd like to know if everything is OK or if you still need help?
Joey Gaspe
SDK Support Engineer -
On 05/03/2015 at 06:48, xxxxxxxx wrote:
Hi Ronald,
Although I don't see your message here, I got an E-mail of your post stating that you found a solution and that I can close the thread, so I will do so. Thanks for letting me know!
Joey Gaspe
SDK Support Engineer -
On 05/03/2015 at 07:09, xxxxxxxx wrote:
Hi Gaspe,
I thought I found a solution, but this was a fault
And: Yes I need help
Ronny
-
On 05/03/2015 at 08:44, xxxxxxxx wrote:
Hi Ronny,
for only deleting double material tags from an object you just can build a comparison list on the fly, like:
for obj in o_list: taglist = obj.GetTags() mattaglist = [] for tag in reversed(taglist) : if tag.GetType() == c4d.Ttexture: mat = tag[c4d.TEXTURETAG_MATERIAL] if mat not in mattaglist: mattaglist.append(mat) else: tag.Remove()
there are a few exeptions if there are selection tags or the material was passed through a parent objects tag
To compare no hashable sequences you can build an extra list, like:
#______________________________________________ #second list comparison for mat in matlist: if not mat in cleanmatlist: cleanmatlist.append(mat) print cleanmatlist
or compare the strings, like:
matnamelist = [] for obj in o_list: taglist = obj.GetTags() for tag in reversed(taglist) : if tag.GetType() == c4d.Ttexture: mat = tag[c4d.TEXTURETAG_MATERIAL] matnamelist.append(mat[c4d.ID_BASELIST_NAME]) #______________________________________________ #string comparison matnamelist = set(matnamelist) print matnamelist
But you´ll lose the direct pointer to the material than.
Hope this helps?
Best wishes
Martin -
On 05/03/2015 at 14:15, xxxxxxxx wrote:
@Monkytag
Thanks a lot.
This works great
I have to remind to go backwards in lists!!!!