论坛帮助 |
社区圈子 |
日历事件 |
2024-06-05, 06:40 | 只看该作者 #3 | ||
|
|||
正式会员
等级: 四袋长老
|
|
||
回复时引用此帖 |
2024-06-05, 18:34 | 只看该作者 #7 | ||
|
|||
正式会员
等级: 四袋长老
|
var selection = doc.selection; if (selection.length > 0) { var topObject = selection[0]; topObject.name = "Another"; for (var i = 1; i < selection.length; i++) { selection[i].name = "Another"; if (selection[i].top > topObject.top) { topObject = selection[i]; } } topObject.name = "TopObj"; doc.selection = null; topObject.selected = true; var topbounds = topObject.geometricBounds; } var selectedItems = app.activeDocument.selection; if (selectedItems.length > 0 ) { var selectedItem = selectedItems[0]; if (hasClippingMask(selectedItem)) { var dimensions = getClippingMaskDimensions(selectedItem); var width = pointsToMillimeters(dimensions.width); var height = pointsToMillimeters(dimensions.height); var topX = pointsToMillimeters(dimensions.topX); var topY = pointsToMillimeters(dimensions.topY); } else { var dimensions = getItemDimensions(selectedItem); var width = pointsToMillimeters(dimensions.width); var height = pointsToMillimeters(dimensions.height); var topX = pointsToMillimeters(dimensions.topX); var topY = pointsToMillimeters(dimensions.topY); } var rect = doc.pathItems.rectangle(dimensions.topY , dimensions.topX , width*(72/25.4), height*(72/25.4) ); doc.selection = null; rect.selected = true; var shapes = doc.selection; var shape = shapes[0] var a0 = shape.geometricBounds[0]; var a1 = shape.geometricBounds[1]; var a2 = shape.geometricBounds[2]; var a3 = shape.geometricBounds[3]; doc.artboards.add([a0, a1, a2, a3]); rect.remove(); } var doc = app.activeDocument; for (var i = 0; i < doc.pageItems.length; i++) { var item = doc.pageItems[i]; if (item.name == "Another") { item.selected = true; } } //// if (app.documents.length > 0) { var selected = doc.selection; var endIndex = selected.length; RUN(); redraw(); } function RUN() { var inputSize = [width,height]; if (inputSize.length == 1) { inputSize.push(inputSize[0]); } inputSize[0] = inputSize[0] * 2.834645; inputSize[1] = inputSize[1] * 2.834645; for (var i = 0; i < endIndex; i += 1) { if (selected[i].clipped) { getObject(selected[i], inputSize); } else { itemRedefining(selected[i], inputSize); } redraw(); }; } function pointsToMillimeters(points) { var inches = points / 72; var millimeters = inches * 25.4; return millimeters; } function getObject(tartgetObject, inputSize, scaleMod) { var scale = getClipped(tartgetObject, inputSize, scaleMod); var maskObj = getMaskOBJ(tartgetObject); var viewTransCorner = getObjTransCorner(maskObj); var AiTransCorner = getObjTransCorner(tartgetObject); var deltaTransCorner = new Array(); deltaTransCorner[0] = viewTransCorner[0] - AiTransCorner[0]; deltaTransCorner[1] = viewTransCorner[1] - AiTransCorner[1]; var offsetArr = new Array(); offsetArr[0] = (maskObj.geometricBounds[0] - tartgetObject.geometricBounds[0]) - ((maskObj.geometricBounds[0] - tartgetObject.geometricBounds[0]) * (scale[0] / 100)); offsetArr[1] = (maskObj.geometricBounds[1] - tartgetObject.geometricBounds[1]) - ((maskObj.geometricBounds[1] - tartgetObject.geometricBounds[1]) * (scale[1] / 100)); getTransformCorner = Transformation.TOPLEFT; tartgetObject.resize(scale[0], scale[1], true, true, true, true, scale[0], getTransformCorner); tartgetObject.translate(offsetArr[0], offsetArr[1]); } function getMaskOBJ(refOBJ) { for (var j = 0; j < refOBJ.pageItems.length; j += 1) { if (refOBJ.pageItems[j].clipping) { return refOBJ.pageItems[j]; break; } } } function getObjTransCorner(refOBJ) { var objTransCorner = Array(2); objTransCorner[0] = refOBJ.position[0] + (refOBJ.width / 2); objTransCorner[1] = refOBJ.position[1] - (refOBJ.height / 2); return objTransCorner; } function itemRedefining(selectedRef, inputSize) { var newPosition = new Array(2); newPosition[0] = selectedRef.position[0]; newPosition[1] = selectedRef.position[1]; selectedRef.width = inputSize[0]; selectedRef.height = inputSize[1]; selectedRef.position = newPosition; } function getClipped(slectedClippedObject, inputSize, scaleMod) { if (scaleMod) { scale = [inputSize[0] * 100, inputSize[1] * 100]; } else { var mySel = slectedClippedObject; for (var i = 0; i < mySel.pathItems.length; i += 1) { var item = mySel.pathItems[i]; if (item.clipping == true) { var clipSize = [item.width, item.height]; break; } } scale = [(inputSize[0] / clipSize[0]) * 100, (inputSize[1] / clipSize[1]) * 100]; } return scale; } function hasClippingMask(item) { if (item.typename === "GroupItem" && item.clipped) { return true; } if (item.typename === "CompoundPathItem" && item.pathItems.length > 0) { return true; } return false; } function getClippingMaskDimensions(item) { var width = 0; var height = 0; var topX = 0; var topY = 0; if (item.typename === "GroupItem" && item.clipped) { var clippingMask = item.pageItems[0]; var bounds=clippingMask.geometricBounds; width = clippingMask.width; height = clippingMask.height; topX = bounds[0]; topY = bounds[1]; } if (item.typename === "CompoundPathItem" && item.pathItems.length > 0) { var clippingPath = item.pathItems[0]; var bounds=clippingPath.geometricBounds; width = clippingPath.width; height = clippingPath.height; topX = bounds[0]; topY = bounds[1]; } return { width: width, height: height, topX: topX, topY: topY }; } function getItemDimensions(item) { var bounds = item.geometricBounds; var width = Math.abs(bounds[2] - bounds[0]); var height = Math.abs(bounds[3] - bounds[1]); var topX = bounds[0]; var topY = bounds[1]; return { width: width, height: height, topX: topX, topY: topY }; } app.executeMenuCommand('Horizontal Align Center') app.executeMenuCommand('Vertical Align Center') app.activeDocument.artboards.remove(app.activeDocument.artboards.getActiveArtboardIndex()); |
||
回复时引用此帖 |