Incremental Moves
Does anyone know how to write/create a pose that moves an object an incremental amount in one direction? For example, you have a cube at position 0,0 (center) and you want to move it 10 units to the right. Then you want to move it 10 more units to the right, or even 10 units backward. How do you write that into a script? When I use a parameter dial to move the object 10 units, then save it as a pose, applying the new pose always puts it back to the 10 unit mark. I tried making sure that only the x-translation was checked before saving the pose, but the problem is that the pose treats the 10 as absolute, not additive.
I am sure this is going to involve establishing a variable for position x, the having a function similar to the following:
b = b (current position on x axis)
c = b + 10 (new position on x axis)
set position = c, y, z
This is for a freebie I am planning to distribute that allows multiple copies of an object in the scene, but each needs to be a specific distance apart so that an object spanning between them will fit perfectly.
Comments
You'd need to use a script. Read in the existing coordinates, do the math, apply the new values to translation x,y and z.
If I can find the time today I might look at it, but crazy busy at the moment so not sure if I'll get to it or not.
I have this Info running around some place. I create Pose controls for Modular sets with scripts for easy set up. I'll find the Base example and post the code if Adam does not beat me to it.
Here is a Basic example of a move Script. I'm not sure when I found this but I'm sure it was from the old Forums.
EDIT The Proper indenting did not Post But I think it will still work properly.
BIG EDIT! will update in few with proper code.
Oh, you both are lifesavers! I used to do some programming in Visual Basic, so I get the gist of most of it, but of course there will be differences. Jaderail, would you consider a quick beta of my freebie, once I implement this code? I don't want to get specific here, not yet anyway.
Adam, I have several of your scripts in my content directory already. I was hoping you would reply, and you did not disappoint! I am really looking forward to getting this done, since it will also be a learning experience for a bigger product I am working on. Modular and whatnot. Jaderail is putting something together for me, as well, since he does some modular work.
I thought about going through the whole shebang of making a GUI prompt to prompt for translation value but that seems unnecessary (why not just use the parameters tab, yanno?)
Anyway, try this:
Oh, you both are lifesavers! I used to do some programming in Visual Basic, so I get the gist of most of it, but of course there will be differences. Jaderail, would you consider a quick beta of my freebie, once I implement this code? I don't want to get specific here, not yet anyway. Be more than happy to Beta for you. Just drop me a PM.
Are you okay with me using this code as is (minus the funny text like Move it, move it, move it :) )? It totally makes sense, I was just unsure about naming conventions for variables. Also, if I had gone through the trouble of trying to write it myself, I would have forgotten to include the other two axes, thereby hitting an error again and again, beating my head to a pulp against the wall.
The main reason for doing this instead of relying on parameter dials is because if the person wants to put 15 of these in the scene, it would be a pain to line up each one, and the align tab would not help in this case. Of course, logic tells us once you figure out the distance of the first one, the rest should just be a matter of typing in the same value for each new instance. But reading through the forum, it is quite clear that "click this icon" is much preferred over "do this math" and a lot of people would not think to remember the distance between each one. I included one of those empty poses to tell the user that the distance between two is 141.20, but most ignore those, I think.
Which leads to another question... to use instancing or not? I am not 100% clear on the difference between an instance and simply putting another figure into the scene. But, I will read up on that
Of course, the ideal scenario, which I will endeavor to write on another project, would be a GUI that prompt for how many instances and in what configuration, then the script lays the whole thing out for them. But I haven't done any kind of coding in about 12 years, so my brain is a little foggy on most of that.
Sure, use the code. There are only a few ways to do this and all of them involve the same root functionality. Variable names are variable names. You could make them anything you want. I like to prefix mine. g_ for global, l_ for local, n for number, o for object, etc. after that it's just a reasonably descriptive name. The function name can also be just about anything (so long as you don't try and use an existing function name, that can get ugly) so feel free to personalize it. the // stuff is just comments.
You may want to look at adding undo functionality around the main for loop if you want the action to be part of the undo stack.
Basically there are three undo actions...
You need a begin and an accept, cancel is optional.
RichardH pointed out a few mistakes in the original code (not fatal ones, but mistakes nonetheless)... I've corrected them in the original code posting. Please double check that you have the current version.
Will do, thanks. I'm glad I haven't had the chance to try the other yet, I would have probably gotten frustrated. That being said, I would have worked it out, which is how I learned coding in the first place.
The code worked, I wouldn't have posted it without that, but I was accidentally using undeclared variables. I'd declared locals but created new globals on the fly. LOL. Fortunately (?) DAZ Script lets you do that, but it's bad practice.