Sg2.9
positioning cloned object usi...
Recent RSS
positioning cloned object using event.point
Date:  29. August 2006, 14:06

I'm having difficulty positioning a cloned object under the ** or // tool using event.point. The cloned objects end up being offset by a few inches. I've attached my code + a screen shot below to illustrate: any ideas as to why the cloned objects are being offset?

thanks, J

/* code */

function createObjInstance(obj, nPt, nRotate){
var nArt = obj.clone();
var m = new Matrix();
m.translate(nPt.x, nPt.y);
nArt.transform(m);
return nArt;
}

function onMouseDown(event) {
sel = activeDocument.getSelectedItems();
}

function onMouseDrag(event) {
var pt = event.point;
for (var a = 0; a < sel.length; a++){
createObjInstance(sel[a], pt, cRotate);
}
}

Re: positioning cloned object using event.point
Date:  29. August 2006, 19:59

you need to subtract the current position of the object:

m.translate(nPt.add(nArt.bounds.center.multiply(-1)));

which would make the code:

function createObjInstance(obj, nPt, nRotate){ 
	var nArt = obj.clone(); 
	var m = new Matrix(); 
	m.translate(nPt.add(nArt.bounds.center.multiply(-1))); 
	nArt.transform(m); 
	return nArt; 
} 

function onMouseDown(event) { 
	sel = activeDocument.getSelectedItems(); 
} 

function onMouseDrag(event) { 
	var pt = event.point; 
	for (var a = 0; a < sel.length; a++){	
		createObjInstance(sel[a], pt, 0); 
	} 
}
Re: positioning cloned object using event.point
Date:  30. August 2006, 02:50

Works like a charm! Thanks Jonathan.

J

Scripts
08.08.14, 15:24
15.05.14, 14:23
02.03.14, 19:16
18.11.13, 14:48
22.03.13, 03:05
22.02.13, 15:45
Posts
10.01.17, 16:37
19.02.16, 06:03
19.02.16, 06:00
17.01.16, 11:00
12.01.16, 13:10
25.11.15, 08:19
Script of the Moment
Crumpler 23.07.10