Isotropix Forums

Help needed with module names vs. import xxx

Clarisse Scripting related topics

Help needed with module names vs. import xxx

Unread postby atnreg » Sat Aug 12, 2017 12:29 pm

Hi!

I cannot understand the logic in module name in SDK documentation vs. import.

For example, I want to use the get_filename() function that I found in SDK documentation for SysFilesystem class.

If I try the command directly i.e. ix.get_filename, it does not exist.
If I try to import SysFilesystem, it does not exist.

How can I know what module I need to import to use different classes? :o

Please somebody explain how this works, there are many functions in classes I would like to use but I cannot use them because I have no idea what needs to be imported :)

Thank you! :)

Antti
Intel i7(6-core),32GB RAM,NVIDIA GTX690 (2GPU)+GTX Titan Black,Win10Pro 64bit
Clarisse 3.5SP2,Blender,ZBrush,Onyx,(3D-Coat,Lightwave+Octane...)
Clarisse since 2016-09-29 (Py 2017-01-04), Python since 2016-11-10
I do all 3D stuff for fun, no business
atnreg
 
Posts: 257
Joined: Mon Sep 19, 2016 5:20 pm
Location: Helsinki, Finland

Re: Help needed with module names vs. import xxx

Unread postby atnreg » Wed Aug 16, 2017 12:14 pm

Anyone?
This may be stupid question to all you Clarisse gurus but I really cannot understand the relation/logic so please give at least some hint :)

Antti
Intel i7(6-core),32GB RAM,NVIDIA GTX690 (2GPU)+GTX Titan Black,Win10Pro 64bit
Clarisse 3.5SP2,Blender,ZBrush,Onyx,(3D-Coat,Lightwave+Octane...)
Clarisse since 2016-09-29 (Py 2017-01-04), Python since 2016-11-10
I do all 3D stuff for fun, no business
atnreg
 
Posts: 257
Joined: Mon Sep 19, 2016 5:20 pm
Location: Helsinki, Finland

Re: Help needed with module names vs. import xxx

Unread postby bvaldes » Wed Aug 16, 2017 1:59 pm

Hi,

You have to understand that all functions inside of the doc aren't for python. Lot's of them are for c++ only. The get_filename() function is only for c++.
You can see that this function does not ask any parameter. It's because it's a function of class. You have to create the class then you will be able to launch this function. The class is SysFile() and ask for some parameters.

In your case, you have to find a function which depends on a class like OfSomething: OfObject, OfAttr... To interact with the items.

In all the cases you don't have to import a package to use the python api INSIDE of Clarisse. The modules are already imported and you just have to use the ix module.

I don't really know why you need a function like get_filename() but I think that this is to get the filename of a map or a geometry. For that it is quite simple because all in formations are inside of the attribute fillename of your node.

python code

item = ix.get_item("project://my_item")
attr = item.get_attribute("filename")
filename = attr.get_string()
print filename

So before to try to use a function found inside of the doc you have to understand how to use it, which are the dependencies...

Regards
Benoit VALDES
Isotropix
Clarisse QA
User avatar
bvaldes
 
Posts: 153
Joined: Mon Sep 26, 2016 11:44 am

Re: Help needed with module names vs. import xxx

Unread postby atnreg » Thu Aug 17, 2017 10:21 pm

Hmm...ok. I thought that function was generic function to get filename part of full path (the doc clearly says so).
SysFilesystem Class Reference
static CoreString get_filename (const CoreString &full_path)
Return the filename as string from the specified path. Example: "/root/tmp/log.tmp" will return "log.tmp".

The problem is that you never know if a function or class is even available in Python. I saw some remarks of 'C++ only' or something like that but very rarely.

>So before to try to use a function found inside of the doc you have to understand how to use it, which are the dependencies...

EXACTLY my point, WHERE can I get that information? Not in SDK docs at least :)

Antti
Intel i7(6-core),32GB RAM,NVIDIA GTX690 (2GPU)+GTX Titan Black,Win10Pro 64bit
Clarisse 3.5SP2,Blender,ZBrush,Onyx,(3D-Coat,Lightwave+Octane...)
Clarisse since 2016-09-29 (Py 2017-01-04), Python since 2016-11-10
I do all 3D stuff for fun, no business
atnreg
 
Posts: 257
Joined: Mon Sep 19, 2016 5:20 pm
Location: Helsinki, Finland

Re: Help needed with module names vs. import xxx

Unread postby bvaldes » Fri Aug 18, 2017 10:22 am

Hi,

