示例#1
0
def drawOpening(distance, length, block=0):
    if block == 1 and rs.IsBlock("window") == False:
        util.initWindowBlock()
    if block == 2 and rs.IsBlock("door") == False:
        util.initDoorBlock()
    if not rs.IsLayer("Axis"):
        util.initCaadLayer("Axis")

    twoLines = findTwoParallelLines()
    if not twoLines:
        return 0
    pi, linei, linej = twoLines
    if not linej:
        return 0
    pj = linej.CurveGeometry.Line.ClosestPoint(pi, False)

    oldLockMode = rs.LayerLocked("Axis", True)
    # side=0 start from startPoint , side=1 start from endPoint
    if rs.Distance(linei.CurveGeometry.Line.From, pi) <= rs.Distance(
            pi, linei.CurveGeometry.Line.To):
        side = 0
    else:
        side = 1

    # direct:
    #  0 | 1
    # -------
    #  2 | 3
    vji = rs.VectorCreate(pj, pi)
    vi = linei.CurveGeometry.Line.Direction
    angle = rs.Angle((0, 0, 0),
                     rs.VectorRotate(vji, -rs.Angle((0, 0, 0), vi)[0],
                                     (0, 0, 1)))
    if abs(angle[0] - 90) < sc.doc.ModelAbsoluteTolerance:
        line0 = linei
        line1 = linej
        if side == 0:
            direct = 2
        else:
            direct = 3
    elif abs(angle[0] + 90) < sc.doc.ModelAbsoluteTolerance:
        line0 = linej
        line1 = linei
        if side == 0:
            direct = 0
        else:
            direct = 1

    dl = DoubleLine(line0.CurveGeometry.Line, line1.CurveGeometry.Line)
    newLayer = rs.ObjectLayer(line0.Id)
    oldLayer = rs.CurrentLayer(newLayer)
    dl.drawOpening(distance, length, side, block, direct)
    rs.DeleteObject(line0.Id)
    rs.DeleteObject(line1.Id)
    rs.CurrentLayer(oldLayer)
    rs.LayerLocked("Axis", oldLockMode)
示例#2
0
    def unlock(self):
        """Unlocks layer.
        Returns:
          self
        """

        rs.LayerLocked(self.name, False)

        return self
示例#3
0
    def lock(self):
        """Locks layer.
        Returns:
          self
        """

        rs.LayerLocked(self.name, True)

        return self
示例#4
0
 def initLayers(self):
     #propagate required layers
     parent = get_layer_name('LOCKEDLAYERS')
     rs.AddLayer(get_layer_name('LOCKEDLAYERS'), locked=False)
     for phase in PHASES:
         lay = get_layer_name(phase)
         if not rs.IsLayer(lay): rs.AddLayer(lay, locked=False)
         else: rs.LayerLocked(lay, False)
         #rs.ParentLayer(lay,parent)
     rs.ExpandLayer(parent, False)
示例#5
0
def set_layer_properties(layer, properties):
    """Set Rhino layer properties."""

    rs.LayerVisible(layer, properties.get("LayerVisible"))
    rs.LayerLocked(layer, properties.get("LayerLocked"))
    rs.LayerColor(layer, hex_to_rbg(properties.get("LayerColor")))
    rs.LayerMaterialIndex(layer, properties.get("LayerMaterialIndex"))
    rs.LayerLinetype(layer, properties.get("LayerLinetype"))
    rs.LayerPrintColor(layer, hex_to_rbg(properties.get("LayerPrintColor")))
    rs.LayerPrintWidth(layer, properties.get("LayerPrintWidth"))
示例#6
0
def main():

    print "Spkcam's vector from gcode"
    print "selecciona tu archivo de codifo g:"
    if not rs.IsLayer(LAYER_NAME):
        rs.AddLayer(LAYER_NAME)
    else:
        rs.LayerLocked(LAYER_NAME, locked=False)
    f_path = rs.OpenFileName(title="Selecciona CodigoG",
                             filter=None,
                             folder=None,
                             filename=None,
                             extension=None)
    f = open(f_path)
    gcode = f.readlines()
    f.close()
    vector_list, total_time, total_length = vectors_from_gcode(gcode, True)
    print "Tiempo de corte: %s minutos" % total_time
    print "Logitud total: %s mm" % total_length
    rs.LayerLocked(LAYER_NAME, locked=True)
