Example #1
0
def BlockTxt(block, str = False, cstr = False, boolFlipHeb=True):
    if not block: return
    
    blockName = rs.BlockInstanceName(block)
    objref = rs.coercerhinoobject(block)
    idef = objref.InstanceDefinition
    idefIndex = idef.Index
    
    XformBlock = rs.BlockInstanceXform(block)
    blockObjects = rs.BlockObjects(blockName)
    
    txtobjs = False
    
    for obj in blockObjects:
        if rs.IsText(obj):
            if not str: txtobjs = True
            elif rs.TextObjectText(obj) == str: txtobjs = True
    
    if txtobjs:
        
        blockInstanceObjects = rs.TransformObjects(blockObjects, XformBlock, True)
        
        keep = []
        
        rs.EnableRedraw(False)
        
        for obj in blockInstanceObjects:
            if rs.IsText(obj):
                if not str and not cstr:
                    str = rs.TextObjectText(obj)
                    cstr = ConvTxt(str, boolFlipHeb)
                if not cstr == str:
                    rs.TextObjectText(obj, cstr)
                keep.append(obj)
            else: keep.append(obj)
        
        rs.TransformObjects(keep, rs.XformInverse(XformBlock), False)
        
        newGeometry = []
        newAttributes = []
        for object in keep:
            newGeometry.append(rs.coercegeometry(object))
            ref = Rhino.DocObjects.ObjRef(object)
            attr = ref.Object().Attributes
            newAttributes.append(attr)
        
        InstanceDefinitionTable = sc.doc.ActiveDoc.InstanceDefinitions
        InstanceDefinitionTable.ModifyGeometry(idefIndex, newGeometry, newAttributes)
        
        rs.DeleteObjects(keep)
 def _get_line_specs_and_lpoint_specs(self, guids):
     """Receives a list of guids:
         [guid, ...]
     Returns a list of coord-coord pairs and a list of coord-label pairs:
         (   [((num, num, num), (num, num, num)), ...],
             [((num, num, num), str), ...]
         )
     """
     line_specs = []
     lpoint_specs = []
     line_type = 4  ##  limit to straight lines
     annotation_type = 512
     textdot_type = 8192
     for guid in guids:
         guid_type = rs.ObjectType(guid)
         if guid_type == line_type:
             line_spec = self._get_line_spec(guid)
             line_specs.append(line_spec)
         elif guid_type == annotation_type:
             point = rs.TextObjectPoint(guid)
             x, y, z = point[0], point[1], point[2]
             coord = (x, y, z)
             label = rs.TextObjectText(guid)
             lpoint_spec = (coord, label)
             lpoint_specs.append(lpoint_spec)
         elif guid_type == textdot_type:
             coord, label = self._get_lpoint_spec(guid)
             lpoint_spec = (coord, label)
             lpoint_specs.append(lpoint_spec)
     return (line_specs, lpoint_specs)
 def _get_rule_name_from(self, rule_name_tag):
     """Receives:
         rule_name_tag   the guid of a text object; the type is guaranteed 
                         by the calling method
     Returns:
         str             the text of the text object, i.e., the rule name
     """
     return_value = rs.TextObjectText(rule_name_tag)
     return return_value
def viewportclock():
    now = datetime.datetime.now()
    textobject_id = rs.AddText(now, (0, 0, 0), 20)
    if textobject_id is None: return

    while True:
        rs.Sleep(1000)
        now = datetime.datetime.now()
        rs.TextObjectText(textobject_id, now)
