コード例 #1
0
def turn(board, mask, grid):
    test = True
    textdot_id = rs.GetObject("", rs.filter.textdot)
    for x in range(len(grid)):
        for y in range(len(grid)):
            if grid[x][y] == textdot_id:
                i, j = x, y
    rs.EnableRedraw(False)
    if board[i][j] == 'Mine':
        destroy_grid((i, j), grid)
        rs.TextDotText(textdot_id, board[i][j])
        rs.MessageBox("Game over! :(", title='Rhino Minesweeper')
        test = False
    elif board[i][j] == 0:
        board_copy = [row[:] for row in board]
        cells_test = cells_0(i, j, board_copy, [])
        for x, y in cells_test:
            if not mask[x][y]:
                if board[x][y] == 0:
                    rs.DeleteObject(grid[x][y])
                else:
                    rs.TextDotText(grid[x][y], board[x][y])
            mask[x][y] = True
    else:
        rs.TextDotText(textdot_id, board[i][j])
        mask[i][j] = True
    rs.EnableRedraw(True)
    if test and check_mask(mask):
        rs.MessageBox("You win!", title='Rhino Minesweeper')
        return False
    else:
        return test
コード例 #2
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)
コード例 #3
0
 def _get_label(self, textdot_guid):
     """Receives a textdot guid:
         guid
     Returns its text:
         str
     """
     string = rs.TextDotText(textdot_guid)
     return string
コード例 #4
0
 def _get_lpoint_spec(self, textdot_guid):
     """Receives a textdot guid:
         Guid
     Returns a labeled point spec:
         ((num, num, num), label)
     """
     point = rs.TextDotPoint(textdot_guid)
     coord = self._point_to_coord(point)
     label = rs.TextDotText(textdot_guid)
     return (coord, label)
コード例 #5
0
 def _get_lpoint_spec(self, lpoint_guid):
     """Receives:
         lpoint_guid     textdot guid. Verified by calling method
     Returns:
         ((num, num, num), str)              ##  Note: SG spec: (x, y, str)
                         the labeled point spec
     """
     point = rs.TextDotPoint(lpoint_guid)
     point_spec = tuple(point)
     label = rs.TextDotText(lpoint_guid)
     return (point_spec, label)
コード例 #6
0
def get_annotation():
    prompt_for_annotation = 'Select objects'
    guids = rs.GetObjects(prompt_for_annotation)
    print('number of objects: %i' % len(guids))
    for guid in guids:
        print('object type: %i' % rs.ObjectType(guid))
        if rs.IsText(guid):
            print('text: %s' % rs.TextObjectText(guid))
        elif rs.IsTextDot(guid):
            print('text dot: %s' % rs.TextDotText(guid))
        else:
            print('guid is not text')
コード例 #7
0
def draw_square(side):
    mid = side / 2
    x0, y0, z = 0, 0, 0
    x1, y1 = side, side
    x2, y2, = mid, mid
    p00 = [x0, y0, z]
    p01 = [x0, y1, z]
    p10 = [x1, y0, z]
    p11 = [x1, y1, z]
    p22 = [x2, y2, z]
    rs.AddLine(p00, p01)
    rs.AddLine(p00, p10)
    rs.AddLine(p01, p11)
    rs.AddLine(p10, p11)
    dot00 = rs.AddTextDot('00', p00)
    dot22 = rs.AddTextDot('22', p22)
    dot_text = rs.TextDotText(dot22)
    dot_point = rs.TextDotPoint(dot22)
    print('dot text : %s' % dot_text)
    print('dot point: %s' % dot_point)
コード例 #8
0
def getdir():
    dot = rs.GetObject('dir?', 8192)
    dotText = rs.TextDotText(dot)
    return (dotText)
コード例 #9
0
 def _get_ordered_line_and_labeled_point_specs(cls, element_guids):
     """Receives:
         element_guids   [guid, ...]. A list of the guids of (first) the 
                         frame instance and (then) the lines and labeled 
                         points
     Returns:
         ordered_line_and_labeled_point_specs
                         ([line_spec, ...], [labeled_point_spec, ...]). A 
                         list of line specs 
                             (   (num, num, num), 
                                 (num, num, num)) 
                         and a list of labeled point specs
                             (   str,
                                 (num, num, num))
                         where the specs are relative to the frame 
                         instance, if successful
         None            otherwise
     """
     method_name = '_get_ordered_line_and_labeled_point_specs'
     try:
         if element_guids == []:
             raise ValueError
     except ValueError:
         message = "There is no frame instance"
         print("%s.%s\n    %s" % (cls.__name__, method_name, message))
         return_value = None
     else:
         line_specs, labeled_point_specs = [], []
         frame_instance = element_guids.pop(0)
         frame_position = rs.BlockInstanceInsertPoint(frame_instance)
         curve_type, textdot_type = 4, 8192
         for element_guid in element_guids:
             if rs.ObjectType(element_guid) == curve_type:
                 p1_absolute = rs.CurveStartPoint(element_guid)
                 p2_absolute = rs.CurveEndPoint(element_guid)
                 p1_relative = rs.PointSubtract(p1_absolute, frame_position)
                 p2_relative = rs.PointSubtract(p2_absolute, frame_position)
                 p1_spec = tuple(p1_relative)
                 p2_spec = tuple(p2_relative)
                 if p1_spec < p2_spec:
                     tail = p1_spec
                     head = p2_spec
                 elif p1_spec > p2_spec:
                     tail = p2_spec
                     head = p1_spec
                 line_spec = (tail, head)
                 line_specs.append(line_spec)
             elif rs.ObjectType(element_guid) == textdot_type:
                 label = rs.TextDotText(element_guid)
                 p_absolute = rs.TextDotPoint(element_guid)
                 p_relative = rs.PointSubtract(p_absolute, frame_position)
                 p_spec = tuple(p_relative)
                 labeled_point_spec = (label, p_spec)
                 labeled_point_specs.append(labeled_point_spec)
             else:
                 pass
         ordered_line_and_labeled_point_specs = (
             sorted(line_specs), sorted(labeled_point_specs))
         return_value = ordered_line_and_labeled_point_specs
     finally:
         return return_value
コード例 #10
0
        spanish = translate(english, "en", "es")
        german = translate(english, "en", "de")
        french = translate(english, "en", "fr")
        italian = translate(english, "en", "it")
        japanese = translate(english, "en", "ja")
    elif rs.ContextIsRhino():
        # get text dots and translate their contents
        dots = rs.GetObjects("Select dots to translate", rs.filter.textdot)
        if dots:
            langs = {
                "English": "en",
                "ChineseSimplified": "zh-CN",
                "ChineseTraditional": "zh-TW",
                "Czech": "cs",
                "French": "fr",
                "German": "de",
                "Italian": "it",
                "Japanese": "ja",
                "Korean": "ko",
                "Polish": "pl",
                "Spanish": "es"
            }
            source_lang = rs.GetString("source", "English", langs.keys())
            source_lang = langs[source_lang]
            target_lang = rs.GetString("target", "Spanish", langs.keys())
            target_lang = langs[target_lang]
            for dot in dots:
                s = rs.TextDotText(dot)
                s = translate(s, source_lang, target_lang)
                rs.TextDotText(dot, s)
コード例 #11
0
import rhinoscriptsyntax as rs

td = rs.AddTextDot('x', [10, 10, 0])
p = rs.TextDotPoint(td)
t = rs.TextDotText(td)

print("type(td): %s" % type(td))
print("t: %s" % t)
print("p: %s" % p)
print("type(p): %s" % type(p))
print("len(p): %i" % len(p))
print("p is list: %s" % (type(p) == list))
print("p is tuple: %s" % (type(p) == tuple))
p_tuple = tuple(p)
print("type(p_tuple): %s" % type(p_tuple))
print(p_tuple)
# print("p coordinates: %s" % rs.PointCoordinates(p))
print("td coordinates: %s" % rs.PointCoordinates(td))   ##  None