Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var d=fl.getDocumentDOM();
- var s=d.selection;
- if(s) {
- snap(s);
- } else {
- fl.trace("No document opened");
- }
- function snap(s) {
- if(s.length==0) {
- fl.trace("Nothing selected");
- return;
- }
- for(var i=0;i<s.length;i++){
- var e=s[i];
- //fl.trace(e);
- if(e.elementType=="shape") {
- snapShape(e);
- } else if(e.elementType=="instance") {
- snapInst(e);
- }
- }
- }
- function snapInst(inst) {
- inst.x=Math.round(inst.x);
- inst.y=Math.round(inst.y);
- inst.width=Math.round(inst.width);
- inst.height=Math.round(inst.height);
- }
- function snapShape(shape) {
- //fl.trace("drawing object: "+shape.isDrawingObject+" group: "+shape.isGroup+" oval: "+shape.isOvalObject+" rect: "+shape.isRectangleObject );
- if(shape.isDrawingObject) return;
- //if(shape.isGroup) snapGroup(shape);
- shape.beginEdit();
- var vs=shape.vertices;
- for(var i=0;i<vs.length;++i) {
- var v=vs[i];
- var newX=Math.round(v.x);
- var newY=Math.round(v.y);
- v.setLocation(newX,newY);
- }
- shape.endEdit();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement