Ejemplo n.º 1
0
def get_polygons(layer=None):
    """Get all polygons.

    Parameters
    ----------
    layer : str, optional
        Name of a layer containing the polygons.

    Returns
    -------
    list[System.Guid]
        The identifiers of the polygons.

    """
    if layer:
        rs.EnableRedraw(False)
        # Argument names for LayerVisible command are not the same for Rhino5 and Rhino6
        # that is why we use positional instead of named arguments
        visible = rs.LayerVisible(layer, True, True)
        guids = rs.ObjectsByType(rs.filter.curve)
        guids = [guid for guid in guids if is_curve_polygon(guid)]
        guids = list(set(guids) & set(rs.ObjectsByLayer(layer)))
        rs.LayerVisible(layer, visible, True)
        rs.EnableRedraw(True)
    else:
        guids = rs.ObjectsByType(rs.filter.curve)
        guids = [guid for guid in guids if is_curve_polygon(guid)]
    return guids
Ejemplo n.º 2
0
def GetFracture ():
    dx = rs.GetReal("Enter x-axis direction:")
    if not dx:
        dx = 0.0
    print "x-axis direction: ", dx
    objs = rs.ObjectsByType(8,False)
    cir_objs = rs.ObjectsByType(4)
    
    #delete all circles
    for cur_obj in cir_objs:
        if rs.IsCircle(cur_obj):
            rs.DeleteObject(cur_obj)
    occor = []
    radius = []
    center = []
    
    #for all surface
    for obj in objs:
        rs.UnselectAllObjects()
        rs.SelectObject(obj)
        rs.Command ("_Silhouette")
        created_objs = rs.LastCreatedObjects()
        #not a circle
        if len(created_objs) !=1:
            rs.DeleteObjects(created_objs)
            print "unvailded surface"
            continue
        created_objs = created_objs[0]
        #not a circle
        if not rs.IsCircle(created_objs):
            rs.DeleteObject(created_objs)
            print "unvailded surface, not circle"
            continue
        point = rs.CircleCenterPoint(created_objs)
        center.append(point)
        r = rs.CircleRadius(created_objs)
        radius.append(r)
        normal = rs.SurfaceNormal(obj,[0,0])
        occor.append(GetDirDip(normal,dx))
        rs.DeleteObject(created_objs)
    print center
    print occor
    print radius
    path = rs.DocumentPath()
    path_l = path.split("\\")
    path_l[len(path_l)-1] = "fracture.dat"
    file = open("\\".join(path_l),"w")
    file.write(str(len(occor)))
    file.write('\n')
    for i in range (len(occor)):
        file.write("%.15f " % center[i][0])
        file.write("%.15f " % center[i][1])
        file.write("%.15f " % center[i][2])
        file.write ("%.15f " % occor[i][0])
        file.write ("%.15f " % occor[i][1])
        file.write ("%.15f " % radius[i])
        file.write ("0.0001 0.1 30\n")
    file.close ()
Ejemplo n.º 3
0
def get_meshes(layer=None):
    if layer:
        rs.EnableRedraw(False)
        visible = rs.LayerVisible(layer, visible=True, force_visible=True)
        guids = rs.ObjectsByType(rs.filter.mesh)
        guids = list(set(guids) & set(rs.ObjectsByLayer(layer)))
        rs.LayerVisible(layer, visible=visible, force_visible=visible)
        rs.EnableRedraw(True)
    else:
        guids = rs.ObjectsByType(rs.filter.mesh)
    return guids
Ejemplo n.º 4
0
def get_meshes(layer=None):
    if layer:
        rs.EnableRedraw(False)
        # Argument names for LayerVisible command are not the same for Rhino5 and Rhino6
        # that is why we use positional instead of named arguments
        visible = rs.LayerVisible(layer, True, True)
        guids = rs.ObjectsByType(rs.filter.mesh)
        guids = list(set(guids) & set(rs.ObjectsByLayer(layer)))
        rs.LayerVisible(layer, visible, True)
        rs.EnableRedraw(True)
    else:
        guids = rs.ObjectsByType(rs.filter.mesh)
    return guids
Ejemplo n.º 5
0
def get_polygons(layer=None):
    if layer:
        rs.EnableRedraw(False)
        visible = rs.LayerVisible(layer, visible=True, force_visible=True)
        guids = rs.ObjectsByType(rs.filter.curve)
        guids = [guid for guid in guids if is_curve_polygon(guid)]
        guids = list(set(guids) & set(rs.ObjectsByLayer(layer)))
        rs.LayerVisible(layer, visible=visible, force_visible=visible)
        rs.EnableRedraw(True)
    else:
        guids = rs.ObjectsByType(rs.filter.curve)
        guids = [guid for guid in guids if is_curve_polygon(guid)]
    return guids
