I think it would be easier to share an image to show what I'm trying to accomplish.
This will be a mogrt so the actual rectangle size / aspect ratio is determined by variable text size.
But, I think I should still be able to figure out offset angle so the trimmed paths will always be centered on the corners.
Edit: Getting a bit further but still not there. This should make the yellow stroke start directly in the lower right corner, but it doesn't.
# text layer determines width and height
txt=thisComp.layer("quote").sourceRectAtTime();
# padding adding to width and height
p=thisComp.layer("controls").effect("box padding")("Slider");
h=txt.height+p;
w=txt.width+p;
# angle from upper right corner to lower right corner (yay trigonometry)
x=radiansToDegrees(Math.atan(h/w))*2;
[x]
I still haven't figured out how I'm going to account for the length of the line yet (in degrees).
Edit 2: Decided to take a different approach and use a mask with 2 rectangle shapes (controlled with a second slider)
The yellow stroke shape uses the dual rectangle shape layer as a track matte and I'm using these two expressions to determine the width/height of the rectangles.
txt=thisComp.layer("quote").sourceRectAtTime();
h=txt.height;
w=txt.width;
p=thisComp.layer("controls").effect("box padding")("Slider");
sw=thisComp.layer("controls").effect("stroke length")("Slider")
x=w-sw;
y=h+p*2;
[x,y]
txt=thisComp.layer("quote").sourceRectAtTime();
h=txt.height;
w=txt.width;
p=thisComp.layer("controls").effect("box padding")("Slider");
sw=thisComp.layer("controls").effect("stroke length")("Slider")
x=w+p*2;
y=h-sw;
[x,y]
I won't be able to animate the way I had planned, but I should still be able to come up with a cool look by animating the track matte. I'm leaving this question open because I would love to know why my first solution wasn't correct.
Edit3: Thanks for the answer Clif!