Does not exist in ObjectTable...?

I don’t understand why my script does work now… it was working, but since, two weeks… on one moment it return:

Message: 461ae419-8c00-4a18-9184-1d51dbc5b53f does not exist in ObjectTable

Traceback:
line 1065, in coercerhinoobject, “C:\Users\Franck\AppData\Roaming\McNeel\Rhinoceros\7.0\Plug-ins\IronPython (814d908a-e25c-493d-97e9-ee3861957f49)\settings\lib\rhinoscript\utility.py”
line 1569, in SelectObject, “C:\Users\Franck\AppData\Roaming\McNeel\Rhinoceros\7.0\Plug-ins\IronPython (814d908a-e25c-493d-97e9-ee3861957f49)\settings\lib\rhinoscript\object.py”
line 275, in OrientedBox, “S:\SCRIPT\Python\X_PSEAPLAT.py”
line 60, in PseAPlat, “S:\SCRIPT\Python\X_PSEAPLAT.py”
line 312, in , “S:\SCRIPT\Python\X_PSEAPLAT.py”

i don’t know why this object does not exist in the ObjectTable… is it possible to find an object by this id?

thanks!!
Franck

my script can orient a lot of blocs on XY plane
can you check the two blocs on this file: Blocs to test.3dm (69.3 KB) the orange one is okay, but the red one return the error message… if someone can find why one is okay and the other no…

my script goes through all the blocks in the order of their numbering, explodes them, sorts the surfaces in order of size, and then it goes through all these surfaces to find which of these surfaces is the surfaces perpendicular to the thickness of the block, this is a bit complicated to explain like that, but it’s by going through the list of surfaces sorted by area that I get the error message on the red block and not on the orange block…

thank’s
Franck

Every element in the document, no matter if its simple point, a curve, a block or whatever you can select and modify, has a unique id. When you use RhinoScriptSyntax, you usually use this id for reference. However the moment you manually modify something in Rhino, you could in theory delete the object. E.G If you explode a block and recreate it, it will create a new RhinoObject with a new id. Therefore it is bad practice to hardcode the id in your scripts. I don‘t see the python file, but this is what I assume here.

You have removed that object from the model.
If you explode a polycurve and had its GUID, then the new generated curves will be added to the object table, and the OG polycurve will be removed.
Same applies to instance definitions and so on.

So, somewhere in your code you’ve deleted the object and you’re trying to perform some sort of operations with it.

Share your code so I can help you better should be an easy fix.

this is my script, i hope you’ll not fall from your chair when you’ll open it… :sweat_smile:
X_PSEAPLAT.py (11.7 KB)

test it with this file
Blocs to test.3dm (233.0 KB)

thank’s!
Nb:
Maybe @Helvetosaur can have a look… when I wrote this script he gave me a lot of solutions…

Hi @onlyforpeace
There you go with the fixxed script

# coding: utf-8
#triblocpypse02
import rhinoscriptsyntax as rs
from collections import Counter


def NbAngleDroit(cont):
    points=rs.CurvePoints(cont)
    lp = len(points)-1
    count=0
    for i in range(lp):
        angle=rs.Angle2( [points[i] , points[(i+1)%lp] ], [points[(i+1)%lp] , points[(i+2)%lp]])
        #print (angle)
        if round(angle[0])==90:count+=1
    #print count
    return count

