PDA

View Full Version : unwrap_uvw and select element


jonlauf
06-17-2011, 02:26 PM
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 = % \n" currentSelection

denisT
06-17-2011, 04:19 PM
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.

jonlauf
06-17-2011, 04:30 PM
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.

denisT
06-17-2011, 04:49 PM
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.

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

jonlauf
06-17-2011, 05:04 PM
OK, thanks for the tips. I'll check it out @ lunch and let you know how it goes.

jonlauf
06-17-2011, 05:49 PM
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.

denisT
06-17-2011, 06:19 PM
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.

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.

jonlauf
06-17-2011, 06:38 PM
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.

denisT
06-17-2011, 07:20 PM
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
)

jonlauf
06-17-2011, 08:27 PM
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.

CGTalk Moderation
06-17-2011, 08:27 PM
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.