Jump to content

Stacking, python to vex


Recommended Posts

Hello,

Is anyone able to point out where I am going wrong here? Ideally I would like the boxes of different scales to stack up one on top of another.

In another package, using python on a series of boxes I get the desired stacking effect. When I try to convert the python to vex it's not working as I'd hoped. I suspect it's a really small oversight on my behalf but it would be really helpful for me to understand where I'm doing wrong.

My Python code

# Example Python code

def main():
    list = op.GetObjects()
    new = Vector(0)

    for object in list:
        pos = object.GetPos()
        scale = object.GetScale()

        new.y = new.y + scale.y + pos.y

		#Set new position to new
        object.SetPos(new)

		#Update new
        new.y = new.y + scale.y - pos.y

My Vex code run in Detail mode

vector new = 0;
for (int i = 0; i < (@numpt); i++){
    vector pos = point(0, "P", i);
    vector scale = point(0, "scale", i);
    
    new.y = new.y + scale.y + pos.y;
    
    setpointattrib(0, "P", i, new);
    
    new.y = new.y + scale.y - pos.y;
    }

Thank you

stacking.png

stacking_up.hip

Edited by sessionbeer
Link to comment
Share on other sites

//point wrangle
@P.y += v@scale.y;

not sure if this is a small example of a larger problem you're trying to solve. sorry if this is obvious and not what you're looking for

if you still want to use a detail wrangle

for (int i = 0; i < (@numpt); i++)
{
    vector pos = point(0, "P", i);
    vector scale = point(0, "scale", i);   
    pos.y += scale.y;
    setpointattrib(0, "P", i,  pos);
}

 

Edited by dchow1992
Link to comment
Share on other sites

Hey Sessionbeer,

Slightly different setup but it works on a detail wrangle:

//get start point
vector new = point(0,"P",0);

for (int i = 0; i < @numpt; i++){
    
    if(i == 0) // skip first point
        continue;
  
    vector scale = point(0, "scale", i);
    vector prev_scale = point(0, "scale", i-1);
    
    //get the height fron current and prev_scale combined
    new.y = new.y + ((scale.y + prev_scale.y)*0.5);
    
    setpointattrib(0, "P", i, new);
}

 

stack.PNG

  • Like 1
Link to comment
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.

×
×
  • Create New...