I was looking through the list of functions in the reference and I found a function called CLAMP that I tried to use, but when I did I got an error saying the global name CLAMP wasn’t defined. I’m assuming this means I haven’t imported whatever CLAMP is a part of. I went back to the reference and the function is listed as undefined, and I can’t figure out what I need to import to gain access to it.
If anyone knows what I need to import to get access to clamp, that would be nice. If anyone knows how I can look up that information for any function in the reference, that would be even better.
In the meantime, I’m just writing my own clamping function.
Thanks in advance, cheers.
A grep command turns up the definition of CLAMP in direct/src/DirectUtil.py, i.e. module direct.DirectUtil. For the record, it’s a trivial definition:
def CLAMP(val, minVal, maxVal):
return min(max(val, minVal), maxVal)
I don’t think it was specifically intended to be a globally visible function, but the reference auto-generator appears to be fairly non-discriminating about the functions it picks up. (Nor is it immediately obvious how it could be improved to be more discriminating, but that’s the nature of Python. Maybe it could mention only those functions that are listed in an all for the module?)
Also, the doc generator should tell you which module the function came from.
I’m not sure what you’re referring to wen you say the doc generator.
My panda install (I’m using 1.5.4 because I couldn’t get the maya2egg85.exe to work in the latest build) only put a few things in the start menu, including the sample programs, the links to websites (which are broken because they point to panda.etc.cmu.edu which produces a server not found error) and the uninstall. I also looked through the folders for anything with doc or help in the name and couldn’t find anything. What is the doc generator?
I mean the program that generates the API reference on this website.
Sorry, I realize in hindsight how misleading my statement was. When I said, “the doc generator should tell you which module the function came from,” I wasn’t directing you to a place to find the answer; I was pointing out a deficiency in the doc generator, which should tell you this, but obviously doesn’t.
It was more of a note to myself (or anyone interested) take a look at this problem and fix it.
Oh, okay, that makes sense. Well thanks again David. You’ve done an amazing job answering question after question that I’ve posted, and I really do appreciate it.
Actually, there is global clampScalar(min,max,value) function, defined in PythonUtil.py.
Right, but in neither case does the online API tell you what you need to import to use the functions.
And I think the former really shouldn’t be documented at all, because it’s a local helper function only, and only globally-visible by accident. Adding it to the documentation only clutters up the page with uselessness and contributes to confusion. (There are many such local helper functions that appear on the API reference page, and I think this is a mistake.)
Hrm, it’s actually a well-exposed function as that file does not contain an all. I think adding an all to DirectUtil.py would solve the problem (or it should).
Although I do still think we need to use a more Python-based approach to the API reference tool. The current one is hard to maintain and has lots of troubles and limitations.
In the end, I just made my own clamping function using the definition David posted. Thanks for the help, guys.