Grasshopper

algorithmic modeling for Rhino

How to update uuids: open file, select objects by layer, and extract ids

We have pieced together a VB script component that opens a file, selects objects based on a given layer name, and extracts the object ids of everything on that layer. It works, but has a few problems, and I am wondering if anyone can help us work out the kinks.

The file name is driven by a slider that runs through different files, selecting each from a list of strings by index (we will use "animate slider" to make it run through all the values). We cannot seem to get it to work for more than one layer at a time, and so we have resorted to copying and pasting it, effectively opening the same file several times in a row to get all the lists of object ids. If we copy only the portion that extracts the ids, then the ids will not update. It seems that the same script that extracts the ids needs to open the files.

How can we rewrite this to get all the lists of ids for multiple layers in one script?

Thank you in advance, and thank you to everyone who we have learned from in order to piece together this script (especially Rajaa).
---------------------------------------------------

'Select curves and extract their uuids

If( Not Open ) Then Return

If Open Then

app.RunScript("_SelAll ")

app.RunScript("_delete ")
app.RunScript("-_import " & sFileName & " _Enter")

app.RunScript("-_ZE ")

app.RunScript("-_SelNone ")

End If

'Empty lists
m_ids.Clear()

' Dim context As IRhinoCommandContext

' Get a reference to the layer table
Dim layer_table As MRhinoLayerTable = doc.m_layer_table
' Get the current layer
Dim current_layer As IRhinoLayer = layer_table.CurrentLayer()

' Prompt for a layer name
Dim gs As String = layername

' Validate the string
Dim layer_name As String = gs.Trim()

' Find the layer
Dim layer_index As Integer = layer_table.FindLayer(layer_name)

' Get the layer
Dim layer As IRhinoLayer = layer_table(layer_index)

' Get all of the objects on the layer
Dim obj_list As MRhinoObject() = Nothing
Dim obj_count As Integer = doc.LookupObject(layer, obj_list)


'Iterate through all objects and isolate their uuids
For i As Integer = 0 To obj_count - 1
Dim id As Guid
id = obj_list(i).ModelObjectId
m_ids.Add(id)
Next

'Output names
ids = m_ids
A = sFilename

Views: 1146

Replies to This Discussion

Hi Benjamin,
Can you post or email me your ghx files and 3dm files you are using so that we can test the same thing?
Hi Rajaa,

I just sent you an email with all the necessary files attached.

Thank you in advance for any advice you might have.
Hi Ben,
I emailed you back a GH file.
Thank you Rajaa!!

It works great! Below is the final VB.net script that we used.

'Select curves and extract their uuids

If( Not Open ) Then
ids_tree = m_ids_tree
Return
End If

If Open Then

app.RunScript("_SelAll ")

app.RunScript("_delete ")
app.RunScript("-_import " & sFileName & " _Enter")

app.RunScript("-_ZE ")

app.RunScript("-_SelNone ")

End If

'Empty lists
'm_ids_list.Clear()
m_ids_tree.Clear()


' Dim context As IRhinoCommandContext

' Get a reference to the layer table
Dim layer_table As MRhinoLayerTable = doc.m_layer_table
' Get the current layer
Dim current_layer As IRhinoLayer = layer_table.CurrentLayer()

For j As Integer = 0 To layernames.Count() - 1

'Define a new guid list
'Dim ids As New List(Of Guid)
Dim path As New EH_Path(j)
'GH_path(j)


' Prompt for a layer name
Dim gs As String = layernames(j)
Print(layernames(j))

' Validate the string
Dim layer_name As String = gs.Trim()

' Find the layer
Dim layer_index As Integer = layer_table.FindLayer(layer_name)

' Get the layer
Dim layer As IRhinoLayer = layer_table(layer_index)

' Get all of the objects on the layer
Dim obj_list As MRhinoObject() = Nothing
Dim obj_count As Integer = doc.LookupObject(layer, obj_list)


'Iterate through all objects and isolate their uuids
For i As Integer = 0 To obj_count - 1
Dim id As Guid
id = obj_list(i).ModelObjectId
Print(id.ToString)
'ids.Add(id)
m_ids_tree.Add(id, path)
Next

'Add to private list
'm_ids_list.Add(ids)

Next

'Output names
'ids_list = m_ids_list
ids_tree = m_ids_tree
A = sFilename
Once again, it is excellent!!!!!
thank you thank you!!
You welcome :)
Would it reference several different object layers only by opening the file? Could you share the complete GHX files? It would be great. Thanx!
yes, it opens several object layers after opening the file, but you would need to input your own layer names and your own file paths. Since you would have to change the inputs, and that is the only thing different from the script above, my ghx is not any better than copying this into a component of your own and changing the inputs to that component.
I see, but i´m a novice at using VB yet, and I easily get lost in variables, inputs , outputs and its hints, classes...still learning...so I need to know more exactly which name/type hint of inputs and outputs must enter. My apologies for any inconvenience...but could you be more specific?. Thanx in advance
Attachments:
Need help with it, please

RSS

About

Translate

Search

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service