Maya2020Python Can't get the number of mel.eval('uvTkDoGetTexelDensity')

Maya2020Python Can't get the number of mel.eval('uvTkDoGetTexelDensity')

243202504
Enthusiast Enthusiast
1,762 Views
9 Replies
Message 1 of 10

Maya2020Python Can't get the number of mel.eval('uvTkDoGetTexelDensity')

243202504
Enthusiast
Enthusiast

I used Maya’s script editor to write the code, and I encountered a problem in it. I want to get the pixel density of my selected part. This function is available in Maya’s UV toolkit. Click the Get button as shown in the figure below. Get a number in the back box, but I don't know how to get this number through code. Including me, I can't get the 512 after the Map Size below.

The code I use is

 

mel.eval('uvTkDoGetTexelDensity')

 

当我打印它,我得到没有。也许此功能不会返回值,但会将获得的值给 UI 界面后面的框。

 

4 月 1 日, 吉马亚 · 伊金 · 吉亚 · 吉亚 · 吉特 · 吉夫 · 特夫特 · 特瓦特 · 特格特 · 吉夫(三)次次次的"大号"

我使用的代码是

 

mel.eval('uvTkDoGetTexelDensity')

 

打印打印可能这个功能没有返回值,而是把得到的值给了UI界面后面的方框里。

0 Likes
Accepted solutions (1)
1,763 Views
9 Replies
Replies (9)
Message 2 of 10

243202504
Enthusiast
Enthusiast

There are errors in the Chinese part above, just read English.

0 Likes
Message 3 of 10

243202504
Enthusiast
Enthusiast

When I print its value, I get None. Maybe this function will not return a return value, but will give the obtained value to the UI box later. I need your help and tell me how to get the average pixel density calculated in the box below.

0 Likes
Message 4 of 10

zewt
Collaborator
Collaborator
Accepted solution

uvTkDoGetTexelDensity is a callback for updating a UI field, it doesn't return a value.  It just takes the texture size and calls texGetTexelDensity:

 

map_size = cmds.optionVar('polyUVTexelDensityMapSize', q=True)

density = mel.eval('texGetTexelDensity(%i)' % map_size)

 

map_size is the texture size set in the options box.  The polyUVTexelDensityMapSize optionVar won't exist if the user hasn't used that options box before.  texGetTexelDensity will also raise an error if there's no object selected to query density for.

 

Message 5 of 10

243202504
Enthusiast
Enthusiast

Thanks for ur reply!

"map_size is the texture size set in the options box. The polyUVTexelDensityMapSize optionVar won't exist if the user hasn't used that options box before."

I don't know how to set texture size, I give a number in 'Map Size:' box (512). script editor raise 'uvTkTexelDensityChangeCB', and then I run 

 

import maya.cmds as cmds
 
map_size = cmds.optionVar('polyUVTexelDensityMapSize', q=True)
print map_size

 

it raise 

 

# Error: Object polyUVTexelDensityMapSize is invalid
# Traceback (most recent call last):
#   File "<maya console>", line 3, in <module>
# TypeError: Object polyUVTexelDensityMapSize is invalid # 

 

 

0 Likes
Message 6 of 10

243202504
Enthusiast
Enthusiast

ok i found a way ,

map_size = cmds.optionVar(q='polyUVTexelDensityMapSize')

and then i got print 512.

0 Likes
Message 7 of 10

zewt
Collaborator
Collaborator

FYI, that's just the last-used setting in the options box (and it won't exist if that options box has never been used).

 

0 Likes
Message 8 of 10

243202504
Enthusiast
Enthusiast

yeah,and i create a value,then it will be created.

i use it at my code first line like this

# coding=utf-8
import maya.cmds as cmds
from maya import mel
from functools import wraps

map_size = cmds.optionVar(q='polyUVTexelDensityMapSize')

and then it will be created.

0 Likes
Message 9 of 10

243202504
Enthusiast
Enthusiast
btw,i have a new quesion now,,, i can query the value of map_size,but i found,optionVar is undoable, queryable, and NOT editable. so if i want change the valuse of ui box, set size as 512 or 1024 ,how can i do ,what commnd should i use? ty!
0 Likes
Message 10 of 10

243202504
Enthusiast
Enthusiast

texCalculateTexelDensity

density = mel.eval('texGetTexelDensity(%i)' % map_size)

This line of code takes too long. Is there any other way? If I get the vertices of the face, the UV ratio and the texture size to calculate the accuracy, or if I don’t need to call mel, but directly use python to speed it up. This Lines of code take up more than 90% of the time consumed by my entire tool. I want to optimize it.