auto-increment object id's?
hey,
i use inkscape a lot - it is my primary svg editor - and i'm very impressed with it. but there's one thing that frustrates me, and that is the way it handles auto-id assignment.
ideally i'd like to be able to select a group of objects, set the ID property of one, with a -1 at the end, and have the rest all be enumerated based on the first one..
is there any way to tell inkscape to use specific id's for objects, and auto-increment properly? i've dl'ed the code and had a look at the sd-object "sp_object_get_unique_id" function, but it doesn't look to me as if theres' an 'easy' way to get it to handle auto-increments properly without majorly restructuring things .. anyone got clues?
On Thu, 11 Nov 2004, Jay Vaughan wrote:
i use inkscape a lot - it is my primary svg editor - and i'm very impressed with it. but there's one thing that frustrates me, and that is the way it handles auto-id assignment.
ideally i'd like to be able to select a group of objects, set the ID property of one, with a -1 at the end, and have the rest all be enumerated based on the first one..
Ooh, interesting idea.
is there any way to tell inkscape to use specific id's for objects, and auto-increment properly? i've dl'ed the code and had a look at the sd-object "sp_object_get_unique_id" function, but it doesn't look to me as if theres' an 'easy' way to get it to handle auto-increments properly without majorly restructuring things .. anyone got clues?
Yes, in fact I recently was working on the section of code that does this, so can tell you exactly where to make these changes. Look in the routine sp_item_widget_label_changed() in item-properties.cpp. This is the code that is run when you click on the "Update Properties" (aka "Set ID") button in the Object (or Item) Properties dialog.
Look at the section of code beginning with
/* Retrieve the label widget for the object's id */
This code takes the text typed into the ID text box, verifies that it's a valid new ID, and then applies it via the 'sp_object_setAttribute()' routine.
Currently, you'll note that if you select multiple object, the fields in this dialog box grey out. So your first task is to figure out a way to make the dialog not grey out the ID box, but somehow indicate that the user can enter an ID pattern according to your idea. My guess is that this is done at the start of sp_item_widget_setup() where it says:
if (!selection->singleItem()) { gtk_widget_set_sensitive (GTK_WIDGET (spw), FALSE); return;
} else { gtk_widget_set_sensitive (GTK_WIDGET (spw), TRUE);
}
Experiment with changing that first clause to setting the sensitivity of the ID field to TRUE (but leaving the rest of the dialog to be insensitive).
Next, the fun part: Back in sp_item_widget_label_changed(), in the object id section, replace the line
sp_object_setAttribute (SP_OBJECT (item), "id", id, &ex);
with some logic that does something like:
if (!selection->singleItem()) { /* TODO: * Parse the entered ID into 'name' and 'incrementable' * Generate an array of old ID's to new ID's * If any of the new ID's are taken, issue an error message * Else, foreach old ID: * Set the new ID using sp_object_setAttribute() */ } else { sp_object_setAttribute (SP_OBJECT (item), "id", id, &ex); }
obviously replacing the commented out section with your own logic.
Hope this helps, Bryce
While fiddling with the text on a path function I came across a simple tip or trick which allows you to get your text inside an object rather than outside.
Draw a circle Duplicate circle and flip horizontally Separate the two circles
Write text sample Duplicate text sample
Take original circle and one of the text samples and put text on path The text goes on the outside of the path
Take flipped circle and other text sample and put text on path The text goes inside the circle
This technique also works with text objects if they are converted to paths first
See attached example I have not seen this documented before. vellum
participants (3)
-
Bryce Harrington
-
Jay Vaughan
-
vellum