Delete Prim without List

   4692   17   1
User Avatar
Member
766 posts
Joined: April 2014
Offline
How do I delete the primitive without storing anything in a list; more then one suggestion is very welcome.
for pnts in geo.prims():
    if pnts.number() == 5:
        geo.deletePrims(pnts,keep_points=False)
【T】【C】【S】
User Avatar
Member
471 posts
Joined: Nov. 2013
Offline
Hello.
Did you try this?
geo.deletePrims([geo.iterPrims()[primitive_number]])
User Avatar
Member
766 posts
Joined: April 2014
Offline
I was hoping I could do it within the ForLoop since I'm already iterating over the primitives, why doesn't
geo.deletePrims(pnts,keep_points=True)
not work ?
【T】【C】【S】
User Avatar
Member
471 posts
Joined: Nov. 2013
Offline
Because it takes sequence of objects so you need to type this:
geo.deletePrims([pnts], keep_points=True)
Edited by Nima - Nov. 24, 2017 18:30:58
User Avatar
Member
766 posts
Joined: April 2014
Offline
Thank You The first argument is treated as a list
【T】【C】【S】
User Avatar
Member
766 posts
Joined: April 2014
Offline
for pnts in geo.prims():
    if pnts.number() == 2:
        strPrm = geo.deletePrims([pnts],keep_points=False)
        fcList = FaceList.append(strPrm)
        print(fcList)

One other thing. I want to store the prim into a list but printing “fcList” prints nothing ?
【T】【C】【S】
User Avatar
Member
387 posts
Joined: Nov. 2008
Offline
fcList is the result of the “append” method not list itself. You want to
print(FaceList)

https://docs.python.org/2/tutorial/datastructures.html [docs.python.org]
User Avatar
Member
766 posts
Joined: April 2014
Offline
pezetko
fcList is the result of the “append” method not list itself. You want to
print(FaceList)

https://docs.python.org/2/tutorial/datastructures.html [docs.python.org]

Yes, but I put it in a variable because it was not printing a list of the prims or points I stored in the list when using “FaceList” ?
【T】【C】【S】
User Avatar
Member
471 posts
Joined: Nov. 2013
Offline
Christopher_R
for pnts in geo.prims():
if pnts.number() == 2:
strPrm = geo.deletePrims(,keep_points=False)
fcList = FaceList.append(strPrm)
print(fcList)


geo.deletePrims(,keep_points=False) returns a None hence if you try to print it nothing will get.
User Avatar
Member
766 posts
Joined: April 2014
Offline
Nima
Christopher_R
for pnts in geo.prims():
if pnts.number() == 2:
strPrm = geo.deletePrims(,keep_points=False)
fcList = FaceList.append(strPrm)
print(fcList)


geo.deletePrims(,keep_points=False) returns a None hence if you try to print it nothing will get.

Originally what you're telling I sorta knew would happen but I was hoping I could put it in a list; unless you know of another solution ?

You wouldn't happen to know if destroy() in PrimGroup keeps the prim/points in the group but removes them from the geometry or completely removes the prim/group from the group and geometry ?
Edited by _Christopher_ - Nov. 26, 2017 01:16:38
【T】【C】【S】
User Avatar
Member
471 posts
Joined: Nov. 2013
Offline
What do you want to do exactly?
These type of functions return None so you need to hold your data in a list before you delete them out.
For instance in your example you can simply put 5 in a list however why do you want to do it after deletion whereas you can have it simply before deletion process?
User Avatar
Member
766 posts
Joined: April 2014
Offline
If I'm doing this right;

if pnts.number() == 5:
        tt = FaceList.append(pnts)
        #strPrm = geo.deletePrims([pnts],keep_points=False)
        strGroupPrim = hou.PrimGroup
        strGroupPrim.add(pnts)
        print(tt)

This is storing primitive #5 in a list, but why is the first item in the list None and the second item in the list primitive #5; shouldn't there not be a first item in the list ? The second last line gives an error ?
Edited by _Christopher_ - Nov. 26, 2017 10:30:05
【T】【C】【S】
User Avatar
Member
471 posts
Joined: Nov. 2013
Offline
strGroupPrim = hou.PrimGroup isn't instantiate new object (try print id() for both).
It is a new name for hou.PrimGroup instead of typing hou.PrimGroup over and over again.
This is why you get unbound method error because you don't create a real object of the class.
In order to create new instance of the class you should type strGroupPrim = hou.PrimGroup().
However you can't instantiate directly because it raises up an attribute error and says No constructor defined!
hou.PrimGroup is a class that lets you to modify and manipulate a group so it doesn't make sense to have ability of creating objects directly from this class.
You should create a new primitive group that returns hou.PrimGroup in this case you can use all of hou.PrimGroup methods without any problem.
Let's complete your code:

node = hou.pwd()
geo = node.geometry()

# Add code to modify contents of geo.
# Use drop down menu to select examples.

group = geo.createPrimGroup("Mark_for_Delete")
FaceList = []   # Declare that FaceList is an empty list

for pnts in geo.prims():                
    if pnts.number() == 5 or pnts.number() == 10:           
        FaceList.append(pnts)
        #strPrm = geo.deletePrims([pnts],keep_points=False)        
        group.add(pnts)
        print FaceList[len(FaceList) - 1].number()

Now you have a primitive group called Mark_for_Delete and you can use in a delete SOP node.
If you uncomment the three last line, primitives number 5 and 10 will delete as well.
Hope this helps.
Edited by Nima - Nov. 26, 2017 19:28:50
User Avatar
Member
766 posts
Joined: April 2014
Offline
hou.PrimGroup is a class that lets you to modify and manipulate a group so it doesn't make sense to have ability of creating objects directly from this class.

Can you create objects directly from this class ?

You can't instantiate directly without an error unless you populate a new class instance with values; and that is only done by calling a method on a class instance with the type which want to return ?
【T】【C】【S】
User Avatar
Member
471 posts
Joined: Nov. 2013
Offline
Yes that's it.
Object creates for you by calling geo.createPrimGroup().
User Avatar
Member
766 posts
Joined: April 2014
Offline
node = hou.pwd()
geo = node.geometry()

tt = geo.createPoint
bb = tt.number()

Since createPoint() returns hou.Point I should be able to use the number() method from hou.Point ?
【T】【C】【S】
User Avatar
Member
471 posts
Joined: Nov. 2013
Offline
tt is a short name for geo.createPoint if you don't put parentheses however if you try to run your code it's not work because createPoint wants argument but you don't tell python what they are (even your function hasn't parameters)
in these two manners you can do:

#First Manner:

tt = geo.createPoint()    #If you put parentheses at the front of createPoint, object will create.
bb = tt.number()          #shouldn't put any parentheses at the front of tt

print bb

#Seccnd Manner:

tt = geo.createPoint      #If you don't put parentheses at the front of createPoint, object won't create
bb = tt().number()        #should put parentheses at the front of tt

print bb
User Avatar
Member
766 posts
Joined: April 2014
Offline
Would you know whether you can loop over all primitives and select them the same way you would, set the component mode to primitives and use the lasso tool to select the primitives in the viewport ?
Edited by _Christopher_ - Nov. 30, 2017 22:59:28
【T】【C】【S】
  • Quick Links