Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix find and replace script when objects are renamed #5

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 30 additions & 30 deletions find-and-replace-graphics/findAndReplaceGraphic_transformToFit.jsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/////////////////////////////////////////////////////////////////
//Copy to Object(s) v5 -- CS,CS2,CS3
// Hacked again by Nathaniel Vaughn Kelso @ 7 June 2007
// [email protected]
// Hacked again by Nathaniel Vaughn Kelso @ 7 June 2007
// [email protected]
// "Multiple-object-replacement" hack by Iain Henderson
// [email protected]
// [email protected]
//
//>=--------------------------------------
// User selects two (or more) objects:
Expand All @@ -15,10 +15,10 @@
//Version 4 update: Deselects everything but source object
// --this makes it easy to delete the source object if you wish,
// -- also this makes the older "Replace-Object" script obsolete.
//Version 5 update: option to NOT transform to fit original shape
// -- with additional option flag to register the replacing shape to
// the being-replaced shape's center instead of upper-left corner
//TODO: add flag to delete "master" replacing symbol on completion
//Version 5 update: option to NOT transform to fit original shape
// -- with additional option flag to register the replacing shape to
// the being-replaced shape's center instead of upper-left corner
//TODO: add flag to delete "master" replacing symbol on completion
//>=--------------------------------------
// JS code (c) copyright: John Wundes ( [email protected] ) www.wundes.com
//copyright full text here: http://www.wundes.com/js4ai/copyright.txt
Expand All @@ -35,10 +35,10 @@ if (documents.length>0) {
//initialize vars
//
//*******************************************************
// Toggles for scaling object, fitting to original, offset to center
// Toggles for scaling object, fitting to original, offset to center
//toggle for scaling stroke: set to true to scale stroke.
var scaledStroke = true; // when fitting original dimensions, scale the stroke
var scaledObject = true; // fit to original dimensions
var scaledStroke = true; // when fitting original dimensions, scale the stroke
var scaledObject = true; // fit to original dimensions
var scalingCentered = false; // register with center of being-replaced object
//*******************************************************
//create stroke Array
Expand Down Expand Up @@ -69,23 +69,23 @@ if (documents.length>0) {

for (var i=0; i < mySelection.length; i++) {
eval('subArray' + i + '=' + 'new Array()');
eval('subArray' + i + '["object"]' + '=' + mySelection[i]);
eval('subArray' + i + '["object"]' + '="' + mySelection[i] + '"');
initBounds = mySelection[i].geometricBounds;
ul_x = initBounds[0];
ul_y = initBounds[1];
lr_x = initBounds[2];
lr_y = initBounds[3];
mySelWidth = (lr_x-ul_x);
mySelHeight = (ul_y-lr_y);
mySelPos = [ul_x, ul_y];
mySelOffsetXpos = (ul_x + mySelWidth / 2 - oSelWidth / 2);
mySelPos = [ul_x, ul_y];
mySelOffsetXpos = (ul_x + mySelWidth / 2 - oSelWidth / 2);
mySelOffsetYpos = (ul_y - mySelHeight / 2 + oSelHeight / 2);
eval('subArray' + i + '["width"]=' + mySelWidth);
eval('subArray' + i + '["xpos"]=' + ul_x);
eval('subArray' + i + '["ypos"]=' + ul_y);
eval('subArray' + i + '["height"]=' + mySelHeight);
eval('subArray' + i + '["height"]=' + mySelHeight);
eval('subArray' + i + '["offsetXpos"]=' + mySelOffsetXpos);
eval('subArray' + i + '["offsetYpos"]=' + mySelOffsetYpos);
eval('subArray' + i + '["offsetYpos"]=' + mySelOffsetYpos);

eval('alterObjectArray.push(subArray' + i + ')');
}
Expand All @@ -112,27 +112,27 @@ if (documents.length>0) {
newGroup.move(docRef, ElementPlacement.PLACEATEND);
mySelection[0].duplicate(newGroup, ElementPlacement.PLACEATEND);
}
markStroked(newGroup);

markStroked(newGroup);
// Check to see if the replacing object should be scaled down/up to fit the dimensions of the being-replaced object
if ( scaledObject == true) {
if ( scaledObject == true) {
eval('newGroup.position = [alterObjectArray['+i+']["xpos"], alterObjectArray['+i+']["ypos"]]');
eval('newGroup.height = alterObjectArray['+ i +']["height"]');
eval('newGroup.width = alterObjectArray[' + i +']["width"]');
} else {

// Check to see if the replacing object should be registered to the upper left corer of
// the being-replaced objects or if it should be centered on the being-replaced object
if( scalingCentered == true ) {
eval('newGroup.width = alterObjectArray[' + i +']["width"]');
} else {
// Check to see if the replacing object should be registered to the upper left corer of
// the being-replaced objects or if it should be centered on the being-replaced object
if( scalingCentered == true ) {
eval('newGroup.position = [alterObjectArray['+i+']["offsetXpos"], alterObjectArray['+i+']["offsetYpos"]]');
} else {
eval('newGroup.position = [alterObjectArray['+i+']["xpos"], alterObjectArray['+i+']["ypos"]]');
}
}

} else {
eval('newGroup.position = [alterObjectArray['+i+']["xpos"], alterObjectArray['+i+']["ypos"]]');
}
}
mySelection[i].remove();
//restroke with new proportions
scaleStroke(strokeArray, propDiff);
scaleStroke(strokeArray, propDiff);
}
slen = selection.length;

Expand Down