[Sidefx-houdini-list] Delete by id Python SOP

Olex P hoknamahn at gmail.com
Tue Mar 1 04:48:13 EST 2011


Forgot to mention. Before you create an idlist you do something like

idlist = n.userData("myidlist")
if idlist == None:
   createIdList()
   n.setUserData("myidlist", idlist)

If you want to force regeneration of idlist you can put a button and
call setUserData() method or you can check if current frame equal to
sim start frame and force regeneration.

On Tue, Mar 1, 2011 at 9:37 AM, Olex P <hoknamahn at gmail.com> wrote:
> Hi Steven,
>
> If you want to calculate id list once and reuse it you can do the following:
>
> n = hou.pwd()
> n.setUserData("myidlist", idlist)
>
> ...
>
> # fetch already generated islist
> n.userData("myidlist")
>
> This should be a generic and transparent way.
>
> On Tue, Mar 1, 2011 at 5:13 AM, sgustafso at gmail.com <sgustafso at gmail.com> wrote:
>> The way I like to do id kills is to develop a solid copy attribute SOP (via hdk) that chooses source/target points by matching attributes. Then to delete by ID, you group the points, add a marker point attribute (say, dodelete) set to 1 for the points you want to delete, use the custom sop to copy the marker attribute to the animated points, and then delete all points for which the marker evals to 1. Then time shift to freeze the selection and wrap it in an otl.
>> When you break it up like this, it becomes really easy to do arbitrary procedural kills. Eg, select a set of points within a bounding object, and kill them over the full range of a sim according to id.
>>
>> The point sop can match by id when given two inputs. It kept failing to match correctly in H10, so I had to do an hdk equivalent. But I think it might have (hopefully) been improved for h11. So it might be worth seeing if that's a workable solution for transferring a delete marker by ID matching. If so, that makes this pretty easy to setup as an otl, and should scale well to large particle sims and kill counts.
>>
>> Sure, you /can/ do the matching in Python, but imo Python scales far too poorly for this kind of task, especially if you're hoping to use this with large particle sims. Throw a million particles and a kill list with 10,000 ids at it and see how well it performs. (Same goes for hscript $ID expressions: fine for 10 or 20 kills, but try and eval the expression for 1000 unique ids!)
>>
>>>Peter Bowmar <pbowmar at gmail.com> wrote:
>>>
>>>This is how I've done it at a few places. However, at least 5 years
>>>ago, I found it only worked up to a certain point then Houdini would
>>>crash. I was just using $ID == 5 || $ID == 123 etc populated by a
>>>simple script in a Delete SOP's expression field. I bet 64 bit not such
>>>a problem but I could be wrong. I like the Parm idea being populated
>>>because it's easy to test and see visually (in the parms) what is going
>>>on. Cheers, Peter B On 28 February 2011 18:30, Tom Nixon
>>><ignivomous at gmail.com> wrote: > Another option is to have a top level
>>>parameter populate with the id's > selected and reference that
>>>parameter for your list. This way, if you are > selecting points on
>>>multiple frames, you'll be fine. > > On Tue, Mar 1, 2011 at 1:57 AM,
>>>Stephen Tucker > <stucker at allegrodigital.com>wrote: > >> >> You'd
>>>likely want to have your script place down a time shift node that is >>
>>>set to be the current frame, and then reference the points that are
>>>present >> in that node. >> >> >> >> >> > Date: Tue, 1 Mar 2011
>>>09:45:22 +0800 >> > From: steve_nong at pointy.tv >> > To:
>>>sidefx-houdini-list at sidefx.com >> > Subject: Re: [Sidefx-houdini-list]
>>>Delete by id Python SOP >> > >> > Okay, >> > >> > The following works
>>>for me but the id list keeps changing. Is there a >> > way to set the
>>>id list for the frame I select the points and not have >> > it compute
>>>again? Do I create a button to trigger it? >> > >> > >> > point_ids =
>>>map(int,geo.pointFloatAttribValues("id")) >> > id_mapping = {} >> > >>
>>>> for id, point in zip(point_ids, geo.points()): >> >
>>>id_mapping[id] = point >> > >> > f = lambda id: id_mapping[id] >> >
>>>geo.deletePoints(map(f, iList)) >> > >> > >> > Thanks again! >> > >> >
>>>Cheers! >> > steven >> > >> > >> > > Thanks guys for the code snippets.
>>>I'll implement them and see what >> > > works best since it's a pretty
>>>heavy particle system. >> > > >> > > Cheers! >> > > steven >> > > >> >
>>>> >> > >> Some other ways that should be faster for large point counts
>>>and >> > >> depending on the number of ids you have to filter: >> > >>
>>>>> > >> points_to_delete = [] >> > >> point_ids =
>>>map(int,geo.pointFloatAttribValues("id")) >> > >> for point_id, point
>>>in zip(point_ids, geo.points()): >> > >> if point_id in ids: >> >
>>>>> points_to_delete.append(point) >> > >>
>>>geo.deletePoints(points_to_delete) >> > >> >> > >> ####################
>>>>> > >> >> > >> point_ids = map(int,geo.pointFloatAttribValues("id"))
>>>>> > >> id_mapping = {} >> > >> >> > >> for id, point in zip(point_ids,
>>>geo.points()): >> > >> id_mapping[id] = point >> > >> >> > >> f =
>>>lambda id: id_mapping[id] >> > >> geo.deletePrims(map(f, idlist)) >> >
>>>>> >> > >> >> > >> >> > >> >> > >> >> > >> On Mon, Feb 28, 2011 at 8:08
>>>AM, Graham Thompson >> > >> <captainhammy at gmail.com> wrote: >> > >>> To
>>>delete points or primitives you need to pass a list/tuple of >> > >>>
>>>hou.Point/hou.Prim objects to hou.Geometry.delete[Points/Prims] so >> >
>>>>>> you >> > >>> could do a couple of things: >> > >>> >> > >>> If your
>>>ids always match your point numbers you could do something >> > >>>
>>>like this: >> > >>> >> > >>> to_delete = geo.globPoints("
>>>".join(map(str, idlist))) >> > >>> geo.deletePoints(to_delete) >> > >>>
>>>>> > >>> If they don't match then you could do something like: >> > >>>
>>>>> > >>> attr_pointer = geo.findPointAttrib("id") >> > >>> to_delete =
>>>[] >> > >>> for point in geo.points(): >> > >>> if
>>>point.intAttribValue(attr_pointer) in idlist: >> > >>>
>>>to_delete.append(point) >> > >>> >> > >>> geo.deletePoints(to_delete)
>>>>> > >>> >> > >>> Better still you could do something like this: >> >
>>>>>> >> > >>> attr_pointer = geo.findPointAttrib("id") >> > >>>
>>>id_filter = lambda point: point.intAttribValue(attr_pointer) in >> >
>>>>>> idlist >> > >>> points_to_delete = filter(id_filter, points) >> >
>>>>>> geo.deletePoints(points_to_delete) >> > >>> >> > >>> >> > >>> On
>>>Mon, Feb 28, 2011 at 7:32 AM, steven ong <steve_nong at pointy.tv> >> >
>>>>>> wrote: >> > >>>> Hi, >> > >>>> >> > >>>> I'm writing my first
>>>Python SOP to delete points by id. I've >> > >>>> managed to get >> >
>>>>>>> the ids of the points I selected in a tuple (should I use a list
>>>>> > >>>> instead?) >> > >>>> and wondering how do I delete them by id?
>>>>> > >>>> >> > >>>> My idea is to match all the points (particle system
>>>with changing >> > >>>> point >> > >>>> count) to the id list I have
>>>and delete those that matched. I'm >> > >>>> still trying >> > >>>> to
>>>figure out how to do this simple comparison and call the delete >> >
>>>>>>> function. >> > >>>> Does the delete function work with id? Or can
>>>I do >> > >>>> >> > >>>> for point in points(): >> > >>>>
>>>point.delete(point.intAttribValue() == idlist[point]) >> > >>>> >> >
>>>>>>> I'm typing the above from memory so it's probably wrong but I >> >
>>>>>>> think >> > >>>> you get >> > >>>> the idea. >> > >>>> >> > >>>>
>>>Another question I have is, how do I make sure the SOP doesn't >> >
>>>>>>> change the >> > >>>> list of ids every time the SOP cooks? I guess
>>>I'm asking for ways >> > >>>> to control >> > >>>> the SOP, for
>>>example, what functions or methods should I be using? >> > >>>> >> >
>>>>>>> I'm a python noob and trying to wrap my brain around the hou >> >
>>>>>>> module. >> > >>>> >> > >>>> Thank you very much. >> > >>>> >> >
>>>>>>> Cheers! >> > >>>> steven >> >
>>>>>>>_____________________________________________
>>>>> > >>>> Sidefx-houdini-list mailing list >> > >>>>
>>>Sidefx-houdini-list at sidefx.com >> > >>>>
>>>https://lists.sidefx.com:443/mailman/listinfo/sidefx-houdini-list<https://lists.sidefx.com/mailman/listinfo/sidefx-houdini-list>;
>>>>> > >>>> >> > >>> >> > >>_____________________________________________
>>>>> > >> Sidefx-houdini-list mailing list >> > >>
>>>Sidefx-houdini-list at sidefx.com >> > >>
>>>https://lists.sidefx.com:443/mailman/listinfo/sidefx-houdini-list<https://lists.sidefx.com/mailman/listinfo/sidefx-houdini-list>;
>>>>> > >> >> > > >> > > >> >
>>>>_____________________________________________
>>>>> > > Sidefx-houdini-list mailing list >> > >
>>>Sidefx-houdini-list at sidefx.com >> > >
>>>https://lists.sidefx.com:443/mailman/listinfo/sidefx-houdini-list<https://lists.sidefx.com/mailman/listinfo/sidefx-houdini-list>;
>>>>> > > >> > >> > >> >_____________________________________________
>>>>> > Sidefx-houdini-list mailing list >> >
>>>Sidefx-houdini-list at sidefx.com >> >
>>>https://lists.sidefx.com:443/mailman/listinfo/sidefx-houdini-list<https://lists.sidefx.com/mailman/listinfo/sidefx-houdini-list>;
>>>>> >>_____________________________________________
>>>>> Sidefx-houdini-list mailing list >> Sidefx-houdini-list at sidefx.com
>>>>>
>>>https://lists.sidefx.com:443/mailman/listinfo/sidefx-houdini-list<https://lists.sidefx.com/mailman/listinfo/sidefx-houdini-list>;
>>>>> >_____________________________________________
>>>> Sidefx-houdini-list mailing list > Sidefx-houdini-list at sidefx.com >
>>>https://lists.sidefx.com:443/mailman/listinfo/sidefx-houdini-list > --
>>>No, I am not on Facebook._____________________________________________
>>>Sidefx-houdini-list mailing list Sidefx-houdini-list at sidefx.com
>>>https://lists.sidefx.com:443/mailman/listinfo/sidefx-houdini-list
>>
>> --
>> Sent from my Android phone with K-9 Mail. Please excuse my brevity.
>> _______________________________________________
>> Sidefx-houdini-list mailing list
>> Sidefx-houdini-list at sidefx.com
>> https://lists.sidefx.com:443/mailman/listinfo/sidefx-houdini-list
>>
>



More information about the Sidefx-houdini-list mailing list