Check if TextDotText already is in document

Hi!

I want to check the document for TextDotText when creating a new dot for similar texts, so I never have the same dots twice.

import rhinoscriptsyntax as rs

def AddReview():
nr = rs.StringBox (“Enter review number”, None, “Review number” )
note = rs.StringBox (“Enter review note”, None, “Review note” )
point = rs.GetPoint (“Select review location”)
allobj = rs.SelectObjects(
obj = rs.AddTextDot (nr, point)
if nr: rs.SetUserText(obj, “Nr”, nr)
if note: rs.SetUserText(obj, “Note”, note)

AddReview()

any ideas?

Regards,
Thomas

Add a cycle within a cycle checking every textdottext against every other one, but itself.

Hmm okay, i’m new at scripting. Can you give me a start?

I could if it was Rhino script. I don’t know Python too well. Mitch (Helvetosaur) might chime in to help ya.

I guess the simplest would be just to check all the dots in the document every time and see if a dot with the text already exists, if so, ask the user to choose a different text…

import rhinoscriptsyntax as rs

def GetAllDotTexts():
    dot_texts=set()
    dots=rs.ObjectsByType(8192)
    if dots:
        dot_texts=set()
        for dot in dots: dot_texts.add(rs.TextDotText(dot))
        #dot_texts is now the set of all dot texts in document
        #if no dots, returns an empty set
    return dot_texts
    
def DontDuplicateTextDots():
    text_dot_set=GetAllDotTexts()
    #run a loop
    while True:
        user_string=rs.GetString("Dot text?")
        if user_string is None or user_string=="": return
        if not user_string in text_dot_set:
            #no dot with this text in document, OK to add
            break
        else:
            #dot with this text already exists
            response=rs.MessageBox("Text dot already exists!",1)
            if response !=1: return
    pt=rs.GetPoint("Text dot insertion point?")
    if pt: rs.AddTextDot(user_string,pt)
DontDuplicateTextDots()

–Mitch

Thanks Mitch!

This is the result:

> import rhinoscriptsyntax as rs
> import time
> import getpass


> def GetAllDotTexts():
>     dot_texts=set()
>     dots=rs.ObjectsByType(8192)
>     if dots:
>         dot_texts=set()
>         for dot in dots: dot_texts.add(rs.TextDotText(dot))
>         #dot_texts is now the set of all dot texts in document
>         #if no dots, returns an empty set
>     return dot_texts

> def DontDuplicateTextDots():
>     text_dot_set=GetAllDotTexts()
>     #run a loop
>     while True:
>         no = rs.StringBox ("Enter review number", None, "Review number" )
>         if no is None or no=="": return
>         if not no in text_dot_set:
>             #no dot with this text in document, OK to add
>             break
>         else:
>             #dot with this text already exists
>             response=rs.MessageBox("Review number already exists!",1)
>             if response !=1: return
>     note = rs.StringBox ("Enter review note", None, "Review note" )
>     action = rs.StringBox("Action for", None, "Action")
>     datemod = time.strftime("%d/%m/%Y")
>     user = getpass.getuser()
>     point = rs.GetPoint ("Select review location")
>     obj = rs.AddTextDot (no, point)
>     if no: rs.SetUserText(obj, "No", no)
>     if note: rs.SetUserText(obj, "Note", note)
>     if action: rs.SetUserText(obj, "Action", action)
>     if user: rs.SetUserText(obj, "Modified by", user)
>     if datemod: rs.SetUserText(obj, "Date modified", datemod)
>     rs.SetUserText(obj, "Resolved (y/n)", "n")
>     rs.SetUserText(obj, "Info", " ")    
> DontDuplicateTextDots()