Example #5
0
def UpdateAreaTag():
    objs = rs.GetObjects('Select area tags to update', preselect = True)
    if objs is None: return

    successfulObjsRun = 0
    failedObjsRun = 0
    for obj in objs:
        try:
            host = rs.GetUserText(obj, 'hostGUID')
            if host is None:
                print "Could not find associated geometry"
                return None

            #Get number of dec places
            text = rs.TextObjectText(obj)
            splitText = text.Split(" ")

            numberString = splitText[0]
            units = splitText[-1]

            try:
                decPlaces = len(numberString.Split(".")[1])
            except:
                decPlaces = 0

            #Get area
            if rs.UnitSystem() == 8:
                area = rs.Area(rs.coerceguid(host))*0.0069444444444444
                areaText = utils.RoundNumber(area, decPlaces) + " " + units
            else:
                print "WARNING: Your units are not in inches"
                area = rs.Area(rs.coerceguid(host))
                areaText = area + ' ' + rs.UnitSystemName(False, True, True)

            rs.TextObjectText(obj, areaText)

            successfulObjsRun += 1
        except:
            failedObjsRun += 1
            print "Tag failed"

    utils.SaveFunctionData('Drawing-Update Area Tag', [__version__, successfulObjsRun, failedObjsRun])

    return successfulObjsRun
Example #6
0
def test_text():
    draw_lpoint()
    prompt = 'Select some objects, OK?'
    guids = rs.GetObjects(prompt)
    print('Number of objects: %i' % len(guids))
    for guid in guids:
        if rs.IsText(guid):
            text = rs.TextObjectText(guid)
            print('object is text: %s' % text)
        else:
            print('object not text')
Example #7
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')
Example #8
0
def convertToPolylines(obj):

    # get object properties
    text            = rs.TextObjectText(obj)
    pt              = rs.TextObjectPoint(obj)
    origin          = rs.coerce3dpoint([0,0,0])
    ht              = rs.TextObjectHeight(obj)
    object_layer    = rs.ObjectLayer(obj)
    plane           = rs.TextObjectPlane(obj)
        
    diff = rs.coerce3dpoint([pt.X, pt.Y, pt.Z])

    p1 = rs.WorldXYPlane()
        
    matrix = rs.XformRotation4(p1.XAxis, p1.YAxis, p1.ZAxis, plane.XAxis, plane.YAxis, plane.ZAxis)


    rs.DeleteObject(obj)
        


    # set current layer to put strings in
    prevlayer = rs.CurrentLayer()
    layer = rs.AddLayer('temptextlayer')
    rs.CurrentLayer('temptextlayer')

    # split text at enters
    text = text.split('\r\n')
    opts='GroupOutput=No FontName="timfont" Italic=No Bold=No Height='+ str(ht)
    opts+=" Output=Curves AllowOpenCurves=Yes LowerCaseAsSmallCaps=No AddSpacing=No "
    
    origin.Y += ht * len(text) *1.2
    for item in text:
        rs.Command("_-TextObject " + opts + '"'+item+'"' + " " + str(origin) , False)
        origin.Y -= ht *1.5
        
    #restore current layer
    rs.CurrentLayer(prevlayer)

    
    #select newly created texts
    polylines = rs.ObjectsByLayer('temptextlayer')
    
    # transform to old position
    rs.TransformObjects(polylines, matrix, copy=False)
    rs.MoveObjects(polylines, diff)
    
    rs.ObjectLayer(polylines, object_layer)
    
    return polylines
Example #9
0
def convertTextToPolylines2(obj):

    # get object properties
    text = rs.TextObjectText(obj)
    pt = rs.TextObjectPoint(obj)
    origin = rs.coerce3dpoint([0, 0, 0])
    ht = rs.TextObjectHeight(obj)
    object_layer = rs.ObjectLayer(obj)
    plane = rs.TextObjectPlane(obj)

    diff = rs.coerce3dpoint([pt.X, pt.Y, pt.Z])

    p1 = rs.WorldXYPlane()
    #restore view cplane
    rs.ViewCPlane(None, p1)

    matrix = rs.XformRotation4(p1.XAxis, p1.YAxis, p1.ZAxis, plane.XAxis,
                               plane.YAxis, plane.ZAxis)

    rs.DeleteObject(obj)

    # split text at enters
    text = text.split('\r\n')
    opts = 'GroupOutput=No FontName="' + EXPORT_FONT + '" Italic=No Bold=No Height=' + str(
        ht)
    opts += " Output=Curves AllowOpenCurves=Yes LowerCaseAsSmallCaps=No AddSpacing=No "

    n_lines = len(text)

    origin.Y += 1.6 * ht * (len(text) - 1)

    polylines = []
    for item in text:
        rs.Command(
            "_-TextObject " + opts + '"' + item + '"' + " " + str(origin),
            False)
        polylines += rs.LastCreatedObjects()
        origin.Y -= ht * 1.6

    rs.ObjectLayer(polylines, object_layer)

    polylines = rs.ScaleObjects(polylines, (0, 0, 0), (0.7, 1, 1), True)

    # transform to old position
    rs.TransformObjects(polylines, matrix, copy=False)
    rs.MoveObjects(polylines, diff)

    return polylines