Ejemplo n.º 6
0
def BlockTxtAll(boolFlipHeb=True):
    
    blocks = rs.ObjectsByType(4096, False, 0)
    
    for blockRef in blocks:
        BlockTxt(blockRef, False, False, boolFlipHeb)
    
    rs.EnableRedraw(True)
Ejemplo n.º 7
0
    def set_mesh_objects(self):
        sys.path.append(self.pluginPath)

        object_ids = rs.ObjectsByType(32 | 16, True)
        objects_visible = True
        view = rs.CurrentView()

        for obj in object_ids:
            rs.HideObjects(obj)
Ejemplo n.º 8
0
def SelectNearDupCrvs(chk_all=True,
                      sel_dup_all=False,
                      crv_divs=25,
                      user_tol=0.1):
    msgs = Localize(rs.LocaleID())
    if chk_all:
        crvIDs = rs.ObjectsByType(4, state=1)
    else:
        crvIDs = rs.GetObjects(msgs[0], 4, preselect=True)
    if not crvIDs: return

    if "SelNearDup_Tol" in sc.sticky: user_tol = sc.sticky["SelNearDup_Tol"]

    tol = sc.doc.ModelAbsoluteTolerance
    comp_tol = rs.GetReal(msgs[1], user_tol, minimum=tol)
    if comp_tol is None: return

    crv_bbs = []
    for crvID in crvIDs:
        crv = sc.doc.Objects.Find(crvID).Geometry
        bb = crv.GetBoundingBox(True)
        length = crv.GetLength()
        crv_bbs.append((crv, bb, length))

    rs.EnableRedraw(False)
    rs.Prompt(msgs[2])
    if PC: rs.StatusBarProgressMeterShow(msgs[3], 0, 100, True)
    #idea - collect indices, not IDs...
    found_index = set()
    st = time.time()
    for i in range(len(crv_bbs) - 1):
        if PC and i % 100 == 0:
            rs.StatusBarProgressMeterUpdate(100 * i / len(crv_bbs))
        for j in range(i + 1, len(crv_bbs)):
            #check to see if cuve is already in select list
            if j in found_index: continue
            #print "Compare curve {} to curve {}".format(i,j)
            if IsNearDupCrv(crv_bbs[i], crv_bbs[j], comp_tol, crv_divs):
                found_index.add(j)
                if sel_dup_all: found_index.add(i)
    if PC: rs.StatusBarProgressMeterHide()
    print msgs[4].format(time.time() - st)
    if found_index:
        #need to add list of IDs
        found = [crvIDs[index] for index in found_index]
        rs.SelectObjects(found)
        msg = msgs[5].format(len(found))
    else:
        msg = msgs[6]
    print msg
    sc.sticky["SelNearDup_Tol"] = comp_tol
Ejemplo n.º 9
0
def layerChangeEvent(sender, e):
    toolpaths = rs.LayerChildren("Toolpaths")
    layerId = ""

    for toolpath in toolpaths:
        layerId = rs.LayerId(toolpath)

        for textDotId in rs.ObjectsByType(8192):
            toolpathName = rs.TextDotText(textDotId)

            if rs.GetUserText(textDotId, "LayerId") == layerId:
                newToolpathName = toolpath.split("::")[1]
                print "Renaming ", toolpathName, " to ", newToolpathName
                rs.TextDotText(textDotId, newToolpathName)
def e(theta, num):
    """
    receives:
        theta = degree of line ( 0 < theta < 45 ) 
        num = number of pattern ( 0 < num < 15 )
    works:
        draw tile pattern
    returns:
        None
    """
    def base(x, y):
        d = ma.radians(theta)

        r = 1 / ma.cos(d) - (ma.sin(d)**2) / ma.cos(d)
        n = r * ma.sin(d)
        k = r * ma.cos(d)

        a1 = (x, y, 0)
        b1 = (x, y + 1, 0)
        c1 = (x + 1, y + 1, 0)
        d1 = (x + 1, y, 0)

        a2 = (x + k, y + n, 0)
        b2 = (x + n, y + 1 - k, 0)
        c2 = (x + 1 - k, y + 1 - n, 0)
        d2 = (x + 1 - n, y + k, 0)

        l1 = rs.AddLine(a1, a2)
        l2 = rs.AddLine(b1, b2)
        l3 = rs.AddLine(c1, c2)
        l4 = rs.AddLine(d1, d2)

    for i in range(0, num):
        for k in range(0, num):
            base(i, k)

    line = rs.ObjectsByType(0)
    n = len(line)
    for i in range(0, n):
        a = line[i]
        b = rs.AddLine((0, 0, 0), (0, 0, 0.05))
        c = rs.RotateObject(b, (0, 0, 0), 90, None, False)
        s = rs.ExtrudeCurve(a, b)
        rs.ExtrudeSurface(s, c)
