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
YA
import Rhino
import rhinoscriptsyntax as rs
def LayerDot():
while True:
rs.Command(“_Cplane _View”)
object = rs.GetObjectEx(“Select part to label”, 0, False )
if object is None: return
layer = rs.ObjectLayer(object[0])
if layer is None: return
colour = rs.ObjectColor(object[0])
point1 = rs.AddPoint(object[3])
if object[3]:
layerName = layer.split(“::”)[-1]
point2=rs.GetPoint()
if not point2: return
if layerName:
dot = rs.AddTextDot(layerName, point2)
rs.TextDotHeight(dot, height=10)
line = rs.AddLine(point1,point2)
my_group = rs.AddGroup()
objs = [dot, point1, line]
rs.AddObjectsToGroup(objs, my_group)
rs.ObjectColor(point1, (170,5,5))
rs.ObjectLayer(point1, layer)
rs.ObjectColor(line, (170,5,5))
rs.ObjectLayer(line, layer)
rs.ObjectColor(dot, (170,5,5))
rs.ObjectLayer(dot, layer)
rs.ObjectPrintWidth(objs, 0.2)
LayerDot()
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.
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 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;
PS:
I modified the part (DoSomething) of the code to create Leader instead of TextDot. I believe that is more effective…
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:
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 pick_pt…
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 )
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.
def annotation_name():
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"
return
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):
pickPt.Transform(detail.WorldToPageTransform)
point2 = rs.GetPoint("", pickPt)
if not point2: return
point3 = rs.GetPoint("Text location", pickPt)
if not point3: return
pts=[]
pts.extend([pickPt, point2, point3])
leader = rs.AddLeader(pts, text=name1)
# Rhino.Geometry.Leader.LeaderHasLanding(leader) = True
if __name__ == '__main__':
annotation_name()
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