Example #10
0
def test__get_rule_name_tag():
    def set_up():
        g.Grammar.clear_all()
        f.Frame.new()
        r.Rule.add_first()

    method_name = "_get_rule_name_tag"
    try_name = 'try_any'
    set_up()
    my_ex = e.Exporter()
    actual_guid = my_ex._get_rule_name_tag()
    actual_value = rs.TextObjectText(actual_guid)
    expected_value = 'rule_1'
    if not actual_value == expected_value:
        g.Grammar.print_test_error_message(method_name, try_name,
                                           expected_value, actual_value)
 def _a_rule_name_tag_is_selected(self):
     """Returns:
         boolean         True, if the selected object is a rule name tag
                         False, otherwise
     """
     return_value = True
     selected_objects = rs.SelectedObjects()
     if not len(selected_objects) == 1:
         return_value = False
     else:
         selected_object = selected_objects[0]
         if not (rs.IsText(selected_object)
                 and cn.ComponentName._component_name_is_listed(
                     'rule', rs.TextObjectText(selected_object))):
             return_value = False
     return return_value
def RestoreWorldCoordinate():
    try:

        rs.EnableRedraw(False)

        # retreive northing and easting from text object
        obj = rs.ObjectsByName("_ORIGIN_TEXT_")
        if obj:
            text = rs.TextObjectText(obj)
            textList = text.split()
            easting = float(textList[1])
            northing = float(textList[3])

            # create reference coordinates to make vector
            orPoint = (easting, northing, 0)
            point = rs.PointCoordinates(rs.ObjectsByName("_ORIGIN_POINT_"))
            vector = rs.VectorCreate(orPoint, point)

            # move all objects back to original origin point
            allObj = rs.AllObjects()
            rs.MoveObjects(allObj, vector)

            # delete coordinate geometry
            isCurrent = rs.IsLayerCurrent("_ORIGIN_")
            if isCurrent == False:
                rs.PurgeLayer("_ORIGIN_")
            if isCurrent == True:
                defaultCheck = rs.IsLayer("Default")
                if defaultCheck == True:
                    rs.CurrentLayer("Default")
                    rs.PurgeLayer("_ORIGIN_")
                if defaultCheck == False:
                    rs.AddLayer("Default")
                    rs.CurrentLayer("Default")
                    rs.PurgeLayer("_ORIGIN_")

            rs.EnableRedraw(True)

    except:
        print("Failed to execute")
        rs.EnableRedraw(True)
        return
Example #13
0
def play_text():
    draw_lpoint.draw_lpoint()
    annotation = rs.GetObject('Select object', rs.filter.annotation)
    point = rs.TextObjectPoint(annotation)
    label = rs.TextObjectText(annotation)
    print('object type: %s' % type(point))
    point_type = type(point)
    if point_type == list:
        print('point type is list')
    elif point_type == tuple:
        print('point type is tuple')
    elif point_type == array.array:
        print('point type is array')
    # elif point_type == Point:
    #     print('point type is Point')
    else:
        print('point type is something else')
    print('len(point): %i' % len(point))
    x, y, z = point[0], point[1], point[2]
    print('coords: (%s, %s, %s)' % (x, y, z))
    print('point: %s' % point)
    print('label: %s' % label)