The information is in SDK docs:
Image
This hierarchy shows you what are the dependencies of the current class. If you are in the class OfSomething, or a class inherent of OfSomething, you can be sure at 99% that you can use the function (I prefer to say 99% to prevent a potential function that doesn't work).

Moreover, you are right, we have to improve the visibility of the function callable in Python. I create a new feature request (#7304) about this subject.

Regards
Benoit VALDES
Isotropix
Clarisse QA
User avatar
bvaldes
 
Posts: 153
Joined: Mon Sep 26, 2016 11:44 am

Re: Help needed with module names vs. import xxx

Unread postby atnreg » Sun Aug 20, 2017 1:52 pm

Ok, thanks, so all 'generic' functions should work as ix.funcname? And if not, then it is not callable from Python? Of course when I have some object, then I need to use object.funcname but otherwise it's always ix,funcname, not ix.something.funcname? This clears things a lot but please confirm it is like that for the 99% :) Hmm...actually that is not correct, for example for cmds you need to use ix.cmds.funcname.

So are the namespace list items the only ones that are needed to find any function (that is implemented in Python)?
Actually not because api is not listed there and still SOME functions are under it. And clarisse_helper is loaded to the root of ix.

Aaaarghhhh...this is what I mean, it is impossible to figure out how to call a function until you know it.

Please please add to the SDK docs the module path how to call that class functions from Python. Good place would be just below the class title. So that when you see some function you need, you only need to check the top of the page and append that to function name to call it.

For example:
cmds Namespace Reference
Python call path: ix.cmds

or

IOHelpers Class Reference
Python call path: ix.api.IOHelpers

or

OfAttr Class Reference
Python call path: class object

It took quite a while before I figured out how to call IOHelpers class methods (or actually I think I had to ask here). There is not a word referring to API on that class doc page so how could I guess that it needs the ix.api?

If there is some way to find that out already, then please explain how it works, to me it does not open.
Maybe I'm just stupid and cannot use the SDK docs properly but either way, please explain :)

Antti
Intel i7(6-core),32GB RAM,NVIDIA GTX690 (2GPU)+GTX Titan Black,Win10Pro 64bit
Clarisse 3.5SP2,Blender,ZBrush,Onyx,(3D-Coat,Lightwave+Octane...)
Clarisse since 2016-09-29 (Py 2017-01-04), Python since 2016-11-10
I do all 3D stuff for fun, no business
atnreg
 
Posts: 257
Joined: Mon Sep 19, 2016 5:20 pm
Location: Helsinki, Finland

Re: Help needed with module names vs. import xxx

Unread postby bvaldes » Mon Aug 21, 2017 9:25 am

Hi,

It is not ix.funcname because ix.funcname is for the helpers directly written in python. It's like ix.api.funcname except for IOHelper (that you should use rarely because helpers contain most of them) and cmds.

You are right there is, for now, no way to find this information inside of the SDK doc. I added your comments to the feature request #7304 to help to improve the SDK documentation.

You have a useful function in Python called dir(). This function list all the method of the given class or all functions inside of a module.

python code

def doesExists(fnc):
fncs = dir(ix.api)
if fnc in fncs:
return True
return False

print doesExists("AbcScene")

The function doesFncExists return True or False depending if the function or the class given in parameter exists in ix.api.

Regards
Benoit VALDES
Isotropix
Clarisse QA
User avatar
bvaldes
 
Posts: 153
Joined: Mon Sep 26, 2016 11:44 am

Re: Help needed with module names vs. import xxx

Unread postby atnreg » Mon Aug 21, 2017 2:57 pm

bvaldes wrote:Hi,

It is not ix.funcname because ix.funcname is for the helpers directly written in python. It's like ix.api.funcname except for IOHelper (that you should use rarely because helpers contain most of them) and cmds.

You are right there is, for now, no way to find this information inside of the SDK doc. I added your comments to the feature request #7304 to help to improve the SDK documentation.

You have a useful function in Python called dir(). This function list all the method of the given class or all functions inside of a module.

python code

def doesExists(fnc):
fncs = dir(ix.api)
if fnc in fncs:
return True
return False

print doesExists("AbcScene")

The function doesFncExists return True or False depending if the function or the class given in parameter exists in ix.api.

Regards


Ok, now I understand better and I know dir but have used it only to list the class members and as log only takes limited number of rows on one print, it has been a bit tricky. But I improved your script to use fnmatch and to search ix as well and optionally any class and show list of matches, that way I can do more flexible search. Thanks :)

Antti
Intel i7(6-core),32GB RAM,NVIDIA GTX690 (2GPU)+GTX Titan Black,Win10Pro 64bit
Clarisse 3.5SP2,Blender,ZBrush,Onyx,(3D-Coat,Lightwave+Octane...)
Clarisse since 2016-09-29 (Py 2017-01-04), Python since 2016-11-10
I do all 3D stuff for fun, no business
atnreg
 
Posts: 257
Joined: Mon Sep 19, 2016 5:20 pm
Location: Helsinki, Finland


Return to Scripting