[Closed] select a to b ?
Hi,
Since I do not know much about maxscript, this question may seem stupid but I could not find anything about it.
I have objects which have unique names in a correct order. (box_a01, box_a02, box_a03…)
I put all of them in an array;
arr = $box_a* as array
how can I reach them in blocks? for example I want to select from box_a25 to box_a32.
In short I try to do this in the script language;
x = an integer variable
y = another integer
select box_a(x) to box_a(y)
put these in an array called “blockarr01”
thanks for your help and interest
Right, this is one way to do it. assuming “object_array” is the array.
blockarr01 = #()
[font=Courier New][/font]
sort object_array
selection_start = 25
selection_end = 30
for n = selection_start to selection_end do
(
blockarr01[block_arr01.count+1] = object_array[n]
)
Can i just suggest that in the long run it would be better to use more descriptive naming conventions. If you ever write a large piece of code and after a few weeks you need to go back to the code, it is so much easier to have naming conventions that are more descriptive.
This is not exactly trivial.
First, the array is always in CREATION order, so unless you created the boxes in the right order, they might not be numbered sequentially. For example, if you created 01, 02 and 03, then deleted 02 and created a new one, the order of the array would be 01,03,02 instead.
Another bad news – you cannot sort object arrays directly, you have to either do an indexed qsort or resort to collecting the names, sorting them and then converting the names back to objects uisng getNodeByName().
The latter is done like this:
theObjects = $Box* as array
theNames = for i in theObjects collect i.name
sort theNames
theObjects = for i in theNames collect getNodeByName i
At this point, theObjects will contain the objects in sorted order, assuming you don’t have duplicated names (which is technically possible and allowed in Max, a really bad design idea).
So now you have theObjects sorted and you can say
theChunkArray = for i = 10 to 19 collect theObjects[i]
This will give you the objects Box10 to Box19 in the array theChunksArray.
Now you could do stuff with the collected portion…
Ah, that makes good sense.
Suppose I really should test stuff before I blurt it out.
actually you both helped me greatly. Thank you very much.
I realized that creation order is much more important for my case than the names. Because that objects are created in the previous part of the script and what I need is the creation order. so,
theChunkArray = for i = 10 to 19 collect theObjects[i]
this is all I need for now. As I mentioned I am pretty inexperienced about scripting. maybe I am on the wrong way, but cant know before try. Thank you again for your help and quick replies.
Ah…, but if you created the boxes in this same script, you shouldn’t be using the $’’ notation to get your ‘theObjects’ array. You should put the boxes into theObjects when you create them. It would help to see your code, but when you create each box, do an: append theObjects myBox. Now you’re guaranteed to get the right box when you pull it out of theObjects, regardless of its name and it’ll be faster.
Actually I thought about that. But I couldnt figure out how to do it. I actually nearly completed the script, working on the adjustments and improvements. I know it is not a great or new idea, I am just working on it to learn. Probably there are much more and possibly better ways to accomplish the same effect. I guess there is no explanation needed to understand it, but just to be sure:
First part of the script creates a box, chamferbox or capsule for each pixel of a given image sequence and sets a height value relative to the color value of image sequences matching pixel. Second part animates the created objects height values according to the image sequence. An humble attempt to improve an example from maxscript help…
Anyway, here is the code.
macroscript Tik_Displace
category: "Tik Works"
tooltip: "Tik Displacer"
(
if RO != undefined then (closeRolloutFloater RO)
RO = NewRolloutFloater "TIK Displacer" 200 250
(
rollout Imapbutton "Image"
(
button choosemap "<" tooltip:"Select Video or Image" width:120
dropdownlist vox_type_ddl "Voxel Type" items:#("Box", "Chamferbox", "Capsule")
button yuru_bak "Execute"
on choosemap pressed do
(
z_d = selectbitmap ()
try choosemap.text=z_d.filename
catch (choosemap.text="<")
)
on yuru_bak pressed do
(
delete $VoxelBox* --Deletes all previous voxels
global arr = #()
global parallelchunk = #()
progressstart "Rendering Voxels..."
for y = 1 to z_d.height do
(
progressupdate (100.0 * y / z_d.height)
z_line = getpixels z_d [0,y-1] z_d.width
for x = 1 to z_d.width do
(
-- create voxels as boxes
if vox_type_ddl.selection == 1 then
(
b = box width:10 length:10 height:((z_line[x].value/2)+10)
)
else ()
-- creates voxels as chamferboxes
if vox_type_ddl.selection == 2 then
(
b = chamferbox width:10 length:10 height:((z_line[x].value/2)+10) fillet:2
)
else ()
-- creates voxels as capsules
if vox_type_ddl.selection == 3 then
(
b = capsule radius:5 sides:8 height:((z_line[x].value/2)+10)
)
else ()
b.pos = [x*10,-y*10,0]
b.wirecolor = gray
b.name = uniquename "VoxelBox"
)--end x loop
)--end y loop
arr = $voxelbox* as array --Makes all VoxelBox objects Array
parallelchunk = #(1)
for i = 1 to z_d.width do
(
append parallelchunk ((i*z_d.width)+1)
)
fn anima t =
(
for y = 1 to z_d.height do
(
z_d.frame = t
z_line = getpixels z_d [0,y-1] z_d.width
theChunkArray = for i = (parallelchunk[y]) to ((parallelchunk[y] + z_d.width) - 1) collect arr[i]
for x = 1 to z_d.width do
(
theChunkArray[x].height = ((z_line[x].value/2)+10)
)
)
)
animate on
for i in 1 to z_d.numframes do
(
at time i
(
anima (i)
)
)
progressend ()
)
)
addRollout Imapbutton RO
)
)