Example #14
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)
Example #15
0
def SampleExportUTF8():

    # extract texts in the model
    textList = []
    for o in rs.AllObjects():
        if rs.IsText(o):
            # explicitly encode to utf-8
            s = rs.TextObjectText(o).encode('utf-8')
            textList.append(s)

    # create a filename variable
    path = System.Environment.GetFolderPath(
        System.Environment.SpecialFolder.Desktop)
    filename = System.IO.Path.Combine(path, 'SampleExportUTF8.csv')

    file = open(filename, 'w')

    # create and write a header for the CSV file
    headerList = [u'Index', u'中国', u'English', u'Français']

    # explicitly encode to utf-8
    headerList = [i.encode('utf-8') for i in headerList]
    header = u"{}\n".format(u';'.join(headerList))
    file.write(header)

    # create and write a line in CSV file for every text in the model
    lineList = []
    i = 0
    for text in textList:
        line = [str(i), text]
        i += 1
        lineList.append(line)

    for line in lineList:
        fileLine = u';'.join(line) + u'\n'
        file.write(fileLine)

    file.close()
Example #16
0
"""
Author: Angel Linares Garcia.
Date: 150821
Description: This scripts takes one
selected curve and creates N offsets
at D distance.
"""
##############################

import rhinoscriptsyntax as rs

text = rs.GetObjects("Select text", 512, False, True)
strTarget = rs.GetString("Text to search")
strReplace = rs.GetString("Text to use")
print text

for t in text:
    if rs.IsText(t):
        str0 = rs.TextObjectText(t)
        strNew = str0.replace(strTarget, strReplace)
        rs.TextObjectText(t, strNew)
Example #17
0
import Rhino
import rhinoscriptsyntax as rs
import scriptcontext as sc

txt = rs.GetObject(message='select text', filter=512, preselect=True)

if rs.IsText(txt):
    text = rs.TextObjectText(txt)
    color = rs.ObjectColor(txt)

objs = rs.GetObjects(message='select objs', preselect=True)

def AddTag(obj, text, color):
    box = rs.BoundingBox(obj)
    mid = (box[0] + box[-2])/2
    tag = rs.AddTextDot(text, mid)
    rs.SetUserText(obj, 'tag', text)
    rs.ObjectColor(obj, color)
    group = rs.AddGroup()
    rs.AddObjectsToGroup([obj, tag], group)

if objs:
    map(lambda x: AddTag(x, text, color), objs)
Example #18
0
"""
Author: Ángel Linares García.
Date: 150821
Description: This scripts takes 
selected text objects in Rhino and creates
3dpoints located at the height contained in 
the text object.
"""
##############################

import rhinoscriptsyntax as rs

numbers = rs.GetObjects("Select text containing topography data", 512, False,
                        True)

for n in numbers:

    height = rs.TextObjectText(n)
    a = height.replace(",", ".")
    #print repr(a)
    #print float(height)
    pt = rs.TextObjectPoint(n)

    rs.AddPoint(pt.X, pt.Y, float(a))
Example #19
0
groupSet = list(set([rs.ObjectGroups(x)[0] for x in groupSet]))
###
print(groupSet)
filename = rs.SaveFileName("Save CSV File", "*.csv", None, "areaExport", "csv")

file = open(filename, 'w')

headerline = "Area Name, Area in SF\n"
file.write(headerline)

returnList = []

for groupObj in groupSet:
    objs = rs.ObjectsByGroup(groupObj)
    for obj in objs:
        print(rs.TextObjectText(obj))
        if rs.ObjectName(obj) == "Area Text":
            areaText = rs.TextObjectText(obj)
        elif rs.ObjectName(obj) == "Name Text":
            nameText = rs.TextObjectText(obj)
        objLayer = rs.ObjectLayer(obj)
    parentLayer = rs.ParentLayer(objLayer)
    if not parentLayer:
        parentLayer = "ROOT"
    else:
        parentLayer = parentLayer.split("::")[-1]

    returnList.append(
        [parentLayer,
         nameText.replace('\r', '').replace('\n', ' '), areaText])