Ejemplo n.º 11
0
def getSurfaces():
    surface = rs.ObjectsByType(8)
    hidobj = rs.HiddenObjects()
    if hidobj:
        for obj in hidobj:
            rs.ShowObject(obj)
    outDic = {'mod': None, 'ref': None}
    for srf in surface:
        print rs.ObjectName(srf)
        if rs.ObjectName(srf) == "ref":
            #rs.HideObject(srf)
            outDic['ref'] = srf
        elif rs.ObjectName(srf) == "mod":
            outDic['mod'] = srf
        else:
            rs.DeleteObject(srf)
    for obj in hidobj:
        rs.HideObject(obj)
    return outDic
Ejemplo n.º 12
0
def outline(s):
    
    x1= 6*s
    y1= 0 
    x2= 3*s
    y2= 6*s*ma.sqrt(3)/2
    
    xy1 = (x1, y1, 0)
    xy2 = (x2, y2, 0)
    
    line_origin = rs.AddLine(xy1, xy2)
    
    o = length_of_outline = 0.1 #0.05<0<0.10  
    line = rs.ScaleObject(line_origin, (0, 0, 0), (1+o, 1+o, 0), False)
    
    for angle in rs.frange(60, 360, 60):
        rs.RotateObject(line, (0, 0, 0), angle, None, True)
    
    all_lines = rs.ObjectsByType(0)
    
    rs.ObjectColor(all_lines,colors[0])
Ejemplo n.º 13
0
def BlockTxtSim(block, boolFlipHeb=True):
    
    if not block: return
    
    blockName = rs.BlockInstanceName(block)
    blockObjects = rs.BlockObjects(blockName)
    
    obj = blockObjects[0]
    str= ""
    cstr = ""
    
    if rs.IsText(obj):
        str = rs.TextObjectText(obj)
        cstr = ConvTxt(str, boolFlipHeb)
    else: return
    
    blocks = rs.ObjectsByType(4096, False, 0)
    
    for blockRef in blocks:
        BlockTxt(blockRef, str, cstr, boolFlipHeb)
    
    rs.EnableRedraw(True)
def delete_something(k):
    some_objects = rs.ObjectsByType(k)
    rs.DeleteObjects(some_objects)
Ejemplo n.º 15
0
petalCurves = []

outerCircle = rs.AddCircle(flowerCenter, flowerRadius)
points = rs.AddPoints(rs.DivideCurve(outerCircle, petalCount))
rs.HideObjects(points)

for i in range(len(points)):
    centerLine = rs.AddLine(points[i], flowerCenter)
    rs.HideObject(centerLine)
    petalMidpoint = rs.AddPoint(rs.CurveMidPoint(centerLine))
    rs.HideObjects(petalMidpoint)
    vector = rs.VectorCreate(points[i], petalMidpoint)
    vector = rs.VectorUnitize(vector)
    vector = rs.VectorScale(vector, (petalWidth / 2))
    vector = rs.VectorRotate(vector, 90, [0, 0, 1])
    petalEdgePoint = rs.CopyObject(petalMidpoint)
    petalEdgePoint = rs.MoveObject(petalEdgePoint, vector)
    curve = rs.AddArc3Pt(flowerCenter, points[i], petalEdgePoint)
    vector2 = rs.VectorRotate(vector, 180, [0, 0, 1])
    petalEdgePoint2 = rs.CopyObject(petalMidpoint)
    petalEdgePoint2 = rs.MoveObject(petalEdgePoint2, vector2)
    curve2 = rs.AddArc3Pt(flowerCenter, points[i], petalEdgePoint2)
    petalCurves.append(rs.JoinCurves([curve, curve2]))

rs.AddPlanarSrf(petalCurves)

rs.MoveObject(rs.AddPlanarSrf(rs.AddCircle(flowerCenter, centerRadius)),
              [0, 0, .1])

