I am using following code (LayerDot) to label (tag) the objects with textdots using layernames. As the code is used mostly on layout view, i need help for select/pick object in a detail within a layout view.
Thank you in advance
import rhinoscriptsyntax as rs
object = rs.GetObjectEx(“Select part to label”, 0, False )
if object is None: return
layer = rs.ObjectLayer(object)
if layer is None: return
colour = rs.ObjectColor(object)
point1 = rs.AddPoint(object)
layerName = layer.split(“::”)[-1]
if not point2: return
dot = rs.AddTextDot(layerName, point2)
line = rs.AddLine(point1,point2)
my_group = rs.AddGroup()
objs = [dot, point1, line]
below is an example function which returns the Rhino object and selection point. I’ve used the attached example file for testing.
You can get all required information (layer, layername, object id) from the returned rhino object.
GetObjectExFromInactiveDetail.py (1.8 KB)
ExampleFile.3dm (91.7 KB)
Your script work just fine.
The idea behind the
InactiveDetailPickEnabled is to enable picking objects in inactive details while a layout view is active. The original purpose for this was to pick model geometry when creating dimensions in a layout.
Hope this helps.
Hi @dale, thanks for testing. In my initial post, i had 2 details which where overlapping. After i’ve found out that this broke the picker, i’ve edited my post.
In case this is useful to anyone, try to avoid selecting the detail object itself, it might result in an invalid pick point from the WorldToPageTransform.
Thank you so much…It worked great !!
Thank you for your support.
Could you help me? i can select the object only by picking any edge (or visible vertex, surface isocurve etc) of the object. Most of my detail views are in shaded / rendered mode and would like also to pick any point (indicated with X) of the object. See example below;
I modified the part (DoSomething) of the code to create Leader instead of TextDot. I believe that is more effective…
And here the code;
PartLabelWithLeader.py (1.7 KB)
Hi @yigit, that seems to be a limitation of
InactiveDetailPickEnabled to which i don’t know a solution. Maybe @dale can tune the object getter to allow selecting also on shaded areas instead of edges and isocurves. Alternatively, you can bump up isocurve density before labeling and then turn them back when finished.
btw. you can change line 43 to see the leader line when picking:
point2 = rs.GetPoint("Text location", pick_pt)
Could you help me about my final request?
Hi @yigit, there is also a workaround if you prompt for the object using my GetObjectEx picker and then prompt for the first and second point using just
rs.GetPoint. This way you can pick the object from an inactive detail view (by clicking on an edge) and ignore
Been learning some scripting from @clement so figured I’d share an iteration of this script for those who don’t script at all yet: These give the Object Name and the Object Layer in the TextDot, respectively. (Clement, feel free to make anything cleaner/better )
GetObjectExFromInactiveDetail_Name.py (1.7 KB)
GetObjectExFromInactiveDetail_Layer.py (1.8 KB)
I’ll be making one for Leaders (diff option than the Dot), as well.
I’ve already made one for object Names. Check it if it works for you.
Don’t actually remember who’s I based on.
annotation_name.py (1.3 KB)
Thanks, @Screamer it works!
Altho - I tried my hand at tweaking it so I could draw a Leader as I normally would, with the Pickpoint at the object, one coming off at an angle, and the final termination point coming off horizontally for the Text. Not working great yet. I’m happy to research, but figured I’d share what I tweaked (Lines 31-33)
Before I paste that here, I’ll mention that I think the best scenario is to be able to just run the ol’ standard Leader annotation, where you can see the Leader lines and pickpoints as you draw them, but have it use the target object’s name as the text.
go = Rhino.Input.Custom.GetObject()
go.SetCommandPrompt("Select object to annotate:")
go.InactiveDetailPickEnabled = True
rc = go.Get()
if rc == Rhino.Input.GetResult.Object:
objref = go.Object(0)
# restrict to pick selection, prevent window selection
if objref.SelectionMethod()!= Rhino.DocObjects.SelectionMethod.MousePick:
print "Selection should be performed by picking"
obj = objref.Object()
name = rs.ObjectName(obj.Id)
name1 = "%<ObjectName(" + "'" + obj.Id.ToString() + "'" + ")>%"
pickPt = objref.SelectionPoint()
if not pickPt: return
detail_sn = objref.SelectionViewDetailSerialNumber()
if detail_sn > 0:
detail = sc.doc.Objects.Find(detail_sn)
if isinstance(detail, Rhino.DocObjects.DetailViewObject):
point2 = rs.GetPoint("", pickPt)
if not point2: return
point3 = rs.GetPoint("Text location", pickPt)
if not point3: return
pts.extend([pickPt, point2, point3])
leader = rs.AddLeader(pts, text=name1)
# Rhino.Geometry.Leader.LeaderHasLanding(leader) = True
if __name__ == '__main__':
There is an issue by selecting objects on DetailView. The command “go.InactiveDetailPickEnabled” does not allow you to pick the object where you click just (Yellow Cross) on a shaded surface / face / polysurface etc
… See example pls…
Maybe works with Isocurves on in detail display…?