amin.khormaei Posted September 15, 2020 Share Posted September 15, 2020 I have this code below: i[]@TP = neighbours(0,0); foreach(int i ; @TP) { @P.y = 1; } how can I tell Houdini to just move the points insideTP array? foreach move all the points. Quote Link to comment Share on other sites More sharing options...
animatrix Posted September 15, 2020 Share Posted September 15, 2020 Hi, You can do it using a detail wrangle: int pts [ ] = array ( 1, 3, 4 ); foreach ( int pt; pts ) setpointattrib ( 0, "P", pt, 1 ); Quote Link to comment Share on other sites More sharing options...
amin.khormaei Posted September 15, 2020 Author Share Posted September 15, 2020 your code doesn't work Quote Link to comment Share on other sites More sharing options...
fsimerey Posted September 15, 2020 Share Posted September 15, 2020 (edited) int pts [ ] = array ( 1, 3, 4 ); foreach ( int pt; pts ) { vector _P = {0,1,0}; // Create a vector setpointattrib ( 0, "P", pt, _P ); // Here all points would get the same position : _P -> (0,1,0) } {} are missing, and attrib P is a vector, so you must put a vector and not a single integer. In your case, if you want only change P.y on those points: int pts [ ] = array ( 1, 3, 4 ); foreach ( int pt; pts ) { vector _P = point(0, "P", pt); // Get P attribute of point pt _P.y = 1.0; setpointattrib ( 0, "P", pt, _P ); } Edited September 15, 2020 by fsimerey 1 Quote Link to comment Share on other sites More sharing options...
vicvvsh Posted September 15, 2020 Share Posted September 15, 2020 3 hours ago, amin.khormaei said: I have this code below: i[]@TP = neighbours(0,0); foreach(int i ; @TP) { @P.y = 1; } how can I tell Houdini to just move the points insideTP array? foreach move all the points. Try this: i[]@TP = neighbours(0,0); foreach(int i ; @TP) { if(i == @ptnum) @P.y = 1; } 1 Quote Link to comment Share on other sites More sharing options...
animatrix Posted September 15, 2020 Share Posted September 15, 2020 3 hours ago, amin.khormaei said: your code doesn't work I tried it before posting, it works fine. Can you post what error are you seeing? 3 hours ago, fsimerey said: int pts [ ] = array ( 1, 3, 4 ); foreach ( int pt; pts ) { vector _P = {0,1,0}; // Create a vector setpointattrib ( 0, "P", pt, _P ); // Here all points would get the same position : _P -> (0,1,0) } {} are missing, and attrib P is a vector, so you must put a vector and not a single integer. In your case, if you want only change P.y on those points: int pts [ ] = array ( 1, 3, 4 ); foreach ( int pt; pts ) { vector _P = point(0, "P", pt); // Get P attribute of point pt _P.y = 1.0; setpointattrib ( 0, "P", pt, _P ); } 1. {} is not needed in my code. Look here for similar C style syntax rules: http://www.cplusplus.com/forum/beginner/180452 2. You don't need to provide a vector type. VEX will automatically cast 0 into a vector. Quote Link to comment Share on other sites More sharing options...
fsimerey Posted September 15, 2020 Share Posted September 15, 2020 (edited) 4 hours ago, amin.khormaei said: I have this code below: i[]@TP = neighbours(0,0); foreach(int i ; @TP) { @P.y = 1; } how can I tell Houdini to just move the points insideTP array? foreach move all the points. 10 minutes ago, animatrix said: 2. You don't need to provide a vector type. VEX will automatically cast 0 into a vector. In the case of Amin, he seems want to move in Y axis. In your example the 1 give a vector (1,0,0), so moving along X axis AND ALL points are at the same position (1,0,0)... Good to know for C style syntax Edited September 15, 2020 by fsimerey 1 Quote Link to comment Share on other sites More sharing options...
animatrix Posted September 15, 2020 Share Posted September 15, 2020 13 minutes ago, fsimerey said: In the case of Amin, he seems want to move in Y axis. In your example the 1 give a vector (1,0,0), so moving along X axis AND ALL points are at the same position (1,0,0)... Good to know for C style syntax No, 1 will become (1,1,1). I just posted an example. He should be able to adapt it to his needs. 1 Quote Link to comment Share on other sites More sharing options...
fsimerey Posted September 15, 2020 Share Posted September 15, 2020 (edited) 14 minutes ago, animatrix said: No, 1 will become (1,1,1). It's not correct. See attached file. vector(1) give a vector of (1,1,1) Edited September 15, 2020 by fsimerey 1 Quote Link to comment Share on other sites More sharing options...
amin.khormaei Posted September 15, 2020 Author Share Posted September 15, 2020 thank you for all answers. the simplest way was: i[]@pts = neighbours(0,0); foreach(int i ; @pts) { if(i == @ptnum) { @P.y = 1; } } Quote Link to comment Share on other sites More sharing options...
anim Posted September 15, 2020 Share Posted September 15, 2020 3 hours ago, amin.khormaei said: thank you for all answers. the simplest way was: i[]@pts = neighbours(0,0); foreach(int i ; @pts) { if(i == @ptnum) { @P.y = 1; } } if your array is not varying per point (at least from your example) and you still want to use Point wrangle instead of detail you can simplify your code further to int pts[] = neighbours(0,0); if(find(pts, @ptnum) >= 0) { @P.y = 1; } or @P.y += 1; if you want to offset them instead of hardcode to 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.