示例#7
0
def RunCommand(is_interactive):
    config = get_sisufile()
    if not config:
        print('Sisufile not configured')
        return Rhino.Commands.Result.Failure

    layers = get_related_layers(config, derived_only=True)
    for layer in layers:
        rs.LayerLocked(layer, False)

    return Rhino.Commands.Result.Success
def get_layer_properties(layer):
    """Get Rhino layer properties."""

    return {
        "LayerVisible": rs.LayerVisible(layer),
        "LayerLocked": rs.LayerLocked(layer),
        "LayerColor": rgb_to_hex(rs.LayerColor(layer)),
        "LayerMaterialIndex": rs.LayerMaterialIndex(layer),
        "LayerLinetype": rs.LayerLinetype(layer),
        "LayerPrintColor": rgb_to_hex(rs.LayerPrintColor(layer)),
        "LayerPrintWidth": rs.LayerPrintWidth(layer)
    }
示例#9
0
def RunCommand(is_interactive):
    # this script can turn off layers of your selected object
    rs.AddLayer("_t")
    rs.CurrentLayer("_t")

    layers = rs.LayerNames()

    for layer in layers:
        if rs.IsLayerLocked(layer):
            rs.LayerLocked(layer, False)

    return 0
示例#10
0
def wallJoin(layer):
    if not rs.IsLayer("Wall"):
        util.initCaadLayer("Wall")
    if not rs.IsLayer("Axis"):
        util.initCaadLayer("Axis")

    haveLayer = True
    items = (layer, "Off", "On")
    result = rs.GetBoolean("current layer option", items, True)
    if result:
        haveLayer = result[0]

    oldLockMode = rs.LayerLocked("Axis", True)
    while True:
        go = Rhino.Input.Custom.GetObject()
        go.SetCommandPrompt("Select 4 lines, each two parallel to anthor")
        go.GeometryFilter = Rhino.DocObjects.ObjectType.Curve
        go.GetMultiple(4, 4)

        if go.CommandResult() != Rhino.Commands.Result.Success:
            rs.LayerLocked("Axis", oldLockMode)
            return go.CommandResult()

        if go.ObjectCount != 4: return Rhino.Commands.Result.Failure
        crv = []
        for obj in go.Objects():
            crv.append(obj.Geometry().Line)

        rc, doubleLines = DoubleLine.GetIntersectedDoubleline(crv)
        if rc:
            doubleLine0 = doubleLines[0]
            doubleLine1 = doubleLines[1]
            if haveLayer:
                oldLayer = rs.CurrentLayer(layer)
            doubleLine0.drawIntersectionWithDoubleLine(doubleLine1)
            if haveLayer:
                rs.CurrentLayer(oldLayer)
            rs.DeleteObjects(go.Objects())
        else:
            print "Error: no two doubleLines"
示例#11
0
def RunCommand( is_interactive ):

  rs.AddLayer("_t")
  rs.CurrentLayer("_t")

  layers = rs.LayerNames()

  for layer in layers:
      if rs.IsLayerLocked(layer):
          rs.LayerLocked(layer, False)
      if not rs.IsLayerVisible(layer):
          rs.LayerVisible(layer,True)
  return 0
示例#12
0
def RunCommand(is_interactive):
    config = sisuconfig()
    if not config:
        print('Sisufile not configured')
        return Rhino.Commands.Result.Failure

    layers = get_sisu_layers(config, derived_only=True)
    for layer in layers:
        rs.LayerLocked(layer, True)
        parent = rs.ParentLayer(layer)
        rs.ExpandLayer(parent, False)  # collapse parend layer

    print('Layers successfully locked!')
    return Rhino.Commands.Result.Success
示例#13
0
def RunCommand(is_interactive):
    # this script can turn off layers of your selected object

    rs.AddLayer("_t")
    rs.CurrentLayer("_t")

    Layers = []
    CurObjLayNames = []
    CurObjLayParentNames = []

    for layer in rs.LayerNames():
        if not rs.IsLayerLocked(layer):
            Layers.extend([layer])

    Layers = list(dict.fromkeys(Layers))

    CurObjs = rs.GetObjects("select object to keep layers on")

    for CurObj in CurObjs:
        CurObjLayId = rs.ObjectLayer(CurObj)
        CurObjLayName = rs.LayerName(CurObjLayId, fullpath=True)
        CurObjLayNames.extend([CurObjLayName])
        CurObjLayNames = list(dict.fromkeys(CurObjLayNames))

    for name in CurObjLayNames:
        for layer in Layers:
            if rs.IsLayerParentOf(name, layer):
                CurObjLayParentNames.extend([layer])

        CurObjLayParentNames = list(dict.fromkeys(CurObjLayParentNames))

    layList = CurObjLayNames + CurObjLayParentNames

    i = 0
    for layer in Layers:
        if layer not in layList and layer != "_t":
            rs.LayerLocked(layer, True)
            i += 1

    rs.MessageBox(str(i) + " layers Locked", 0, title="SDQT_Sandelions")

    return 0
