Issue with scripts

@pascal you helped me with some scripts a few years ago. they were working fine then I got a new computer… seeing this message

help please thanks!

Hello- post the script, please.

-Pascal

Labeler.py (1.2 KB)
@pascal

Hello - as far as I can see this works here - how are you launching the script?

-Pascal

run python script command

I get that error above in my first post

Hello- that should work - does here - but doing it slightly differently here - try that.

Labeler.py (1.2 KB)

-Pascal

thank you !

what did you do? cus it’s happening to all my scripts…

@pascal - started doing this and now can’t use again
image

Hello - make sure you are running the one that has these lines

        textObj= rs.coercerhinoobject(X)
        #textObj = sc.doc.Objects.Find(X)

-Pascal

I redownloaded the one you uploaded…

@pascal

import rhinoscriptsyntax as rs
import scriptcontext as sc
import Rhino


def AveragePoints(aPts):
    P = len(aPts)
    X = Y = Z = 0
    L = len(aPts)
    for i in range(len(aPts)):
        X = X + aPts[i].X
        Y = Y + aPts[i].Y
        Z = Z + aPts[i].Z
        
    return Rhino.Geometry.Point3d(X/L, Y/L, Z/L)


def Labeler():
    
    ids = rs.GetObjects("Select objects to label.", preselect=True)
    
    if not ids:return
    height = 1
    if sc.sticky.has_key("LABEL_HEIGHT"):
        height = sc.sticky["LABEL_HEIGHT"]
        
    height = rs.GetReal("Set text height", height)
    if not height: return
    
    sc.sticky["LABEL_HEIGHT"] = height
    
    
    for id in ids:
        
        name = rs.ObjectName(id)
        if not name:
            continue
        bb = rs.BoundingBox(id)
        pt = AveragePoints(bb)
        text = "%<objectname(" + chr(34) + str(id) + chr(34) + ")>%"
        X = rs.AddText(" ", pt, height)
        textObj= rs.coercerhinoobject(X)
        #textObj = sc.doc.Objects.Find(X)
        textObj.Geometry.TextFormula = text
        sc.doc.Objects.Replace(X, textObj.Geometry)
   
    sc.doc.Views.Redraw()
    
if __name__ == "__main__": Labeler()