Tamis Posted January 6, 2008 Share Posted January 6, 2008 So i'm tryng to work with python in houdini. so far i understand that hou is the houdini modual that you use to controll houdini itself. hou.pwd means use the incomming geomatry when creating yout own operator(node) hou.pwd.geometry means acces the geometry from the incomming object. and hou.pwd.geometry.points means acces the points from that geometry. so no error this works oke. but when i type hou.pwd.geometry.points *2 it gives an error: unsuported operants type for: * 'instandcemethod' and 'int' i expect it to just multiply the position by 2 for each point ? Quote Link to comment Share on other sites More sharing options...
graham Posted January 6, 2008 Share Posted January 6, 2008 You are getting that error because you aren't actually calling the methods for those functions. Try hou.pwd().geometry().points() *2 instead. Quote Link to comment Share on other sites More sharing options...
Tamis Posted January 6, 2008 Author Share Posted January 6, 2008 Thnx now it isn't giving me any errors atleast a question tho what kind of statements would i be wrting inbetween ()? and *2 dosn't work my sphere isn't moving. Quote Link to comment Share on other sites More sharing options...
sibarrick Posted January 6, 2008 Share Posted January 6, 2008 I think you'll find that points() just returns a point type which consists of more than just the position, plus it will return a list of all the points. I haven't done this in python only the hdk but it seems very similar. I would expect that you would have to loop through all the points returned by points() and access their individual position method, pos() maybe, and then multiple those values by 2. Quote Link to comment Share on other sites More sharing options...
edward Posted January 6, 2008 Share Posted January 6, 2008 In the Windows > Python Shell window, type these to get more info: >>> help('hou.Geometry.points') >>> help('hou.Geometry.iterPoints') >>> help('hou.Point') Notice how there's a position() method in hou.Point that returns the position and a setPosition() method that allows you to set it. Putting all this together we get: geo = hou.pwd().geometry() for pt in geo.points(): pos = pt.position() pt.setPosition([pos[0]+2, pos[1], pos[2]]) Quote Link to comment Share on other sites More sharing options...
Tamis Posted January 6, 2008 Author Share Posted January 6, 2008 wowa that looks alot difrend then writing vex code !! thnx for the help, guess i'm going to have to study this a bit more. Quote Link to comment Share on other sites More sharing options...
symek Posted January 7, 2008 Share Posted January 7, 2008 (edited) First thing you should do is study concepts of object oriented programming and dynamic languages. Go through Python tutorial - the one supplied in python's Help. Then read "Dive into Python" - free book you can download from internet or buy printed. It will help you understand the nature of Python and tackle down the difference between dynamic and C-like languages (one of whom is VEX). There is also another story about HOM itself - this API is not very "pythonic" - because it really can't be like that. Fortunately once you get used to its weird functions() nature, you will use it with please . good luck! sy. Edited January 7, 2008 by SYmek Quote Link to comment Share on other sites More sharing options...
Tamis Posted January 7, 2008 Author Share Posted January 7, 2008 First thing you should do is study concepts of object oriented programming and dynamic languages. Go through Python tutorial - the one supplied in python's Help. Then read "Dive into Python" - free book you can download from internet or buy printed. It will help you understand the nature of Python and tackle down the difference between dynamic and C-like languages (one of whom is VEX).There is also another story about HOM itself - this API is not very "pythonic" - because it really can't be like that. Fortunately once you get used to its weird functions() nature, you will use it with please . good luck! sy. Thank you SYmek, It's always nice to have someone lay that bit of road for you so you don't need to go threw unnecessary pain. Quote Link to comment Share on other sites More sharing options...
Tamis Posted January 8, 2008 Author Share Posted January 8, 2008 (edited) Hey, i'm back so i got a bit further but i am stuck once more. so a couple of questions: i have been playng with the python shell, by using the dir command i can go into the structures. so dir(hou.Geometry.points) gives me: ['__call__', '__class__', '__cmp__', '__delattr__', '__doc__', '__get__', '__getattribute__', '__hash__', '__init__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__str__', 'im_class', 'im_func', 'im_self'] so i assume these are input variables and hou.Geometry.points is a function. but if this is so then were can i find pt ? geo = hou.pwd().geometry() for pt in geo.points(): pos = pt.position() pt.setPosition([pos[0]+2, pos[1], pos[2]]) it's not in there, so what are these __bla__ ? and were can i find the function(or structure) pt ? thank you for your pations edit: Oke so i found out that pt is a variable that contains geo.points. but now the question were did you get .postion from ? is it some kind of global function ? Edited January 8, 2008 by Tamis Quote Link to comment Share on other sites More sharing options...
sibarrick Posted January 8, 2008 Share Posted January 8, 2008 pt is just a user defined variable. It gets set to each "point" in the list of points returned by geo.points() Quote Link to comment Share on other sites More sharing options...
Marc Posted January 8, 2008 Share Posted January 8, 2008 The dir() function will return a list of attributes for that object. The '__' generally means that it's a private attribute and won't really mean much to you. 'pt' is a variable which the point is assigned to. So the 'for pt in geo.points():' will loop through the points and assign them to 'pt'. You can then access specific information about that point by using pt.position() etc. Does this make sense? M Quote Link to comment Share on other sites More sharing options...
Tamis Posted January 8, 2008 Author Share Posted January 8, 2008 (edited) wow, i was just making an edit and already 2 posts !! brilliant !. let me brake that down marc: what your sayng is that the variable pt gets overitten in the loop. the loop loops thrue .points() so it basicly dose the same operation on every single point in the array. now what i don't understand is were edward got this .position function(structure?) is it some sort of global function? Edited January 8, 2008 by Tamis Quote Link to comment Share on other sites More sharing options...
Marc Posted January 8, 2008 Share Posted January 8, 2008 If you look back at Ed's post you'll see that in hou.Point there is a position() method and a setPosition() method. The first will return the position and the second will set the position. I highly recommend reading the books Symek mentioned too. I know a few programming languages and Python was a little tricky to get my head around. Mainly, I think, because its syntax and names for things are so different than any other language. But if you read those then this will all be a lot easier, I promise that . M Quote Link to comment Share on other sites More sharing options...
Tamis Posted January 8, 2008 Author Share Posted January 8, 2008 thnx marc, python is indeed tricky defenatly because alot of things arn't clear because its all automatic. like create a variable you don't specifie if its a float int vector ect. also i'm confused by the . things not clear if something is a structure function variable ect. i'l be looking at that book again as you and symek mentiont didn't make mutch sense the first time tho . thnx for the help, hope to return the favor. Cheers: Quote Link to comment Share on other sites More sharing options...
Marc Posted January 8, 2008 Share Posted January 8, 2008 Sure. Feel free to ask questions here though, I'm sure there are many people who have the same problems with it that could benefit from a little explanation . Personally I'm just looking forward to the day that they document all of the python methods in Houdini. Quote Link to comment Share on other sites More sharing options...
symek Posted January 9, 2008 Share Posted January 9, 2008 (edited) also i'm confused by the . things not clear if something is a structure function variable ect. There is something in Python called "introspection". It basically means that every single python object has a knowledge about itself and that we (or Python) have an access to this knowledge. This is possible because every single python object is... an object not only a statement or expression - thus can posses attributes (which is quite different from variable, func() or operator in C - they state, express or do something but don't posses attributes). If you find your self in trouble to recognize some object's nature ask it to introduce itself. Simple writing its name in interpreter will show you its soul. object class, method, attribute etc. You can use type() build-in method also. Another handy note is that HOM consists almost exclusively with methods (and objects they belong to). An access to object's attributes is possible only with one, unique method() (function). This is HOM specific and has nothing to do with Python. Knowing this you can be sure that whenever you want to access/modify some object's attributes in HOM you should look for a method() for this. So non standard "=" assignment will apply. Methods names are very consistent and descriptive. good luck in diving sy. Edited January 9, 2008 by SYmek Quote Link to comment Share on other sites More sharing options...
Tamis Posted January 9, 2008 Author Share Posted January 9, 2008 For any one tryng to learn python: explenation of object oriented programming and procedual based programming: http://nl.youtube.com/watch?v=4_Oj4xcD52A Quote Link to comment Share on other sites More sharing options...
Tamis Posted January 12, 2008 Author Share Posted January 12, 2008 once more i'm a bit confused: # This code is called when instances of this SOP cook. geo = hou.pwd().geometry() # Add code to modify the contents of geo. geo.createPoint() p = geo.points() p.setPosition(0,0,-2) it is crashing on p.setPosition(0,0,-2) error: object has no attribute setPosition. im tryng to do the same as in SYmek example only for one point(i deleted other incomming points first). but houdini interpertates setPosition as a atribute and not as a method. do i have to declare these methods ? clearly missing something. Quote Link to comment Share on other sites More sharing options...
graham Posted January 12, 2008 Share Posted January 12, 2008 (edited) Your problem is that p is a list object and does not have a setPosition method. You have to index into the list then do setPosition. p[0].setPosition((0,0,-2)) for example, for the first/only point. I should also mention that your position value needs to be a tuple/hou.Vector3. Edited January 12, 2008 by Hammy Quote Link to comment Share on other sites More sharing options...
graham Posted January 12, 2008 Share Posted January 12, 2008 Also, you could also just go p = geo.createPoint() p.setPosition((0,0,-2)) thus skipping the indexing issue if you have a large number or points or whatever. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.