rs.HideObjects(rs.ObjectsByType(4, True))
                for i in range(len(namesColumnU)):
                    print namesColumnU[i]
                    message += " %s - %i\n" % (mergedL[i][1], mergedL[i][0])
                rs.MessageBox(message, 0, "Results")
            else:
                filename = rs.SaveFileName("Save csv file", "*.csv||", None,
                                           "ObjectNamesOccurrences", "csv")
                file = open(filename, 'w')
                headerline = "Names, Occurrences\n"
                file.write(headerline)
                for i in range(len(namesColumnU)):
                    name = mergedL[i][1]
                    occ = mergedL[i][0]
                    line = "%s,%i \n" % (name, occ)
                    file.write(line)
                file.close()
                print "Done"

        else:
            print "You do not have named objects. Function terminated"
            return

    else:
        print "Your 3dm file is empty or you did not select objects. Function terminated"
        return


# function call
objs_ids = rs.ObjectsByType(0)
exportNameOcc(objs_ids)
import rhinoscriptsyntax as rs
import Rhino


def getUnitSystemDescription():
    unitSystemInt = rs.UnitSystem()

    if unitSystemInt == 2:
        return "mm3"
    elif unitSystemInt == 3:
        return "cm3"
    elif unitSystemInt == 4:
        return "m3"
    elif unitSystemInt == 8:
        return "in3"
    elif unitSystemInt == 9:
        return "ft3"


maxVolume = rs.GetReal("Max Volume in " + getUnitSystemDescription())

object_ids = []
object_ids = rs.ObjectsByType(16)

for object_id in object_ids:
    #check to see if the object is closed before calculating volume
    if rs.IsObjectSolid(object_id):
        blockVolume = rs.SurfaceVolume(object_id)[0]
        if blockVolume < maxVolume:
            rs.SelectObject(object_id)
Ejemplo n.º 18
0
def delete_all():
    all_objects = rs.ObjectsByType(0)
    rs.DeleteObjects(all_objects)
        L_Levels.append(level)
outputLevels.extend(list(reversed(sorted(P_Levels))))
outputLevels.extend(["L1"])
if M1 == True:
    outputLevels.extend(["M1"])
outputLevels.extend(sorted(L_Levels))

# Build Area Table for population
for level in outputLevels:
    if requestType == False:
        areasTable[level] = {x: [0] for x in list(hatchnames)}
    else:
        areasTable[level] = {x: [] for x in list(hatchnames)}

#get all the hatches in the document
allHatch = rs.ObjectsByType(65536)

for hatch in allHatch:
    if getLayerType(hatch):
        if requestType == False:
            areasTable[getParent(hatch)][getLayerType(hatch)][0] += rs.Area(
                hatch)
        else:
            if getLayerType(hatch) == "RESIDENTIAL":
                areasTable[getParent(hatch)][getLayerType(hatch)].append(
                    rs.Area(hatch))

if requestType == True: hatchnames = ["RESIDENTIAL"]
outputList = "Level, " + ",".join(hatchnames) + "\n\n"

for lev in reversed(outputLevels):
Ejemplo n.º 20
0
 def getRandMeshGUID(self):
     meshes = rs.ObjectsByType(self.MeshID)
     return random.choice(meshes)
Ejemplo n.º 21
0
def delete_something(n):
    something = rs.ObjectsByType(n)
    rs.DeleteObjects(something)
Ejemplo n.º 22
0
def lockcurves_nofail():
    curves = rs.ObjectsByType(4)
    if not curves: return False
    rs.LockObjects(curves)
    return True
Ejemplo n.º 23
0
def get_objects(name=None, color=None, layer=None, type=None):
    """Get identifiers of Rhino objects, potentially filtered by name, color, layer, or type.

    Parameters
    ----------
    name : str, optional
    color : tuple or list, optional
        RGB color components in integer format (0-255).
    layer : str, optional
    type : Rhino.DocObjects.ObjectType, optional
        The object type.

    Returns
    -------
    list
        The GUIDs of the objects matching the filter parameters.

    Examples
    --------
    .. code-block:: python

        import compas_rhino

        guids_all = compas_rhino.get_objects()
        guids_compas = compas_rhino.get_objects(name='COMPAS.*')
        guids_red = compas_rhino.get_objects(color=(255, 0, 0))
        guids_points = compas_rhino.get_objects(type=compas_rhino.rs.filter.point)
        guids_redpoints = compas_rhino.get_objects(color=(255, 0, 0), type=compas_rhino.rs.filter.point)

    .. code-block:: python

        guids_all = set(compas_rhino.get_objects())
        guids_compas = set(compas_rhino.get_objects(name='COMPAS.*'))
        guids_red = set(compas_rhino.get_objects(color=(255, 0, 0)))
        guids_points = set(compas_rhino.get_objects(type=compas_rhino.rs.filter.point))
        guids_redpoints = set(compas_rhino.get_objects(color=(255, 0, 0), type=compas_rhino.rs.filter.point))

        print guids_compas.issubset(guids_all)
        print guids_all.issubset(guids_compas)

        # True, False

        print guids_red.issubset(guids_all)
        print guids_points.issubset(guids_all)
        print guids_redpoints.issubset(guids_all)

        # True, True, True

        print guids_redpoints.issubset(guids_points)
        print guids_redpoints.issubset(guids_red)
        print guids_points.issubset(guids_red)

        # True, True, False

    """
    guids = rs.AllObjects()
    if name:
        guids = list(set(guids) & set(rs.ObjectsByName(name)))
    if color:
        guids = list(set(guids) & set(rs.ObjectsByColor(color)))
    if layer:
        guids = list(set(guids) & set(rs.ObjectsByLayer(layer)))
    if type:
        guids = list(set(guids) & set(rs.ObjectsByType(type)))
    return guids
