Could someone share a python, C#, or VBscript that inputs a list of guid’s and select the corresponding objects in Rhino ?
Would be much appreciated
Could someone share a python, C#, or VBscript that inputs a list of guid’s and select the corresponding objects in Rhino ?
Would be much appreciated
Hi Olivier ,
Something like this last line here:
import rhinoscriptsyntax as rs
id_list = ['894b6c7d-6581-4fb6-a65b-c09b4e5dc88a',
'501983de-d55b-417d-92d2-9ce7b1cc78ee',
'd12c3658-0824-4471-9b77-a9ba801eda16',
'd17e0228-af5b-4f19-8853-2f0205a3168d']
#this line of could could/should be enough to select all objects in the list
for listed_id in id_list: rs.SelectObject(listed_id)
But maybe you need to add some code to make it work in grasshopper as I suspect you want to use it there?
I made a gh version that operated from within a python component:
select_idlist.gh (5.3 KB)
"""Provides a scripting component.
Inputs:
x: The x script variable
y: The y script variable
Output:
a: The a output variable"""
__author__ = "Willem"
__version__ = "2019.09.26"
import rhinoscriptsyntax as rs
import Rhino
import System
doc = Rhino.RhinoDoc.ActiveDoc
separate_lines = id_list.split('\n')
for str_id in separate_lines:
obj_id = System.Guid(str_id)
rhobj = doc.Objects.Find(obj_id)
rhobj.Select(True)
Maybe you should also define how that list is defined?
I now assumed a single text with on each line the string of the id
-Willem
Hi Willem,
Wow, thanks !
I rather provide a list of guids rather than a simple text.
The workflow is as follows :
-Reference a bunch of geometry
-Grasshopper filters these objects (for example “objects with no names”)
-Using the guid’s of the filtered objects, select them in Rhino
In this case, it allows me to hide all the other objects in my scene an go on giving names to the un-named objects.
But this is just one example, I am likely to make more complex selections, and rather do it through GH rather than fiddling with selection filters in Rhino :
This script unselect all currently selected objects and then select all object with no name.
private void RunScript(List<Guid> guids, bool Select, ref object A)
{
if(Select){
this.RhinoDocument.Objects.UnselectAll();
foreach(Guid guid in guids){
if(this.RhinoDocument.Objects.FindId(guid).Attributes.Name == null){
this.RhinoDocument.Objects.Select(guid, true, true, true);
}
}
}
}
Edit: it can be made to work with all kind of objects. This first solution work with [Geometry pipeline] so only with simple geometry objects (visible)…
I made a list for testing, and that works already.
So if you can leave it like this and it works on both multiline strings and lists
-Willem
Err… I don’t get it
If I feed a list, it complains about “Guid objects having no attribute “split””.
I Riccardo,
Thanks ! That works like a charm.
I got rid of the filter for “Has name ?” because I want to do my own filters ; this one was just a specific case.
So there : I can at last select Rhino stuff from within Grasshopper !!!
Indeed I was testing with strings and you passed guids.
I leave it be because Riccardo already provided a solution for guids.
The component works super well, but today, I realize that a specific block (all it’s instances) will not be selected.
Any idea why ?
My c# code has a:
“if(this.RhinoDocument.Objects.FindId(guid).Attributes.Name == null){ …”
Your screw has a name (nickname), so it won’t be selected.
Remove that if statement or remove the name on the block…
Thanks for the explanation, it helps !
What’s the purpose of rejecting blocks with nicknames (just curious).
Maybe I did misunderstand you, but it seems you asked for that?
OK, got it.
Selecting objects with no name was just an example of a set of guid’s that can be selected by other means.
My real concern was how to select them based on these guid’s.
I understand how that was confusing.
Thanks again !
Hello @maje90
the component work well! but Is it possible to able to highlight only active selected object (by guid) and deselect previous objects?
Thank you in advance
… what do you mean? Please explain in detail. (sorry i’m not native english)
to deselect simply add this line where you need it:
this.RhinoDocument.Objects.UnselectAll();
Thank you @maje90,
I explain better. For e.g. If I select object by GUID I see on screen the highlight of selection on object. So when I change a selection by another GUID I need to see new highlight selection and automatically cancel the previous one and so on…
I hope I was more clear.
Thank you again
Sorry i don’t understand.
My script already fit your description…?
Hi @maje90,
Yes, your component works perfect! But inside my specific definition It is behaving strangely…
I don’t know what the problem could be, the guid data come from Human UI interface (by selection as attached video). The strange thing is that if I instead come from the same geometry by simple selection your component works well (continue watching the video).
Do you have any idea about it?
Thank you!
I have no knowledge of Human UI, maybe try with a DataDam at 0.25 seconds…