Hi
I test your code on sp_file_save_as function.But it doesn't work. Please let me know at where i am doing mistake.
bool sp_file_save_as(Gtk::Window &parentWindow, gpointer /*object*/, gpointer /*data*/) { if (!SP_ACTIVE_DOCUMENT) return false;
SPDocument *doc=inkscape_active_document(); SPObject *Obj = doc->getRoot()->firstChild(); visit_all_objects(Obj);
return breturn; }
void write_coordinates(SPObject *obj) { FILE *fp; fp=fopen("D:\Data.txt","a"); Inkscape::XML::Node *path= obj->getRepr(); gchar const *svgd = path->attribute("d"); fprintf(fp,"PATH2: %s \n ", svgd ); fclose(fp);
} 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); } }
osiĆski"> 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
------------------------------------------------------------------------------ All of the data generated in your IT infrastructure is seriously valuable. Why? It contains a definitive record of application performance, security threats, fraudulent activity, and more. Splunk takes this data and makes sense of it. IT sense. And common sense. http://p.sf.net/sfu/splunk-d2d-c2 _______________________________________________ Inkscape-devel mailing list Inkscape-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/inkscape-devel