示例#14
0
def ringSizes():
    fingerSizes = {}
    fingerChoice = []
    startSize = 72
    endSize = 91
    start = 14.5
    h_incr = 0.2

    for x in range(startSize, endSize):
        start += h_incr
        fingerSizes[str(chr(x))] = round(start, 2)
        start += h_incr
        fingerSizes[str(chr(x)) + chr(189)] = round(start, 2)

        fingerChoice.append(chr(x))
        fingerChoice.append(chr(x) + chr(189))
    #debug
    #print(fingerSizes)

    #listbox
    if fingerChoice:
        try:
            result = rd.ListBox(sorted(fingerChoice), "Select FingerSize",
                                "Finger Size", "N")
            if result:
                myLayer = "Finger Size: " + result
                rs.AddLayer(myLayer, col.Brown)
                rs.CurrentLayer(myLayer)
                rs.CurrentView("front")
                rs.Command("_Circle 0 " + str(fingerSizes.get(result)))
                rs.CurrentLayer("Default")
                rs.LayerLocked(myLayer, True)
                rs.ClearCommandHistory()
                if rs.IsLayer(myLayer):
                    print("\nFinger rail added!")
            else:
                print("\nOperation Aborted")
        except:
            print "Aborted by user"
示例#15
0
 def clean_layers(self):
     
     try:
         rs.LayerLocked(PREVIEW_LAYER_NAME,False)
         rs.LayerLocked(LAYER_CLUSTER,False)
         rs.LayerLocked(LAYER_SORTING,False)
         rs.DeleteObjects(rs.ObjectsByLayer(PREVIEW_LAYER_NAME))
         rs.DeleteObjects(rs.ObjectsByLayer(LAYER_CLUSTER))
         rs.DeleteObjects(rs.ObjectsByLayer(LAYER_SORTING))
     except:
         preview_layer = rs.AddLayer(PREVIEW_LAYER_NAME, color=0, visible=True, locked=True, parent=None)
         rs.AddLayer(LAYER_SORTING, color=0, visible=True, locked=True, parent=preview_layer)
         rs.AddLayer(LAYER_CLUSTER, color=0, visible=True, locked=True, parent=preview_layer)
             
     rs.LayerLocked(PREVIEW_LAYER_NAME,True)
     rs.LayerLocked(LAYER_SORTING,True)
     rs.LayerLocked(LAYER_CLUSTER,True)
示例#16
0
def RunCommand( is_interactive ):
  # this script can turn off layers of your selected object


  import rhinoscriptsyntax as rs

  rs.AddLayer("_t")
  rs.CurrentLayer("_t")

  layers = rs.LayerNames()
  CurObjLayNames=[]

  CurObjs = rs.GetObjects("select object to keep layers on")

  for CurObj in CurObjs:
      CurObjLayId = rs.ObjectLayer(CurObj)
      CurObjLayName = rs.LayerName(CurObjLayId, fullpath=True)
      CurObjLayNames.extend([CurObjLayName])

  for layer in layers:
      if layer in CurObjLayNames and layer != "_t":
          rs.LayerLocked(layer,True)
  return 0
示例#17
0
for layer in rs.LayerNames():
    if not rs.IsLayerLocked(layer):
        Layers.extend([layer])

Layers = list(dict.fromkeys(Layers))

CurObjs = rs.GetObjects("select object to keep layers on")

for CurObj in CurObjs:
    CurObjLayId = rs.ObjectLayer(CurObj)
    CurObjLayName = rs.LayerName(CurObjLayId, fullpath=True)
    CurObjLayNames.extend([CurObjLayName])
    CurObjLayNames = list(dict.fromkeys(CurObjLayNames))

