Notifications
Clear all

[Closed] Checking if you have a face selected or not

While in Edit Poly mode in a I would like to check if there are any faces selected and if there are all the user to run a script. If no faces are selected and the user runs the script I would like to alert the user that they have to select some faces in order for this to work.

So pretty basic error checking and tool guidance but I have no idea why my prototype code is not working. Here is what I am testing with to try and figure out how this works.


-- Makes sure that we have only one window open at a time. 
if (( mainRoll != undefined) and ( mainRoll.isdisplayed)) do
(destroyDialog mainRoll ) -- test if dialog exist 

rollout mainRoll  "Scratch Pad"
(
	
	group "Face Selection"
	(
		button hp "Test Face Selection" align:#left width:85 height:20
	
	)
	
	On hp pressed do
	(
				selectedFaces = polyop.GetFaceSelection --selection[1]
				-- Get your current selection
				if selectedFaces == 0 then
				(
					messagebox "0 Faces Selected"
				)
				
				else if selectedFaces != 0 then
				(
					messagebox "More than 0 faces selected"
				)
	)

)
			
createDialog  mainRoll  175  450


As you can see all I am trying to do is get a message if the user either has or does not have a selection. but I just can not figure this out. I think it has something to do with

selectedFaces = polyop.GetFaceSelection --selection[1]

But I am not sure what I am doing incorrectly.

6 Replies

are you talking about Ediatable_Poly or Edit_Poly modifier?

if it’s editable poly then just node.selectedfaces.count
if it’s modifier then node.edit_poly.getselection #face

2 Replies
(@billyclint)
Joined: 11 months ago

Posts: 0

This was something that I was just reading about. I will try both and post back which one it is. I am pretty sure that its editable poly but I am not 100% sure. Thanks for the response.

(@billyclint)
Joined: 11 months ago

Posts: 0

Humm that did not help. Well it probably did but I am not sure what I am doing wrong with it. This looks like it should be so easy but I can not figure this out right now. I am going to still mess around with the code and see if I can figure it out.

it must work. do you get any error message?

The problem with your code is that the polyop.getFaceSelection requires one more parametter – you commented it. Why?
Also, the selectedFaces variable is a bitarray, so you can;t use
selectedFaces == 0 or != 0
This will do the job:

-- Makes sure that we have only one window open at a time. 
if (( mainRoll != undefined) and ( mainRoll.isdisplayed)) do
(destroyDialog mainRoll ) -- test if dialog exist 

rollout mainRoll  "Scratch Pad"
(
	
	group "Face Selection"
	(
		button hp "Test Face Selection" align:#left width:85 height:20
	
	)
	
	On hp pressed do
	(
		if selection.count == 1 then
		(
			if classof (curO = selection[1]) == Editable_Poly then
			(
				--	the selectedFaces is a bitarray, so...
				selectedFaces = polyop.GetFaceSelection curO
				-- Get your current selection
				if selectedFaces.numberset == 0 then
				(
					messagebox "0 Faces Selected"
				)				
				else 
				(	
					str = selectedFaces.numberset as string
					str += " faces are selected"
					messagebox str				
				)
			)
			else
				messagebox "The selected object is not an Editable Poly" title:"Invalid Selection"
		)
		else
			messagebox "Select only one editable poly object" title:"Invalid Selection"
	)
)			
createDialog  mainRoll  175  450
1 Reply
(@billyclint)
Joined: 11 months ago

Posts: 0

Woot that works and this gives me something to work with. I was just commenting things out to try and figure out what was going on. Thanks for the help and I will post back when I have some code working. Thanks for the help, its greatly appreciated.