Need help with graphic line in InDesign CS

I really need help with this. I posted this about three days ago but I thought the problem went away.

When I run this simple script it reverses the XX or YY coordinates of the geometric bounds if X1 is bigger than X2 or Y1 is bigger than Y2.
the geometric bounds are set at {32.0, 0, 18, 27.9}
but the line that gets drawn is {18, 0, 32.0, 27.9}

My script creates a lot of graphic lines, and it’s usually only the last line that’s affected.

If anyone can shed some light, it would be much appreciated, my script is sidelined until I can figure this out.

tell application "InDesign CS" tell document 1 set graphic_line to make new graphic line with properties {geometric bounds:{32.0, 0, 18, 27.9}, stroke weight:1, right line end:triangle arrow head} end tell end tell

If it only the last line (strange) then draw a random line at end then delete it. Just an idea.

I couldn’t reproduce the problem in InDesign CS 2 so I guess they fixed it.

With yours does the arrow draw on the left not the right?

An example with two lines and a get values would be good (or more fuller example). I can test in CS 2 for you.

Have fun

Bevos

I don’t think so because I had the same problem using CS2 I just got CS3 today so I’ll try it there too

mm

still getting backward results form CS3

I ran this


tell application "Adobe InDesign CS3"
	tell document 1
		set red_slugline to make new graphic line with properties {geometric bounds:{32.0, 0, 18, 27.9}, stroke weight:1, right line end:triangle arrow head}
		get geometric bounds of red_slugline
	end tell
end tell

the script returned {18.0, 0.0, 32.0, 27.9}

and drew a line going from top left pointing to bottom right

I’m still playing around though

I was doing my own numbers, I see now. Its not a X1,Y1 to X2,Y2, it just the rectangle it draws in, you have to use ‘rotation angle’ or ‘absolute rotation angle’ since Applescript doesn’t do Cos, Sin or Tan. This could be hard. UNIX BC has them. There’s a rotate command, but It still needs the angle. You can set archor point and our thing.

I’ve done some more testing, where I use my larger script to create graphic lines that run from a slug in the left margin to the text box in the InDesign document. If the text box is above the slug, InDesign refuses to draw a rule going from lower left to upper right. The same thing occurs if I reverse the slug to the right margin, but below the text box. It doesn’t matter if the entire line is drawn from the margin or totally contained within the bounds of the page. InDesign still refuses to draw from the lower right to the upper left, or the lower left to the upper right. In all cases, it reverses the XX or the YY coordinates to create a line it’s happy with.
I can go into the InDesign program and draw the rule easily enough, so it’s got to be some kind of communication glitch.
There may be a workaround, as Bevos mentioned, by rotating the rule, something like,

if item 1 of geometric bounds of graphic line > than item 3 of geometric bounds of graphic line, rotate graphic line ? degrees

but it would take a math wiz to be able to tell the script how much to rotate the graphic line prior to creating it.

Ok but if I create as as text box instead of a line I still get the reversed results ? not that that has anything to do with what you are trying to acomplish

mm

You are sending an impossible set of coordinates. The first 2 items in GeoBounds are the origin point, which can be most any number (within the confines of the document size), but the other 2 (termination point) depend on the first to calculate dimensions. GeoBounds’s items (4 & 2) and (3 & 1) subtract from each other to arrive at the width and height.

In the case of {32,0,18,27.9}, 18 - 32 produces a height measurement that ID is confused by and attempts to resolve.

Looks like you can do it using the subclass paths and set it points. The points are x and y of the page. Becuase its a subclass you get every option of graphic line, includes arrow heads. Only had a chance to explore it with Script Debugger 4, do you have that? Very handy. Have some code examples soon.

Marc, how would you draw a line in InDesign CS, whose origin point is 32 picas down from the top and 0 picas from the left margin, and whose termination point is 18 picas down from the top and 27.9 picas from the left?

Do you know the X, Y coordinates of what your line is pointing to? If so, I think it would be a better approach to directly assign your line’s dimensions based on the two sets of points. My example below has dummy values for the width and height, you need to insert your values for the horizontal and vertical offset of the two points of origin.

-- LINE DIMENSIONS
property theWidth : 1.5
property theHeight : 1.5

--LINE ORIGIN
set X to 0
set Y to 32


	tell application "InDesign CS"
		tell active document
			make new graphic line with properties ¬
			{geometric bounds:{Y, X, (Y + theHeight), (X + theWidth)}}
		end tell
	end tell

Marc
When I enter your script, I still end up with the same situation. In this case I have to say (Y - theHeight) because the line is going up from the left margin, not down. However, the line ends up being drawn with the X coordinates reversed.

[code]property theWidth : 27.9
property theHeight : 18
set X to 0
set Y to 32
tell application “InDesign CS”
tell document 1
set red_slugline to make new graphic line with properties ¬
{geometric bounds:{Y, X, (Y - theHeight), (X + theWidth)}}

	get geometric bounds of red_slugline--{14.0, 0.0, 32.0, 27.9}
