View Full Version : on mouse click function? or on selection?

11 November 2005, 07:58 AM
Just want to know if there it a way to ctach a mouse click without using tool?

For example if the user clicks on a polygon, i want to update my script to show the material ID of the selected face.
In the same way that it happens in the edit poly rollout...


11 November 2005, 08:23 AM
you probably need to use a selectionchanged callback for this.


11 November 2005, 11:20 AM
sweet, thanks :D

is there a way to get it only when faces selected(or just subobject)?

11 November 2005, 02:51 PM
I would sugesst taking a look at the polygon counter macroscript (in the UI/MacroScipts folder). You can extend the displayed text to include:
((($.selectedFaces as bitarray) as string)
which will add something like: #{1, 2..6, 50}
to the end of the number of faces listed in the viewport in the top left corner.

11 November 2005, 01:13 AM
So what im trying to do is get the order of selected face,

ie pick one face, then pick a second face as the order theyre selected in is important.

the array for the selection order needs to be updated for only 2 polys, the last 2 polys selected in the correct order. So if you select 3 polys or more, theres no need to update the selection order array.

11 November 2005, 01:21 AM
ah but arent faces/edges/vertices bitarrays i.e if you append them to an array they'll automatically get sort. Hmm i'll have a think.


11 November 2005, 02:23 AM
is an array always sorted? I would think an array would keep your values where you placed them?

11 November 2005, 03:54 AM
yes normally but bit arrays are tricky little things. I suppose you could do..hhmm basically cant i dont think pick two faces in the order you want and append them to an array in that order. It'll always go from low to hi eg. pick face 1020, then 30 it'll put them in order 30,1020.

i think there a getpolyops $ face.selection but that still wont help. One way would be to manually do it pick face - append hmm maybe you could do it with mouse point.

so pick face on click - append no. to array. On second click the same. Then do an if check if this array.count > 2 then #stop. I havent done mouse events in a while. But youd need a mouse event callback to check what youve click and probably a selection callback.

on mouse clicked do
if clickno = 1 then
if clickno = 2 then etc etc..


11 November 2005, 04:26 AM
ok thanks, ill have to mess with it more...

11 November 2005, 01:51 AM
ok i thought of an alternative idea, instead of on clicking or what ever, just have something that is contstantly doing a check?

Ie a loop that executes say once every second, is that possible? It would probly be easyer that way....

11 November 2005, 05:10 PM
try this:

global theObject, clickno
global pickedFaces = #()

theObject = selection[1]
clickno = 0

fn pickFaces msg ir obj faceNum shift ctrl alt =
if clickno >= 2 do return true
if faceNum != undefined do
setFaceSelection theObject ( meshop.getPolysUsingFace theObject #{faceNum} as array )

case msg of (
#freemove : #continue
#mouseAbort : return false
#mousePoint : (
format "clickno: %\n" clickNo
if faceNum != pickedFaces[1] do
clickno += 1
append pickedFaces (meshop.getPolysUsingFace theObject #{faceNum} as array)
#mouseMove : #continue

if theObject != undefined and classOf theObject == Editable_Mesh then (

max modify mode
subobjectlevel = 4
mousetrack on:theObject prompt:"Pick 2 faces\n" trackCallBack:pickFaces

format "polys picked: %\n" pickedFaces
else messageBox "Please select an Editable Mesh object first" title:"Pick Object"

That will return an array which will contain 2 more arrays holding the faces that make up the first 2 mesh 'polygons' that were clicked. It will not work on editable poly objects due to limitations in mouse track, but you can use the face arrays to convert the selections afterwards. Hope that helps!

11 November 2005, 05:36 PM
Check out Calros; post in this thread:

"one way to craete your own call backs is to use a timer in a rollout. the rollout could be outside of the monitors ress so it's not visible to the user.
the timer allows you to run script commands every time the timer ticks the intervals between ticks can pe specified in milli seconds. it can also be enbled and disabled. or yo can just distroy the rollout.

to many of this can get slow, but i've mannage to make some preaty nice call backs with it.

May be just what you're looking for.

11 November 2005, 05:02 AM
cool thanks guys :)

11 November 2005, 05:17 AM
cool thanks guys :)

CGTalk Moderation
11 November 2005, 05:17 AM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.