def PseAPlat():
    ep_std=(400,200,100)
    tol=0.00001
    stop=False
    origine=rs.coerce3dpoint([0,0,0])
    blocs=rs.GetObjects('selectionne les blocs à trier',16)
    if not blocs : return
    #Test NOM de chaque Blocs
    rs.EnableRedraw(False)
    for bloc in blocs:
        if not rs.IsPolysurfaceClosed(bloc):
            rs.ObjectColor(bloc,(0,127,0))
            stop=True
        if not rs.ObjectName(bloc):
            rs.ObjectColor(bloc,(0,0,255))
            stop=True
        else:
            try:
                name=int(rs.ObjectName(bloc))
            except:
                rs.ObjectColor(bloc,(250,0,0))
                stop=True
    if stop:
        print('les verts ne sont pas fermés,les bleus n\'ont pas de nom et les rouges sont només n\'importe comment')
        return
    
    #tri par numero
    sorted_blocs=TriBlocParNum(blocs)
    ep400=[]
    ep200=[]
    ep100=[]
    epother=[]
    second_passage=False
    
    for bloc in sorted_blocs:
        if second_passage:
            decal= bboxdecal[1].X-bboxdecal[0].X+500
            origine.X+=decal
            
        second_passage=True
        
    #trouve la boite orientée sur le bloc
        orientedbox=OrientedBox(bloc,ep_std)
        #if not orientedbox:
            #second_passage=False
            #continue

        pt1=orientedbox[0]
        pt2=orientedbox[1]
        pt3=orientedbox[2]
        
        newbloc=BlocAPlat(bloc,pt1,pt2,pt3,origine)
        bboxdecal=rs.BoundingBox(newbloc)
        
        rs.AddLayer('PSE à PLAT')
        rs.AddLayer('PSE à PLAT::400',(123, 38, 205))
        rs.AddLayer('PSE à PLAT::200',(123, 138, 205))
        rs.AddLayer('PSE à PLAT::100',(123, 238, 205))
        rs.AddLayer('PSE à PLAT::Hors Std',(0,100,180))
        if orientedbox[5]== 400:
            rs.ObjectLayer(newbloc[0],'PSE à PLAT::400')
        elif orientedbox[5]== 200:
            rs.ObjectLayer(newbloc[0],'PSE à PLAT::200')
        elif orientedbox[5]== 100:
            rs.ObjectLayer(newbloc[0],'PSE à PLAT::100')
        else:
            rs.ObjectLayer(newbloc[0],'PSE à PLAT::Hors Std')
        #ajout de l'annotation
        ptnote=rs.coerce3dpoint((origine.X+50,4,420))
        note='Bloc' + rs.ObjectName(bloc)+' ep '+str(int(orientedbox[5]))+' '+str(int(orientedbox[3]))+' x '+str(int(orientedbox[4]))
        textnote=rs.AddText(note,ptnote,100)
        if orientedbox[3]==1200 and orientedbox[4]==3000:
            if orientedbox[5]== 400:
                rs.ObjectColor(textnote,(0,0,255))
            elif orientedbox[5]== 200:
                rs.ObjectColor(textnote,(255,0,0))
            else:
                rs.ObjectColor(textnote,(0,255,0))
        rs.RotateObject(textnote,ptnote,90)
        rs.ObjectLayer(textnote,'PSE à PLAT')
        
        objs=rs.ObjectsByLayer('PSE à PLAT::400')
        if not objs:
            rs.DeleteLayer('PSE à PLAT::400')
            
        objs=rs.ObjectsByLayer('PSE à PLAT::200')
        if not objs:
            rs.DeleteLayer('PSE à PLAT::200')
            
        objs=rs.ObjectsByLayer('PSE à PLAT::100')
        if not objs:
            rs.DeleteLayer('PSE à PLAT::100')
            
        objs=rs.ObjectsByLayer('PSE à PLAT::Hors Std')
        if not objs:
            rs.DeleteLayer('PSE à PLAT::Hors Std')

            
    rs.EnableRedraw(True)
    pass


def BlocAPlat(bloc,pt1,pt2,pt3,origine):
    ref=(pt1,pt2,pt3)
    t1=origine
    t2=rs.coerce3dpoint((1,0,0))
    t2.X=t1.X+1
    t3=rs.coerce3dpoint((0,0,1))
    t3.X=t1.X
    targ=(t1,t2,t3)
    bloc_a_plat=rs.OrientObject(bloc,ref,targ,1)
    box=rs.BoundingBox(bloc_a_plat)
    return (bloc_a_plat,box[1])

def TriBlocParNum(blocs):
    lstnum=[]
    for i in range (0,len(blocs)):
        name=int(rs.ObjectName(blocs[i]))
        lstnum.append((blocs[i],name))
    lst_sort=sorted(lstnum,key=lambda s:s[1])
    return [item[0] for item in lst_sort]
    pass

def TriSurf (Surfs):
    Surfs=sorted([(rs.SurfaceArea(Surf)[0],Surf) for Surf in Surfs])
    return [item[1] for item in Surfs]

def CenterPoint(surf):
    Usurfdomain=rs.SurfaceDomain(surf,0)
    Vsurfdomain=rs.SurfaceDomain(surf,1)
    u=(Usurfdomain[0]+Usurfdomain[1])/2
    v=(Vsurfdomain[0]+Vsurfdomain[1])/2
    ctpt=rs.EvaluateSurface(surf,u,v)
    return ctpt

def Plan(surf):
    contour=rs.DuplicateSurfaceBorder(surf,type=1)
    edges=rs.ExplodeCurves(contour)
    sorted_edges=sorted([(rs.CurveLength(edge),edge)for edge in edges])
    pt1=rs.CurveStartPoint(sorted_edges[1][1])
    pt2=rs.CurveEndPoint(sorted_edges[1][1])
    Xvect=rs.VectorCreate(pt2,pt1)
    Usurfdomain=rs.SurfaceDomain(surf,0)
    Vsurfdomain=rs.SurfaceDomain(surf,1)
    u=(Usurfdomain[0]+Usurfdomain[1])/2
    v=(Vsurfdomain[0]+Vsurfdomain[1])/2
    eval=rs.EvaluateSurface(surf,u,v)
    vect=rs.SurfaceNormal(surf,[u,v])
    plan=rs.PlaneFromNormal(CenterPoint(surf),vect,Xvect)
    rs.DeleteObject(contour)
    rs.DeleteObjects(edges)
    return plan



def OrientedBox(bloc,ep_std):
    #Bloc rectangulaire ou pas?
    first_pass=True
    if first_pass:
        vbloc=rs.SurfaceVolume(bloc)
        box=rs.BoundingBox(bloc)
        vbbox=(rs.Distance(box[0],box[1]))*(rs.Distance(box[0],box[3]))*(rs.Distance(box[0],box[4]))
        blocpp=False

        if round(vbbox/1000)==round(vbloc[0]/1000):
            blocpp=True
        first_pass=False
        
    surfs=rs.ExplodePolysurfaces(bloc)
    sorted_surfs=sorted([(rs.SurfaceArea(surf)[0],surf) for surf in surfs],reverse=True)
    
    
    if blocpp:#si le bloc est parallelepipedique
        for epindex in range(0,len(ep_std)):
            for i in range (0 , len(sorted_surfs)):
                rs.SelectObject(sorted_surfs[i][1])
                bplane=Plan(sorted_surfs[i][1])
                rs.UnselectAllObjects()
                box=rs.BoundingBox(bloc,bplane,in_world_coords=True)
                Xtest=rs.Distance(box[0],box[1])
                Ytest=rs.Distance(box[0],box[3])
                Ztest=rs.Distance(box[0],box[4])
                pass

                if round(Ztest)== ep_std[epindex] and round(Xtest)==1200:
                    rs.DeleteObjects(surfs)
                    return ((box[0],box[1],box[4],round(Xtest),round(Ytest),round(Ztest)))
                    
                elif round(Ztest)== ep_std[epindex] and Xtest<Ytest:
                    rs.DeleteObjects(surfs)
                    return ((box[0],box[1],box[4],round(Xtest),round(Ytest),round(Ztest)))
                    
                elif round(Ztest)== ep_std[epindex] and Xtest > Ytest:
                    rs.DeleteObjects(surfs)
                    return((box[1],box[2],box[5],round(Ytest),round(Xtest),round(Ztest)))
                    
                elif Ztest < Xtest and Xtest < Ytest :
                    #rs.DeleteObjects(surfs)
                    boxtemp=(box[0],box[1],box[4],round(Xtest),round(Ytest),round(Ztest))
                    
                elif Ztest < Xtest and Xtest > Ytest :
                    boxtemp=(box[1],box[2],box[5],round(Xtest),round(Ytest),round(Ztest))
    else:# si le bloc n'est pas parrellepidedeic
        surfdec=[]
        for surf in sorted_surfs:
            pass
            cont=rs.DuplicateSurfaceBorder(surf[1],1)
            nb_angledroit=NbAngleDroit(cont)
            if nb_angledroit<=3: surfdec.append(surf[1])
            rs.DeleteObject(cont)
            
        #print (surfdec)
        for surf in surfdec:
            cont=rs.DuplicateSurfaceBorder(surf)
            nb_angledroit=NbAngleDroit(cont)
            points=rs.CurvePoints(cont)
            rs.DeleteObject(cont)
            lp = len(points)-1
            if nb_angledroit != 0:
                for i in range (lp):
                    angle=rs.Angle2( [points[i] , points[(i+1)%lp] ], [points[(i+1)%lp] , points[(i+2)%lp]])
                    distx=rs.Distance(points[(i+1)%lp] , points[(i+2)%lp])
                    disty=rs.Distance(points[i] , points[(i+1)%lp])
                    if angle[0]==90 and distx<disty:
                        bplane=rs.PlaneFromPoints(points[(i+1)%lp],points[(i+2)%lp],points[i])
                        box=rs.BoundingBox(bloc,bplane,in_world_coords=True)
                        Xtest=rs.Distance(box[0],box[1])
                        Ytest=rs.Distance(box[0],box[3])
                        Ztest=rs.Distance(box[0],box[4])
                        rs.DeleteObjects(surfs)
                        return ((box[0],box[1],box[4],round(Xtest),round(Ytest),round(Ztest)))
                    elif angle[0]==90 and disty<distx:
                        bplane=rs.PlaneFromPoints(points[(i+1)%lp],points[(i+2)%lp],points[i])
                        box=rs.BoundingBox(bloc,bplane,in_world_coords=True)
                        Xtest=rs.Distance(box[0],box[1])
                        Ytest=rs.Distance(box[0],box[3])
                        Ztest=rs.Distance(box[0],box[4])
                        rs.DeleteObjects(surfs)
                        return ((box[1],box[2],box[5],round(Xtest),round(Ytest),round(Ztest)))
            else:
                for i in range (lp):
                    vect1=rs.VectorCreate(points[(i+1)%lp],points[i] )
                    vect2=rs.VectorCreate(points[(i+3)%lp],points[(i+2)%lp])
                    if rs.IsVectorParallelTo(vect1,vect2)!=0:
                        bplane=rs.PlaneFromPoints(points[i],points[(i+1)%lp],points[(i+3)%lp])
                        box=rs.BoundingBox(bloc,bplane,in_world_coords=True)
                        Xtest=rs.Distance(box[0],box[1])
                        Ytest=rs.Distance(box[0],box[3])
                        Ztest=rs.Distance(box[0],box[4])
                        rs.DeleteObjects(surfs)
                        return ((box[1],box[2],box[5],round(Xtest),round(Ytest),round(Ztest)))
    # en dernier recour
    for epindex in range(0,len(ep_std)):
        for i in range (0 , len(sorted_surfs)):
            rs.SelectObject(sorted_surfs[i][1])
            bplane=Plan(sorted_surfs[i][1])
            rs.UnselectAllObjects()
            box=rs.BoundingBox(bloc,bplane,in_world_coords=True)
            Xtest=rs.Distance(box[0],box[1])
            Ytest=rs.Distance(box[0],box[3])
            Ztest=rs.Distance(box[0],box[4])
            pass

            if round(Ztest)== ep_std[epindex] and round(Xtest)==1200:
                rs.DeleteObjects(surfs)
                return ((box[0],box[1],box[4],round(Xtest),round(Ytest),round(Ztest)))
                
            elif round(Ztest)== ep_std[epindex] and Xtest<Ytest:
                rs.DeleteObjects(surfs)
                return ((box[0],box[1],box[4],round(Xtest),round(Ytest),round(Ztest)))
                
            elif round(Ztest)== ep_std[epindex] and Xtest > Ytest:
                rs.DeleteObjects(surfs)
                return((box[1],box[2],box[5],round(Ytest),round(Xtest),round(Ztest)))
                
            elif Ztest < Xtest and Xtest < Ytest :
                #rs.DeleteObjects(surfs)
                boxtemp=(box[0],box[1],box[4],round(Xtest),round(Ytest),round(Ztest))
                
            elif Ztest < Xtest and Xtest > Ytest :
                boxtemp=(box[1],box[2],box[5],round(Xtest),round(Ytest),round(Ztest))



    rs.DeleteObjects(surfs)
    
    return boxtemp



PseAPlat()

Hope this helps

-Farouk

Thank you, I will check on Monday, but maybe you can tell me what you change, I would like to understand…:sweat_smile::pleading_face:

You were using a font that was not present on the user machine, I changed the font to Arial which should be present on all user’s machines and surfs deletion

1 Like

Yes… it’s work!! but it’s not the font, it’s rs.deleteobjects(surfs) at the end of my code… you delete somes…

thank you, it seems to work, now!!!