Python attributes.add poor performance

Python attributes.add poor performance

philip.marivoet
Explorer Explorer
939 Views
6 Replies
Message 1 of 7

Python attributes.add poor performance

philip.marivoet
Explorer
Explorer

Hi,

 

In my python extension I need to add an attribute to a fairly large number of sketchPoints and sketchLines.

 

For this I use the following code:

 

@timed
def tag(elements, finger_id, master=False):
if not finger_id:
return

info("Tagging {} elements", len(elements))
value = 'M' if master else 'C'

for element in elements:
element.attributes.add(ATTRIBUTE_GROUP, finger_id, value)

 

This is very slow, e.g. tagging 230 elements this way takes 150 seconds!

 

Any suggestion on how to do this faster ?

 

Thanks,

Philip

 

0 Likes
940 Views
6 Replies
Replies (6)
Message 2 of 7

goyals
Autodesk
Autodesk

Not sure this can be speed up unless you can consider applying the attribute on complete sketch rather than on individual entity in sketch.



Shyam Goyal
Sr. Software Dev. Manager
0 Likes
Message 3 of 7

philip.marivoet
Explorer
Explorer

I need a way to record which elements were created by my extension so I can update them later if needed. I do this by adding an attribute to each element so I can find them back later.

 

Maybe there is another, better way to track these elements, but I could not find it.

 

 

 

0 Likes
Message 4 of 7

JeromeBriot
Mentor
Mentor
0 Likes
Message 5 of 7

philip.marivoet
Explorer
Explorer

Is there an API call to set an attribute on multiple elements using an ObjectCollection (I could not find it) ?

 

0 Likes
Message 6 of 7

JeromeBriot
Mentor
Mentor

I don't think so.

 

I thought that instead of setting attibutes to the elements, you could store the elements in different groups.

 

But maybe that's not what you expect?

 

0 Likes
Message 7 of 7

philip.marivoet
Explorer
Explorer

 

I now use attributes to:

 - track which elements were generated

 - what parameters were used to generate them

 

To track the elements I generate an group id (UUID) and use this as the attribute name which I then set on all elements. This way I can use the findAttributes() method of the Design object to find back all elements which is a lot faster than scanning all elements in the sketch for a specific attibute value.

 

I use attributes because this information has to be persisted.

 

I managed to speed up most other steps by using Design class methods and ObjectCollection but setting the attributes is still slow (and I see no reason why it should be, this is just setting some <key, value> on an object as far as I can tell).

 

Philip

 

 

0 Likes