[Closed] Picking a vertex: Cannot find a solution:
Hi guys!
I’ll make it brief.
I cannot find a way to have max go into it’s “Select vertex mode”. The pickPoint function is close, but picking a point in perspective is not what I’m looking for. I’d like to make a tool that does the following:
- Establishes the current vertex-level selection as an array
- Prompts the user to pick a vertex
- Aligns the vertexes established as an array to an axis of the picked vertex
Basically, a sub-object level align tool. Several scripts exist that will “flatten” a collection of verts along a given axis, but I’m look for a way to get this effect, but without changing the position of the vertex being matched.
Any advice would be most helpful.
Thanks for the read, and I look forward to your response(s).
-Dave
Actually, now that I look at it, I think I can do with without using a special function. I just have to make it a little bulkier than I had wanted.
-Dave
Do you have a link to a tool that does the flatten to an axis? I might be able to assist you in making a slight modification to an existing tool?
Its a function of Meshtools, available at:
It’s in the Meshtools-Functions.ms file that comes with the script. Search for the string “–+ Flatten”.
The problem here, is that what I’m trying to do is a two stage function. The actual code should be quite simple, but it’s getting max to play along that’s tricky. The flatten function in meshtools is simple enough(though well written), but it operates on a collection of verts
alone. Basically, I need max to ask for a vert. How it gets selected is the problem.
A basic properties grab using:
foo_Vert1 = polyop.getVertSelection $ as array
foo_Vert1_POS = polyop.getvert $ foo_Vert1[1]
Will save the first vert’s numerical callout, and then grab it’s position. It would be a simple matter of appling the first vert’s, say, x position to a second vert’s x position. How the second vert is selected, I’m not sure. Perhaps a check to make sure only one is selected with a prompt box to select only one if more than one is selected…dunno. That sounds annoying.
Thanks for the help. It’s not a pressing issue, as it’s just a tool that I think many would find usefull, especially for using editable poly techniques for creating hard-surfaces.
Thanks!
-Dave
well try this…
foo_Vert1 = polyop.getVertSelection $ as array
foo_Vert1_POS = polyop.getvert $ foo_Vert1[1]
for eachVert in foo_Vert1 do
(
currentVert = polyop.getvert $ eachVert
currentVert.x = foo_Vert1_POS.x
--currentVert.y = foo_Vert1_POS.y
--currentVert.z = foo_Vert1_POS.z
polyop.setvert $ eachVert currentVert;
)
If you want a more elegant solution i.e. being able to pick an axis (currently just x) through a UI then you might want to make the changes to the existing align axis script.
Thanks for the help, man. I’ve come up with a very similar solution with a UI and some error correction. It’s probably of little interest to you, but I’ll post the final code when I get it all worked out.
Thanks again!
-Dave
Hmm Maybe the RC Menu can be used for the UI !!!
What I would do is this:
*Let the user select multiple vertices and press a button/icon/shortcut to launch your Align tool.
*At this point, grab the current vertex selection and register a WHEN callback monitoring the selection of the current object.
*When the WHEN callback is triggered because the user changed selection, check to see if only one vertex is selected. If yes, grab the one vertex and perform the alignment using the previous array of selected vertices and the new selection.
*Unregister the WHEN callback.
I have done this in a couple of cases, even more complicated ones (see the script for selecting Edge Loops and Rings I posted to this board some months ago – it was even using a cascade of general and WHEN callbacks to always monitor the current object’s SO selection!)
Here is an example without the actual alignment code:
(
if selection.count == 1 and classof $ == Editable_Poly and subObjectLevel == 1 do
(
theVertsArray = (polyop.getVertSelection $) as array
format "Selected % Vertices! Now select one vertex...
" theVertsArray.count
when select $ change handleAt:#redrawViews id:#monitorVertices do
(
if selection.count == 1 and classof $ == Editable_Poly and subObjectLevel == 1 do
(
theVert = (polyop.getVertSelection $) as array
if theVert.count == 1 do
(
format "Selected Single Vertex %.
" theVertsArray[1]
deleteAllChangeHandlers id:#monitorVertices
--DO SOMETHING HERE
)
)
)
)
)
Hey, thanks Bobo!
Yeah, that’s exactly how I did it at first. I later decided after a good bit of use that I wanted a quicker approach, so I just used the pickPoint function and will assume the user can make use of snaps. It works quite well. I’ve got a bunch of checks in there to make sure the user has one object selected, that it is an editable_poly object, and that at least one vert is selected before the tool can be used.
I’ve got it divided between 4 macroscripts now. Align X, Align Y, Align Z, and Align XYZ. I’m making icons for them now.
Thanks alot to everyone for your help! I now have a pretty neat tool working here.
Heres the AlignX code:
(
if selection.count == 1 and classof $.baseobject == Editable_Poly and subobjectlevel == 1 and polyop.getvertselection $ != #{} then
--------------------------------------------------------------
(
-------------------------------
with undo on
-------------------------------
-------------------------------
global DMB_VertAlign_Verts = polyop.getVertSelection $ as array
global DMB_VertAlign_Vert_POS = for i in 1 to DMB_VertAlign_Verts.count collect polyop.getVert $ DMB_VertAlign_Verts[i]
global DMB_VertAlign_New_Vert = pickpoint snap:#3d
-------------------------------
-------------------------------
if DMB_VertAlign_New_Vert != #rightClick then
(
global DMB_VertAlign_New_Vert_POS_X = DMB_VertAlign_New_Vert[1]
for i in 1 to DMB_VertAlign_Verts.count do
(
polyop.setVert $ DMB_VertAlign_Verts[i] [DMB_VertAlign_New_Vert_POS_X, DMB_VertAlign_Vert_POS[i][2], DMB_VertAlign_Vert_POS[i][3]]
)
)
-------------------------------
-------------------------------
else
(
messageBox "Tool Aborted"
)
)
-------------------------------
--------------------------------------------------------------
else
(
messageBox "This tool only works on a single EditablePoly Object while vertexes are selected"
)
)
----------------------------------------------------------------------------------------------------------------------------------
-Dave