Jump to content

delizade

Arrange boxes that variable widths

Recommended Posts

Posted (edited)

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
Share on other sites

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
Share on other sites

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
Share on other sites

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.


Phil Richards, www.fugidesign.co.uk

Share this post


Link to post
Share on other sites

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

  • Like 1

Share this post


Link to post
Share on other sites

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.

  • Like 3

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites
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
Share on other sites

@jed

Thanks for sharin the project files.

I can understand your code, but I was trying to read up on the c4d.VECTOR_X property in the Python SDK. I found the c4d.Vector class, and it's proprties, but couldn't find mention of the VECTOR_X, only things like vector(x,y,z).


Do you know where c4d.VECTOR_x is in the SDK?

 

Another thing that confuses me, are the statements like c4d.__init__() in the black title bars, but then the example listed beneath doesn't useit.

I understand that it initizes an new vector, but the example will say say something like: c4d.Vector()

 

Is the __init__() and the other code mentioned in the black title bars a Class that needs to be imported or something?

Python SDK.jpg


Phil Richards, www.fugidesign.co.uk

Share this post


Link to post
Share on other sites

I'd done this in a previous project, but using this scene as an example -

 

for the x position code, I just dragged the field in attrib manager into the python window - see last line here

 

drag.png.9aa783d46b9e16167f7e833f38606c42.png

 

(might need some editing for name)

 

then I experimented changing the syntax to global and it went orange (= code ok), and I tested the value against what was happening in the viewport. It all seemed to tally, so I used the code.

 

For local co-ords, I could have used obj.SetRelPos(c4d.Vector(x, 0, 0)) , but since I was only interested in x co-ord I used the syntax above.

 

You can also drag an obj field into console to get syntax, and if you hit enter you get the value ::):

 

console.png.94a6d9b8f4cf4eb78770782f9a32e5ad.png

 

I agree with your findings that SDK search doesn't find code you know is OK. My method - guess, tinker, make it up as you go along...

  • Like 1

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

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.


  • Recently Browsing   0 members

    No registered users viewing this page.

YOUTUBE CHANNEL:

ABOUT US:

C4D Cafe is the largest CINEMA 4D community. We provide facilities for discussion, showcasing and learning our favorite software :) Register now to gain access to all of our features. Once registered and logged in, you will be able to create topics, post replies to existing threads, get your own private messenger, post status updates, manage your profile and much more. If you need to find solution to your problem or otherwise ask for help, Cafe is the right place.
×
×
  • Create New...