Skip to main content
Inspiring
April 28, 2022
Answered

Create a manual path object using size and roundness of a shapelayer rectangle

  • April 28, 2022
  • 3 replies
  • 789 views

Hi there,

How to create realTime Path Object from size and roundness of rectangle?
How Path object looks like, what all elements are inside?
Is there any documentation regarding this path object data?

Please refer attachment for more details.

 

 

This topic has been closed for replies.
Correct answer Dan Ebberts

Try this (I did it in a hurry, so there may still be bugs and it's probably not as efficient as it could be):

s = thisComp.layer("Shape Layer 1").content("Rectangle 1").content("Rectangle Path 1").size;
r = thisComp.layer("Shape Layer 1").content("Rectangle 1").content("Rectangle Path 1").roundness;

w = s[0]/2;
h = s[1]/2;
maxR = Math.min(w,h);
r = Math.min(maxR,r);
t = r*0.5525;

if (r == 0){ // 4 points
  p = [[-w,-h],[w,-h],[w,h],[-w,h]];
  iT = [];
  oT = [];
}else if (r >= maxR){
  if (w == h){ // 4 points
    p = [[0,-h],[w,0],[0,h],[-w,0]];
    iT = [[-t,0],[0,-t],[t,0],[0,t]];
    oT = [[t,0],[0,t],[-t,0],[0,-t]];
  }else{ // 6 points
    if (w > h){
      p = [[-w+r,-h],[w-r,-h],[w,0],[w-r,h],[-w+r,h],[-w,0]];
      iT = [[-t,0],[-t,0],[0,-t],[t,0],[t,0],[0,t]];
      oT = [[t,0],[t,0],[0,t],[-t,0],[-t,0],[0,-t]];
    }else{
      p = [[-w,-h+r],[0,-h],[w,-h+r],[w,h-r],[0,h],[-w,h-r]];
      iT = [[0,t],[-t,0],[0,-t],[0,-t],[t,0],[0,t]];
      oT = [[0,-t],[t,0],[0,t],[0,t],[-t,0],[0,-t]];
    }
  }
}else{ // 8 points
  p = [[-w,-h+r],[-w+r,-h],[w-r,-h],[w,-h+r],[w,h-r],[w-r,h],[-w+r,h],[-w,h-r]];
  iT = [[0,t],[-t,0],[-t,0],[0,-t],[0,-t],[t,0],[t,0],[0,t]];
  oT = [[0,-t],[t,0],[t,0],[0,t],[0,t],[-t,0],[-t,0],[0,-t]];
}
createPath(p,iT,oT,true)

 

3 replies

Community Expert
April 28, 2022

If you want to duplicate any shape on another shape layer, you can select the object (Rectangle 1) in the existing shape layer and choose Edit/Copy with Property Links from the menu (Alt/Option + Ctrl/Cmnd + c). Then create a new, empty shape layer and paste. The new layer will contain a new Rectangle 1 that matches the original Rectangle 1. You could also copy the entire shape layer with property links or Copy with Relative Property Links if you needed the new layer in a nested comp (pre-comp). 

 

Copy with property links works with parametric shapes (Rectangle, Ellipse, Polygon, etc.) and paths drawn with the pen tool. With a bit of fiddling, you can also link a mask directly to a shape layer using the same expression for the path.

 

Try Dan's expression if you want to create a vector path from a parametric shape. It seems to be responsive and works for me. I have only tried it with a couple of rectangles and it works just fine. Adding it to more rectangles in the same comp may slow things down. You'll have to check.

Inspiring
April 29, 2022

Yes Rick, Dan solution working fine here as well.

Thanks for your time.

Dan Ebberts
Community Expert
Dan EbbertsCommunity ExpertCorrect answer
Community Expert
April 28, 2022

Try this (I did it in a hurry, so there may still be bugs and it's probably not as efficient as it could be):

s = thisComp.layer("Shape Layer 1").content("Rectangle 1").content("Rectangle Path 1").size;
r = thisComp.layer("Shape Layer 1").content("Rectangle 1").content("Rectangle Path 1").roundness;

w = s[0]/2;
h = s[1]/2;
maxR = Math.min(w,h);
r = Math.min(maxR,r);
t = r*0.5525;

if (r == 0){ // 4 points
  p = [[-w,-h],[w,-h],[w,h],[-w,h]];
  iT = [];
  oT = [];
}else if (r >= maxR){
  if (w == h){ // 4 points
    p = [[0,-h],[w,0],[0,h],[-w,0]];
    iT = [[-t,0],[0,-t],[t,0],[0,t]];
    oT = [[t,0],[0,t],[-t,0],[0,-t]];
  }else{ // 6 points
    if (w > h){
      p = [[-w+r,-h],[w-r,-h],[w,0],[w-r,h],[-w+r,h],[-w,0]];
      iT = [[-t,0],[-t,0],[0,-t],[t,0],[t,0],[0,t]];
      oT = [[t,0],[t,0],[0,t],[-t,0],[-t,0],[0,-t]];
    }else{
      p = [[-w,-h+r],[0,-h],[w,-h+r],[w,h-r],[0,h],[-w,h-r]];
      iT = [[0,t],[-t,0],[0,-t],[0,-t],[t,0],[0,t]];
      oT = [[0,-t],[t,0],[0,t],[0,t],[-t,0],[0,-t]];
    }
  }
}else{ // 8 points
  p = [[-w,-h+r],[-w+r,-h],[w-r,-h],[w,-h+r],[w,h-r],[w-r,h],[-w+r,h],[-w,h-r]];
  iT = [[0,t],[-t,0],[-t,0],[0,-t],[0,-t],[t,0],[t,0],[0,t]];
  oT = [[0,-t],[t,0],[t,0],[0,t],[0,t],[-t,0],[-t,0],[0,-t]];
}
createPath(p,iT,oT,true)

 

Inspiring
April 29, 2022

It is working fine Dan, thanks for quick reply.Your awesome.

Mylenium
Legend
April 28, 2022

You cannot access the parametric entities' internal path and that is that. You have to fully reconstruct it using your own math, which is easy enough.

 

Mylenium