end tell

end tell[/code]
As far as the geobounds, if I draw the correct line in InDesign, the beginning point is Y=32, X=0. At the other end of the line, then ending coordinates are Y=18, X=27.9. When I ask for the geometric bounds in Applescript of the line I just drew in InDesign, I get {32.0, 0, 18, 27.9}.
Now, if I ask my script to draw this same line in the InDesign document, using the same geometric bounds I just retrieved, I end up with a line whose geometric bounds are 18, 0, 32.0, 27.9. With your script I end up with {14, 0, 32, 27.9}

That is the problem. If I get the geometric bounds of the line as it should be, and ask applescript to use those same geometric bounds, the XX coordinates get reversed if X1 > X2, or Y1 > Y2 .

I did come up with a work-around for the problem. It uses the “transform:flip vertical” aspect of InDesign to reverse back the coordinates it reversed to begin with, but it also offsets the line vertically and has to be moved back down by the formulated equation below. This works here in the bench test, but in my larger script which creates a lot of graphic lines, the script has a little problem with line 7, it has difficulty discerning some lines whose geobounds ARE {b, a, d, c}, and runs the work-around on them anyway.

tell application "InDesign CS" tell document 1 set geobounds to {32, 0, 18, 27.9} set red_slugline to make new graphic line with properties ¬ {geometric bounds:geobounds} set {b, a, d, c} to geometric bounds of red_slugline if geobounds is not {b, a, d, c} then set newB to (b + (d - b)) set newD to (d + (d - b)) set geometric bounds of red_slugline to {newB, a, newD, c} set properties of red_slugline to {absolute vertical scale:-100} end if end tell end tell
I am still looking for a better solution that treats the problem and not the symptom. All I know about creating graphic lines I learned right here at:
http://bbs.applescript.net/viewtopic.php?id=15788, so I make no claims to being a reliable source on the subject, I just want to understand it and make it work right.

Geobounds relies on the leftmost and uppermost coordinates to be the starting/bounding point of its edge; giving it a negative value would cause it to start before it began, which isn’t possible. Your new code, which I’ve only browsed so far, contains a valid and (I now believe) necessary feature - flipping. Using my code, I can see the need to create an if statement that determined if Y+theHeight < Y and would cause the line to rise above the origin point, then invoke a handler that treated it differently from the standard line placement by calculating the reverse of the vertical offset for theHeight and then:


tell red_slugline to resize vertical scale -100 around the top center anchor

It’s important to specify a reference point, or the final X coordinate of your line could potentially move away from where the original coordinate was, depending on what your ref point is currently set at.

ok this still gives the reversed numbers but draws the line correctly


tell application "Adobe InDesign CS3"
	tell document 1
		set red_slugline to make new graphic line with properties {geometric bounds:{32.0, 0, 18, 27.9}, stroke weight:1, right line end:triangle arrow head, absolute flip:vertical}
		set geometric bounds of red_slugline to {32.0, 0, 18, 27.9}
		geometric bounds of red_slugline
	end tell
end tell

:confused:

You could just test for the proper direction and rotate the line 180° around the center point of the object.

Another option is to make the graphic line then set the path points to what you are looking for:

tell application "Adobe InDesign CS2"
	tell page 1 of document 1
		--set x to properties of path 1 of page item 1
		set y to make new graphic line with properties {stroke weight:1, right line end:triangle arrow head}
		set entire path of path 1 of y to {{32, 0}, {18, 27}}
	end tell
end tell

This might take the guesswork out of it.

Okay, thanks to everyone, this works. It takes the coordinates of where I want the rule to come from and where I want it to go and draws the line between those points. Then, it compares the geo bounds supplied to the geo bounds executed and if they’re not the same, it flips the line.

[code]set geobounds to {38.0, 0, 18, 27.9} --an arbitrary number supplied by using the {X2,Y2} of a slug in the left margin as the {Y1,X1} of the line, and the left offset and baseline of a character of text as the {Y2,X2} of the line
set red_slugline to make new graphic line with properties {geometric bounds:geobounds, stroke weight:1, stroke color:red_Color, right line end:triangle arrow head, item layer:myLayer}

					set the_bounds to geometric bounds of red_slugline
					set theboundsString to (the_bounds as string)
					set geoboundsString to (geobounds as string)
					if theboundsString is not geoboundsString then
						tell red_slugline to resize vertical scale -100 around center anchor
					end if[/code]

My thanks to everyone who commented, you’ll probably all find some of your script in this final script.

This is part of a much bigger script that I have built in increments and am about ready to reassemble. The script will identify every item on the page, draw a slug in the left or right margin that identifies the item, and an arrowed line pointing to the item referenced. It will be used to proof mechanicals prior to collecting for output, to assure everyone in the proofing chain that the correct number of colors are used, only one color for each color, no RGB, and what fonts are used. This will also help the printer to know where each image is used, as well as the makeup of each color. The script identifies the colors not only of jpgs but of vector images as well. It sure beats drawing all of this on a tissue overlay.