Ejemplo n.º 24
0
def GetPoint():
    pl = rs.ObjectsByType(1, False, 1)
    for p in pl:
        print rs.PointCoordinates(p)
Ejemplo n.º 25
0
 def get_all_mesh_guids(self):
     return rs.ObjectsByType(self.MeshID)
Ejemplo n.º 26
0
import rhinoscriptsyntax as rs

hatches = rs.ObjectsByType(65536)
lock = True
for hatch in hatches:
    if rs.IsObjectLocked(hatch):
        lock = False

if lock:
    rs.LockObjects(hatches)
else:
    rs.UnlockObjects(selblockhatches)
def clear_all():
    all_obs = rs.ObjectsByType(0)
    rs.DeleteObjects(all_obs)
Ejemplo n.º 28
0
    rs.AddPoint([x, y, z])
    points.append([x, y, z])

    for i in range(count):
        #         time.sleep(0.001)

        xadd = random.randint(rmin, rmax)
        yadd = random.randint(rmin, rmax)

        if (i % 2 == 0):
            toggle *= -1
            xadd *= toggle
            x += xadd

        else:
            yadd *= toggle
            y += yadd

#         rmin += 1
#         rmax += 1

        rs.AddPoint([x, y, z])
        points.append([x, y, z])
#        print(i)
#         Rhino.RhinoApp.Wait()
#     rs.HideObjects(rs.ObjectsByType(1))
    rs.DeleteObjects(rs.ObjectsByType(1))
    rs.AddInterpCurve(points)
#     rs.AddPolyline(points)
Ejemplo n.º 29
0
#Array line
if line:
    i = 0
    for i in range(array_number):
        offset_x = distance_x * i
        line_copy = (offset_x, 0, 0)
        array_line = rs.CopyObject(line, line_copy)

        # Project down
        results = rs.ProjectCurveToSurface(array_line, surf_id, (0, 0, -1))
        rs.DeleteObject(array_line)

    rs.DeleteObject(line)

    # to get curve number
    crvs = rs.ObjectsByType(4, True)
    line_number = (len(crvs))
    filename = rs.SaveFileName("Save", "G-code (*.gcode)|*.gcode||")
    f = codecs.open(filename, 'w', 'utf-8')

    f.write('G90\n')
    f.write('M83\n')
    f.write('M106 S0\n')
    #f.write('M106 S60\n')
    #f.write('M104 S205 T0\n')
    #f.write('M109 S205 T0\n')
    f.write('M140 S{0}\n'.format(bed_temp))
    f.write('M104 S{0} T0\n'.format(extrude_temp))
    f.write('M109 S{0} T0\n'.format(extrude_temp))
    f.write('G28\n')
    f.write('G92 E0\n')
Ejemplo n.º 30
0
import rhinoscriptsyntax as rs

curves = rs.ObjectsByType(4)
picturePlane = rs.GetObject("select the surface to use as the picture plane",
                            8)
eyePoint = rs.GetObject(
    "select the point to use as the eye, the point at which the projected content will converge",
    1)

#note that we wouldn't need an eye point if our projectors are paralell

for curve in curves:
    pointsOnCurve = rs.DivideCurve(curve, 100)
    intersectionPoints = []
    closeCount = 0
    middleCount = 0
    farCount = 0
    for point in pointsOnCurve:

        if rs.Distance(point, eyePoint) < 1000:
            layerName = "close"
            closeCount += 1
        elif rs.Distance(point, eyePoint) >= 1000 and rs.Distance(
                point, eyePoint) < 1300:
            layerName = "middle"
            middleCount += 1
        else:
            layerName = "far"
            farCount += 1

        projector = rs.AddLine(point, eyePoint)