Jump to content

Sign in to follow this  
delizade

Arrange boxes that variable widths

Recommended Posts

Hi,

 

I've been trying to arrange boxes that has variable width values. I need to arrange them 1 cm seperated from each other. I could not achive this. Could anyone give me tip about this?

I mean;

[20 width box]+ [1 space]+[50 width box]+ [1 space]+[10 width box]+ [1 space] .... n

Edited by delizade
typo

Share this post


Link to post

What did you try ? And do you need this done automatically ? If not, you can just turn on quantize, set Move Q to 1 cm, and then move the boxes yourself.

Or set the grid spacing to 1 cm then turn on grid snapping ?

 

CBR

Share this post


Link to post
  • Topic Author
  • Thanx Cerbera,

     

    I did try mograph cloner and modifier.

    box width values will be able to be changed time to time. Thus, making it manual is not a good solution.

    Share this post


    Link to post

    I think you'd need xpresso to iterate through each object, and get the size of it's bounding box, then set the position on x axis of each object to it's bounding box size (width/height/depth) plus 1.

    I tried, but could't get the iteration right.

     

    Someone who knows xpresso may be able to offer a better solution.

    Share this post


    Link to post

    I think its planesmart or image smart plugin that does something similar with folders of images, maybe you could use that and extrude the result. Dont know any expresso myself.

     

    Deck

    Share this post


    Link to post

    I think this does it

     

    def main():
        top = doc.SearchObject('boxes')
        boxes = top.GetChildren()
        count = len(boxes)
    
        boxes[0][c4d.ID_BASEOBJECT_GLOBAL_POSITION,c4d.VECTOR_X] = 0
    
        for a in range(1, count):
            prev_pos = boxes[a-1][c4d.ID_BASEOBJECT_GLOBAL_POSITION,c4d.VECTOR_X]
            prev_rad = boxes[a-1].GetRad().x
            curr_rad = boxes[a].GetRad().x
            boxes[a][c4d.ID_BASEOBJECT_GLOBAL_POSITION,c4d.VECTOR_X] = prev_pos + prev_rad + 1 + curr_rad

    the boxes are under a parent called boxes, and in the for loop

     

    current position = previous position + prev radius + 1 + current radius

     

    result along X

     

    boxes.png.1efc6c72fc8f19c780af5aafad44b196.png

     

    in this file, copy some boxes into the parent 'boxes' in OM

     

    box_arrange.c4d

     

    edit - same in XPresso. Select one obj and change width with scale tool to test.

    box_arrange_xp2.c4d

     

     

    AFAIK bounding box in XP doesn't use primitives only poly, but the GetRad() python method can do both.

    Share this post


    Link to post

    And this is why i've been trying to learn some Python, a few lines of code and it's all sorted. No xpresso iterator node headaches ;)

     

    Share this post


    Link to post

    I learn by reading other peoples code - the MAXON Python SDK is in Klingon...

    Share this post


    Link to post
  • Topic Author
  • Thank you all.

    Share this post


    Link to post
  • Topic Author
  • 17 hours ago, jed said:

    I think this does it

     

    
    def main():
        top = doc.SearchObject('boxes')
        boxes = top.GetChildren()
        count = len(boxes)
    
        boxes[0][c4d.ID_BASEOBJECT_GLOBAL_POSITION,c4d.VECTOR_X] = 0
    
        for a in range(1, count):
            prev_pos = boxes[a-1][c4d.ID_BASEOBJECT_GLOBAL_POSITION,c4d.VECTOR_X]
            prev_rad = boxes[a-1].GetRad().x
            curr_rad = boxes[a].GetRad().x
            boxes[a][c4d.ID_BASEOBJECT_GLOBAL_POSITION,c4d.VECTOR_X] = prev_pos + prev_rad + 1 + curr_rad

    the boxes are under a parent called boxes, and in the for loop

     

    current position = previous position + prev radius + 1 + current radius

     

    result along X

     

    boxes.png.1efc6c72fc8f19c780af5aafad44b196.png

     

    in this file, copy some boxes into the parent 'boxes' in OM

     

    box_arrange.c4d 214.7 kB · 2 downloads

     

    edit - same in XPresso. Select one obj and change width with scale tool to test.

    box_arrange_xp2.c4d 292.06 kB · 2 downloads

     

     

    AFAIK bounding box in XP doesn't use primitives only poly, but the GetRad() python method can do both.

    perfectly working. thanks a lot to show me a programatic way to control my scene objects Jed.

    Share this post


    Link to post

    Join the conversation

    You can post now and register later. If you have an account, sign in now to post with your account.

    Guest
    Reply to this topic...

    ×   Pasted as rich text.   Paste as plain text instead

      Only 75 emoji are allowed.

    ×   Your link has been automatically embedded.   Display as a link instead

    ×   Your previous content has been restored.   Clear editor

    ×   You cannot paste images directly. Upload or insert images from URL.

    Sign in to follow this  

    • Recently Browsing   0 members

      No registered users viewing this page.

    ×
    ×
    • Create New...