Delete empty attributes

   6924   12   2
User Avatar
Member
36 posts
Joined: March 2014
Offline
Hey all,
Is there a way to delete all empty attributes? I googled and didn't find any solution for this, it seams like it should be pretty straight forward.
User Avatar
Member
14 posts
Joined: Nov. 2019
Offline
Hi,
You can use attribute delete node.
User Avatar
Member
36 posts
Joined: March 2014
Offline
Hi Peitro,

I know I can use it to delete specific attributes or all using the *, but is there a way to delete all attributes that doesn't hold any information? (I'm working with imported OSM data and have a lot of empty attributes)
User Avatar
Member
2038 posts
Joined: Sept. 2015
Offline
All attributes have some information in some form, whether that's a float with a value of 0, or even an empty int array - which would be of a length of zero. I mention that because from such information you can create groups or other attributes based on that information.

However, if what you want to do is what I think - You can't say, with points, delete the attribute (based on a condition like it having a value of 0) for only some of the points, and have the other points retain that attribute with other values.

I haven't worked with OSM data but I'm assuming they can have high loads on memory and your wanting to reduce that to make it more workable?

You might want to be more specific on what it is your wanting to do or having issues with.

Otherwise why can't you use attribute delete node? If those attributes ‘don’t hold any information'.
User Avatar
Member
36 posts
Joined: March 2014
Offline
Hi BabaJ,

Thanks for your answer. I will try to explain more in detail what it is I want. From the OSM data I have a lot of prim attributes in string form, there is about 100 or more. A lot of the attributes don't have any entries on any of the prims, as in the picture, “diet_vegan”, “diet_vegetarian”, “display”, “drink_club_mate”, “drink_water_legal” for example, and I'm looking to delete the whole attribute-“category” if that is the case.




As I understood it with the attribute delete I can write all the attributes I want to delete but as they are so many that would take a long time. So how would I delete all prim-string attributes that has no text?

I haven't worked with OSM data but I'm assuming they can have high loads on memory and your wanting to reduce that to make it more workable?
Exactly
Edited by stinzen - Nov. 7, 2019 11:20:28

Attachments:
OSM_attributes.JPG (40.4 KB)

User Avatar
Member
900 posts
Joined: Feb. 2016
Offline
hello, try the following code in a python sop
geo = node.geometry()

prim_attribs = list(geo.primAttribs())

allprims = geo.prims()
for p in allprims:
    for attrib in prim_attribs:
        if p.stringAttribValue(attrib) != "" :
            prim_attribs.remove(attrib)
            break

for attrib in prim_attribs:
    attrib.destroy()


This is very crude, for example it would throw an error if you have non-string attributes.
Up to you to build the exceptions.

Cheers.
User Avatar
Member
900 posts
Joined: Feb. 2016
Offline
ps.
note that this is a post-fix.

Ideally you should be able to clean the OSM file at import stage. Before the parsing occurs. That would be more efficient than creating unnecessary attribs and then remove them.
So maybe you want to mess with the OSM_import node itself.
Edited by Andr - Nov. 7, 2019 12:52:14
User Avatar
Staff
6187 posts
Joined: July 2005
Offline
Faster way might be to use nuniqueval/uniqueval to see if the string attribute has only blank strings in it. Can do it in a detail wrangle that builds up a detail string of attributes to delete that the attribute delete brings in with a details() expression. Bonus points is to wire your geometry to test to the *second* input of the detail wrangle so you have no copy costs for generating this.
User Avatar
Member
900 posts
Joined: Feb. 2016
Offline
jlait
Faster way might be to use nuniqueval/uniqueval to see if the string attribute has only blank strings in it. Can do it in a detail wrangle that builds up a detail string of attributes to delete that the attribute delete brings in with a details() expression. Bonus points is to wire your geometry to test to the *second* input of the detail wrangle so you have no copy costs for generating this.

I've been trying to use vex on first instance, but I wasn't aware of these functions you mentioned. Very handy.
It should be definitely faster.

But now I'm curious, how does nuniqueval() even work, doesn't it have to iterate over all prims as well?
User Avatar
Member
7757 posts
Joined: Sept. 2011
Online
Andr
jlait
Faster way might be to use nuniqueval/uniqueval to see if the string attribute has only blank strings in it. Can do it in a detail wrangle that builds up a detail string of attributes to delete that the attribute delete brings in with a details() expression. Bonus points is to wire your geometry to test to the *second* input of the detail wrangle so you have no copy costs for generating this.

I've been trying to use vex on first instance, but I wasn't aware of these functions you mentioned. Very handy.
It should be definitely faster.

But now I'm curious, how does nuniqueval() even work, doesn't it have to iterate over all prims as well?

String attributes do not store a value per element, rather they store a list of unique values. This makes it trivial to get the number of unique values for string attributes.
User Avatar
Member
2038 posts
Joined: Sept. 2015
Offline
As I stated before, strings that are ‘empty’ or have no ‘value’ can be treated as a value(string length of 0) and used accordingly.

Here is an example of how to use vex and the results within a delete attribute node.

Attachments:
Delete_Empty_Attribute_via_VEX.hiplc (93.0 KB)

User Avatar
Member
900 posts
Joined: Feb. 2016
Offline
jsmack
Andr
jlait
Faster way might be to use nuniqueval/uniqueval to see if the string attribute has only blank strings in it. Can do it in a detail wrangle that builds up a detail string of attributes to delete that the attribute delete brings in with a details() expression. Bonus points is to wire your geometry to test to the *second* input of the detail wrangle so you have no copy costs for generating this.

I've been trying to use vex on first instance, but I wasn't aware of these functions you mentioned. Very handy.
It should be definitely faster.

But now I'm curious, how does nuniqueval() even work, doesn't it have to iterate over all prims as well?

String attributes do not store a value per element, rather they store a list of unique values. This makes it trivial to get the number of unique values for string attributes.
thanks for the insight
User Avatar
Member
41 posts
Joined: Feb. 2018
Offline
Late to the OSM party and just found this post. I wanna report that python is (surprisingly) 5+ times faster in my case. Code based on Andr's:
node = hou.pwd()
geo = node.geometry()

prim_attribs = geo.primAttribs()

for attr in prim_attribs:
    if attr.dataType() != hou.attribData.String:
        continue
    allValues = set(geo.primStringAttribValues(attr.name()))
    if allValues == set([""]):
        attr.destroy()
  • Quick Links