Jump to content
Sign in to follow this  
cermmid

Distribute by size

Recommended Posts

Hello,

I've got 3 boxes first is 15x20, second 20x20, and third 30x30. I want to distribute them in one direction in right orded but also to have even spaces between them. Anybody ecnountered similiar problem?

Share this post


Link to post
Share on other sites

Merge all objects, pack them after connectivity and lay them out with a for loop which sums up all widths plus the spacing.

This detail wrangle code is not sufficient but should give you an idea:

float space = chf('space');
float shift = 0.0;
for(int i = 0; i < npoints(0); i++){
    float bounds[] = primintrinsic(0, 'packedbounds', i);
    float width = bounds[1] + abs(bounds[0]);
    vector pos = set(shift, 0.0, 0.0);
    setpointattrib(0, 'P', i, pos, 'add');
    shift += width + space;
}

 

distribute_objects.hiplc

  • Like 1

Share this post


Link to post
Share on other sites

here is slightly modified code to Konstantin's answer to account for pivots and real bounds in case your packed pieces are already transformed

float space = chf('space');
vector offset = 0.0;
for(int i = 0; i < npoints(0); i++){
    float bounds[] = primintrinsic(0, 'bounds', i);
    vector pivot = set(bounds[0], 0, 0);
    setpointattrib(0, 'P', i, offset-pivot, 'add');
    float width = bounds[1] - bounds[0];
    offset.x += width + space;
}

 

  • Like 2

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×