What generally, or specifically, are you trying to do? Is this in Illustrator?
Yes, illustrator.
Think I got it worked out. Bounding box of text is different than if the text is outlined. So script to outline text first then do the rest.
WeedLines.jsx
// Check if there are any selected objects
if (app.selection.length > 0) {
// Group the selection first
app.executeMenuCommand("group");
app.executeMenuCommand("outline");
var selectedItems = app.selection;
var minX = Infinity, minY = Infinity, maxX = -Infinity, maxY = -Infinity;
// Calculate the combined bounding box of the grouped shapes as a whole
for (var i = 0; i < selectedItems.length; i++) {
var item = selectedItems
;
var bounds = item.visibleBounds;
minX = Math.min(minX, bounds[0]);
minY = Math.min(minY, bounds[1]);
maxX = Math.max(maxX, bounds[2]);
maxY = Math.max(maxY, bounds[3]);
}
// Increase the bounding box width by 0.1 inch and height by 0.1 inch (converted to points, where 1 inch = 72 points)
var widthIncrement = 0.1 * 72;
var heightIncrement = .1 - 72 / 2; // Correct height increment
minX -= widthIncrement / 2;
maxX += widthIncrement / 2;
minY -= heightIncrement /2; // Decrease minY to extend downward
maxY += heightIncrement /2; // Increase maxY to extend upward
// Create a new layer for the rectangle and lines
var layer = app.activeDocument.layers.add();
layer.name = "Rectangle and Lines";
// Create the rectangle with increased dimensions
var rectangle = layer.pathItems.rectangle(maxY, minX, maxX - minX, maxY - minY);
rectangle.filled = false; // No fill
rectangle.stroked = true;
rectangle.strokeColor = app.activeDocument.swatches.getByName("Black").color;
// Create the vertical line segment
var verticalLine = layer.pathItems.add();
verticalLine.setEntirePath([[minX + (maxX - minX) / 2, maxY], [minX + (maxX - minX) / 2, minY]]);
verticalLine.stroked = true;
verticalLine.strokeColor = app.activeDocument.swatches.getByName("Black").color;
// Create the horizontal line segment
var horizontalLine = layer.pathItems.add();
horizontalLine.setEntirePath([[minX, minY + (maxY - minY) / 2], [maxX, minY + (maxY - minY) / 2]]);
horizontalLine.stroked = true;
horizontalLine.strokeColor = app.activeDocument.swatches.getByName("Black").color;
// Ungroup the selection at the end
app.executeMenuCommand("ungroup");
// Deselect everything
app.selection = null;
}