Python generate unique id

Discussion about writing code for Inkscape.
v1nce
Posts: 696
Joined: Wed Jan 13, 2010 4:36 am

Python generate unique id

Postby v1nce » Thu Jan 05, 2012 5:28 am

Hi,
I try to create python extension and I'd like to know if ther's an easy way to generate unique id ?
Some func I would give a string "my_cool_filter" and that will return "my_cool_filter" if no such id exists and "my_cool_filter_random_stuff" otherwise.
I could go with timestamp + some rand (or browsing the whole svg for id) but if someone already got something like that please let me know.

Thank you.

User avatar
LiquidAsh
Posts: 71
Joined: Fri Apr 22, 2011 11:35 pm
Contact:

Re: Python generate unique id

Postby LiquidAsh » Thu Jan 05, 2012 11:47 pm

Here's a link: http://stackoverflow.com/questions/5348 ... -in-python

Although I've simply left the id off of elements that I've created through extensions in the past; Inkscape will automatically add it's own. I typically use labels (instead of ids) as internal keys within my extensions.

v1nce
Posts: 696
Joined: Wed Jan 13, 2010 4:36 am

Re: Python generate unique id

Postby v1nce » Fri Jan 06, 2012 5:52 am

Thank you.

I needed ID coz I add filters in the defs section and link selected objects to those filters.

import uuid
...
random_string = str(uuid.uuid4())


Return to “Programming”