[sharing] Small script to snap all objects to rounded coordinates in presentation mode


    Feb 06 2018 | 7:19 pm
    Here is a simple script that I have been meaning to write for a while and haven't found in the community yet.
    When designing interfaces it can be very annoying if object positions have fractions, causing blurry anti-aliasing and almost-but-not-quite alignment. For some reason these fractions always seem to be unintentionally introduced after a while.
    This script aligns all objects in presentation mode to rounded coordinates. Note that it only works when the patch you are aligning is in presentation mode and <pitfall alert!> if is used in patching mode, it will completely screw up your presentation object positions. This is due to a limitation in the max js API, we can't query the presentation coordinates of objects in patching mode and we also can't find out if a patcher is currently in presentation mode. But given these limitations , this can be a pretty handy script :)
    Use it like this:
    Save as 'objectsnapper.js':
    function bang() {
    	var obj = this.patcher.firstobject; 
    	while(obj != null) {
    		var r = obj.rect;
    		var newR = [Math.round(r[0]), Math.round(r[1]), Math.round(r[2] - r[0]), Math.round(r[3] - r[1])];
    		if (obj.understands("presentation_rect")) obj.message("presentation_rect", newR);
    		post("Adjusting " + obj.maxclass + "\n");
    		obj = obj.nextobject;
    	}
    }
    

    • Feb 07 2018 | 11:43 am
      Very nice. I had to do it manually so many times. I'm gonna try it out.