for name in CurObjLayNames:
    for layer in Layers:
        if rs.IsLayerParentOf(name, layer):
            CurObjLayParentNames.extend([layer])

    CurObjLayParentNames = list(dict.fromkeys(CurObjLayParentNames))

layList = CurObjLayNames + CurObjLayParentNames

i = 0
for layer in Layers:
    if layer not in layList and layer != "_t":
        rs.LayerLocked(layer, True)
        i += 1

rs.MessageBox(str(i) + " layers Locked", 0, title="SDQT_Sandelions")
示例#18
0
def processObject(object, parentInstances):
    global g_instances
    global g_instancesByName
    global g_parts
    global g_materials

    name = rs.ObjectName(object)
    if not name:
        name = "Unnamed"
    type = rs.ObjectType(object)
    layer = rs.ObjectLayer(object)

    if type == rs.filter.instance:
        type = rs.BlockInstanceName(object)

        xform = rs.BlockInstanceXform(object)

        # Seems like transforms are in global frame already
        # --> Probably due to exploding the block hierarchies...
        #for parent in reversed(parentInstances[1:]) :
        #    xform = parent["xform"] * xform

        subObjects = rs.ExplodeBlockInstance(object)

        fullName = name
        if len(parentInstances) > 1:
            for parent in parentInstances[1:]:
                fullName = parent["name"] + "." + fullName
        originalFullName = fullName

        appendixCtr = 1
        while fullName in g_instancesByName:
            fullName = format("%s+%d" % (originalFullName, appendixCtr))
            appendixCtr += 1
        if fullName != originalFullName:
            print("WARNING: Renamed %s => %s" % (originalFullName, fullName))

        instance = \
        {
               "name" : name,
           "fullName" : fullName,
               "type" : type,
              "xform" : xform,
            "parents" : list(parentInstances),
              "parts" : [],
            "touched" : False,
        }
        g_instances.append(instance)
        g_instancesByName[fullName] = instance

        for subObject in subObjects:
            processObject(subObject, parentInstances + [instance])
        return

    skipReason = None
    if rs.LayerLocked(layer):
        skipReason = "layer locked"
    elif not rs.LayerVisible(layer):
        skipReason = "layer hidden"
    elif type != rs.filter.polysurface and type != rs.filter.surface:
        skipReason = "bad type - " + typeStr[type]

    if skipReason:
        # make sure we can delete object by moving to current layer
        rs.ObjectLayer(object, rs.CurrentLayer())
        print("Skipping %s (%s)" % (str(object), skipReason))
    else:
        brep = rs.coercebrep(object)
        meshes = rc.Geometry.Mesh.CreateFromBrep(brep, g_meshParams)
        joinedMesh = rc.Geometry.Mesh()
        for mesh in meshes:
            joinedMesh.Append(mesh)
        joinedMesh.Reduce(0, False, 10, False)
        if not joinedMesh.Faces.ConvertQuadsToTriangles():
            print("WARNING: Failed to convert quads to tris for %s" %
                  (str(object)))
        if not joinedMesh.Compact():
            print("WARNING: Failed to compact %s" % (str(object)))

        materialSrc = rs.ObjectMaterialSource(object)
        if materialSrc == 0:
            materialIdx = rs.LayerMaterialIndex(rs.ObjectLayer(object))
        else:
            materialIdx = rs.ObjectMaterialIndex(object)

        material = rs.MaterialName(materialIdx)
        if not material:
            material = "None"
        g_materials[material] = materialIdx

        joinedMeshGuid = sc.doc.Objects.AddMesh(joinedMesh)
        rs.ObjectName(joinedMeshGuid, name)
        rs.ObjectMaterialSource(joinedMeshGuid, 1)
        rs.ObjectMaterialIndex(joinedMeshGuid, materialIdx)

        part = \
        {
                "name" : name,
                "mesh" : joinedMesh,
            "instance" : parentInstances[-1],
            "material" : material,
        }
        parentInstances[-1]["parts"].append(part)
        if not parentInstances[-1]["touched"]:
            for parentInstance in parentInstances:
                parentInstance["touched"] = True
        g_parts.append(part)

    rs.DeleteObject(object)
示例#19
0
import rhinoscriptsyntax as rs
theObjs = rs.GetObject("Select objects on the layer you wish to hide")

layerName = rs.ObjectLayer(theObjs)
print layerName
rs.LayerLocked(layerName, locked=True)