2011/7/12 mahendra1 <mahendra.gajera@...2640...>:
Hello
I have to find X,Y coordinated of object with use of source code.I don't wants to use Extension option. I try to write code for the same ,It gives only one objects coordinate.The following code i write for get X,Y coordinated. Please let me know how can i get XY coordinate All SPObject on screen .
FILE *fp; fp=fopen("D:\Data.txt","w"); SPDocument *doc=inkscape_active_document();
if(doc == NULL ) {
return true; } Inkscape::XML::Node *root = doc->getReprRoot(); Inkscape::XML::Node *path = sp_repr_lookup_name(root, "svg:path", -1); // if ( path == NULL ) {
doc->doUnref(); return true;
} gchar const *svgd = path->attribute("d"); fprintf(fp,"PATH2: %s\n", svgd); }
This is wrong, you should not call doc->doUnref(), because inkscape_active_document() does not take a reference.
To access all objects you need to iterate over the tree. It's easiest to do by defining a recursive function. Define a function like this:
void visit_all_objects(SPObject *obj) { if (obj == NULL) return; write_coordinates(obj); // write object's coordinates to a file here SPObject *child = obj->children; for (; child; child = child->next) { visit_all_objects(child); } }
Note that this will iterate over all objects in the document rather than only those which are displayed on the screen. For that, you should add some checks at the beginning of the function. For example, call the write_coordinates function only if the object is an SPItem with (use SP_IS_ITEM() to check this) and do not recurse into elements which are not displayed, such as svg:defs (SP_IS_DEFS()) or svg:symbol (SP_IS_SYMBOL()).
Regards, Krzysztof