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
Tags: