Problem with Python Script

Hi Steve
With the wip V6 i have problems with pyton scripts.
In the attached images the script ViteBrugola3.py load the script Dynamic_Copy_2_rs .
When i start ViteBrugola3 i get the message:
Message: No module named Dynamic_Copy_2_rs
In V5 all are OK.
The Python editor option i have the same setting
Ciao Vittorio

Traceback:
line 7, in , “C:\Users\Angela\AppData\Roaming\McNeel\Rhinoceros\5.0\scripts\ViteBrugola3.py

Hi Steve
The problem is because the boolean difference fail and i get the below message error.
In V5 the script is Ok , the tollerance is the same that V5. I attached a 3dm file with objects that fail the boolean difference.

Message: ‘NoneType’ object is unsubscriptable

Traceback:
line 91, in VB, “C:\Users\Angela\AppData\Roaming\McNeel\Rhinoceros\5.0\scripts\ViteBrugola3.py”
line 112, in , “C:\Users\Angela\AppData\Roaming\McNeel\Rhinoceros\5.0\scripts\ViteBrugola3.py”

BooleanDifference_Fail.3dm (2.6 MB)
Ciao Vittorio

There is no script or images attached to this post. Could you attach these?

Hi Steve
Sorry for inconvenience. Below the script.
For me the problem is rs.AddRevSrf. and rs.BooleanDifference
Ciao Vittorio

V6_Boolean_Diff_Failed.py (360 Bytes) V6_Boolean_Diff_Failed_2.py (430 Bytes) V6_Boolean_Diff_OK.py (550 Bytes)

Hi Steve
I have another request:. I want to select only the red curve and not the edge like the attached image.
how should I modify the attached script?import Rhino
import scriptcontext
import rhinoscriptsyntax as rs
def GetCurve():

  """
    Return list of curve and edge
    """

.    filter= Rhino.DocObjects.ObjectType.Curve
    
    rc, objrefs = Rhino.Input.RhinoGet.GetOneObject("Seleziona punto vicino allo spigolo", False, filter)
    crv=objrefs.Curve()  
    
    print crv    
    len=rs.CurveLength(crv)
    lun=len/4
GetCurve()

Hi Vittorio, you may disable sub object selection:

import Rhino
import scriptcontext
import rhinoscriptsyntax as rs

def GetCurve():

    ge = Rhino.Input.Custom.GetObject()
    ge.SetCommandPrompt("Seleziona punto vicino allo spigolo")
    ge.SubObjectSelect = False
    ge.GeometryFilter = Rhino.DocObjects.ObjectType.Curve
    ge.DisablePreSelect()
    
    get_rc = ge.Get()
    if get_rc != Rhino.Input.GetResult.Object: return

    objRef = ge.Object(0)
    crv=objRef.Curve()  
    print crv    
    len=rs.CurveLength(crv)
    lun=len/4

GetCurve()

or do you want to filter by color too ?

c.

I Clement
Many thanks . It’s Ok.
If you do not bother you would like to know how can I add filter by color too.
Ciao Vittorio

Hi Vittorio,

i´ve first thought this can be done using Rhino.Input.Custom.GeometryAttributeFilter but there was no way to filter by object color with it. This seems to be easier, MyFilter() sets the object type and r,g,b value:


import rhinoscriptsyntax as rs

def TestGetRedCrv():

    allowed_objs = MyFilter(objtype=4, r=255, g=0, b=0)
    if not allowed_objs: return

    go_ex = rs.GetObjectEx("Select", 0, False, True, allowed_objs)
    if go_ex:
        print go_ex[0]

def MyFilter(objtype=4, r=255, g=0, b=0):
    objs = rs.ObjectsByType(objtype, False, 1)
    if objs is not None:
        allowed = []
        for o in objs:
            color = rs.ObjectColor(o)
            if color:
                if color.R == r and color.G == g and color.B == b:
                    allowed.append(o)

    if len(allowed) == 0: return None
    return allowed

if __name__=="__main__":
    TestGetRedCrv()

EDIT: it also works identical using rs.GetObject() instead of rs.GetObjectEx()

c.