Notifications
Clear all

[Closed] unwrap_uvw and select element

Has anyone ever noticed discrepancies between selecting an element on a uvw unwrap modifier in the viewport and in script? I have essentially what are a series of attached objects that has a uvw unwrap. I’d like to write a tool to help me quickly separate their individual uvs, but am having a difficult time with what seems like an easy first step. If I go into face mode and select by element and manually select a face in the viewport it selects what was that entire object (10 faces), which is what I’d expect. But if select the same face through script, it returns only two of the faces. Here is the code I’m currently using, any help is appreciated.

theObj = $
max modify mode
unwrapMod=Unwrap_UVW()
addModifier theObj unwrapMod
modPanel.setCurrentObject unwrapMod 

uvw2=unwrapMod.unwrap2
uvw2.setTVSubObjectMode 3
uvw2.setTVElementMode true
uvw2.setGeomSelectElementMode true

uvw2.selectFaces #{3}
uvw2.selectElement()
completeredraw()

currentSelection = uvw2.getSelectedFaces()
format "current Selection = % 
" currentSelection
9 Replies

what elements do you want to select? geo faces or map faces?
“Select By Element” in Unwrap_UVW UI means expanding geo selection to geo element.
“Select Element” in UVWs Editor means expanding map selection to map element.

Well, I’m not sure I understand the difference. How is a map element set? What I would like is the same result as going into face subobject mode on the UVW Unwrap, clicking the “Select By Element” check box in the modifier panel, and selecting a face. I would assume that’s setGeomSelectElementMode but neither seem to work; independently or together.

1 Reply
(@denist)
Joined: 11 months ago

Posts: 0

OK. You want to get GEO face elements. But you have to understand that geo face element might not be the same as map element.
Unwrap_UVW interfaces don’t have a function to expand geo selection to element. So you have to write it yourself.
there are functions that you need:
numberPolygonsByNode
selectPolygonsByNode
expandGeomFaceSelection
getSelectedPolygonsByNode

OK, thanks for the tips. I’ll check it out @ lunch and let you know how it goes.

OK, what I’ve discovered is that adding a “expandGeomFaceSelection()” to the end of my script seems to do what I need, or at least from what I’ve tested, expands the current face selection to the element level. The other functions you listed seem to be for using unwrap on multiple objects, which I am not doing. I have an unwrap on 1 object which was created by attaching several objects together.

Thanks for the help. Unless I’m misunderstanding something, I think I’m good to go.

1 Reply
(@denist)
Joined: 11 months ago

Posts: 0

expandGeomFaceSelection doesn’t expand to element. You have to call this function while the selection keeps grow.

The other functions you listed seem to be for using unwrap on multiple objects, which I am not doing.

you wrote “I have essentially what are a series of attached objects that has a uvw unwrap”. I thoughе that objects are under the same unwrap modifier.

expandGeomFaceSelection doesn’t expand to element. You have to call this function while the selection keeps grow.

Hmm, that stinks. Seems to be working, but I certainly haven’t tested it thoroughly. OK, so I guess my question / problem still stands. Just so were on the same page here is what I am doing. . .

  1. take 10 edit poly objects
  2. attach them
  3. Apply UVW Unwrap
  4. Select Element in UVW Unwrap through script

I’ve tried a few simple cases (boxes, teapots, etc.) and when I select using unwrap_uvw.selectElement() it works, but on some cases it doesn’t expand to the full geometry element. Selecting manually in the viewport with “Select By Element” enabled always seems to return the results I want, I just can’t seem to replicate that behavior through script 100% of the time.

if you have PolyMeshObject you can use polyop methods to get all geo elements.
that’s easy:


fn getFaceElements node:selection[1] = if iskindof node Editable_Poly or iskindof node PolyMeshObject do 
(
	elems = #()
	faces = node.faces as bitarray
	while (f = (faces as array)[1]) != undefined do
	(
		elem = polyop.getElementsUsingFace node f
		append elems elem
		faces -= elem
	)
	elems
)

man, I never thought of using polyop methods to get the face list, that should have occurred to me. Thanks for all the help Denis.