Ejemplo n.º 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)
Ejemplo n.º 2
0
def explodeTextObjects(objs):
    new_list = []

    for obj in objs:

        if rs.IsText(obj) and rs.LayerVisible(
                rs.ObjectLayer(obj)) and ("CNC" in rs.ObjectLayer(obj)):
            # only explode Text when
            # - layer visible
            # - CNC layer

            # polylines = convertTextToPolylines(ob)
            polylines = convertTextToPolylines2(obj)

            for polyline in polylines:
                new_list.append(polyline)

#            if ("CNC" in rs.ObjectLayer(obj)):
#                # rs.GetBoolean(text, "get", True)
#                # result = rs.TextObjectFont(obj, "Machine Tool Gothic")
#
#                # rs.MessageBox('test' + rs.TextObjectText(obj))
#                # polylines = rs.ExplodeText(obj, True)
#
#                polylines = convertTextToPolylines(obj)
#
#                for polyline in polylines:
#                    new_list.append(polyline)
#            else:
#                # add unexploded text
#                new_list.append(obj)
        else:
            new_list.append(obj)

    return new_list
def DeleteMockup():

    if not sc.sticky["PanelTypes_Data" + PANEL_TYPES_ID]: return

    for data in sc.sticky["PanelTypes_Data" + PANEL_TYPES_ID]:
        if isinstance(data, SGLibPanel):
            data.HideAll()  #same as deleting all panel objects
        elif rs.IsText(data):
            rs.DeleteObject(data)
Ejemplo n.º 4
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')
Ejemplo n.º 5
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')
Ejemplo n.º 6
0
def convertToVolumes( objs, material_thickness ):
    invalid_layers =[]
    
    # first find relevant layers
    layers = []
    volumes = []
    subtracts = []
    
    # sort objects
    for obj in objs:
        layer_name = rs.ObjectLayer(obj)
        
        m = ce.parseLayer(layer_name)

        if m and len(m.groups()) > 4 and not rs.IsText(obj):
            tool_id     = m.group(1)
            operation   = m.group(2)
            z_pos       = float(m.group(3) + m.group(4))
            
            if operation == 'Outer contour':
                volume = makeExtrusions(tool_id, operation, z_pos, obj, material_thickness)
                if volume:
                    volumes.append(volume) 
            elif operation == "Pocket" or operation == 'Pocket' or operation=='Drill' or operation == 'Inner contour':
                
                pocket =  createPockets(tool_id, operation, z_pos, obj)
                if pocket:
                    subtracts.append(pocket  )
                    
            elif operation == 'Engrave':
            
                engraves =  makeEngraves(tool_id, operation, z_pos, obj)
                for engrave in engraves:
                    subtracts.append(engrave ) 
        else:
            invalid_layers.append(layer_name)
        
    
    
    myset = set(invalid_layers)
    msg = 'layers could not be processed:\n'
    
    for layer in myset:
        msg += '- ' + layer + "\n"
        
    if len(myset)>0:
        rs.MessageBox(msg)
    
    return volumes, subtracts
Ejemplo n.º 7
0
 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
Ejemplo n.º 8
0
def explodeTextObjects(objs):

    new_list = []

    for obj in objs:
        if rs.IsText(obj):

            # rs.GetBoolean(text, "get", True)
            # result = rs.TextObjectFont(obj, "MecSoft_Font-1")

            polylines = rs.ExplodeText(obj, True)

            for polyline in polylines:
                new_list.append(polyline)
        else:
            new_list.append(obj)

    return new_list
Ejemplo n.º 9
0
def filterObjects(objs):
    new_list = []
    for obj in objs:
        layername = rs.ObjectLayer(obj)
        if rs.LayerVisible(layername) and not (re.search(
                'hulp', layername, re.IGNORECASE)):
            # if rs.LayerVisible( layername ):
            # only export visible layers
            if rs.IsCurve(obj):
                new_list.append(obj)

            elif rs.IsPoint(obj):
                # convert to circle
                layer = rs.ObjectLayer(obj)
                point = rs.coerce3dpoint(obj)

                circle = rs.AddCircle(rs.WorldXYPlane(), 3)

                rs.ObjectLayer(circle, layer)
                rs.MoveObject(circle, [point.X, point.Y, point.Z])
                new_list.append(circle)
                rs.DeleteObject(obj)
                # rs.DeleteObject(point)
            elif rs.IsText(obj) and (re.search('CNC::', layername,
                                               re.IGNORECASE)):
                # only export text if it is in CNC layer
                new_list.append(obj)
            else:
                # remove from obj list
                rs.DeleteObject(obj)
        else:
            # remove from obj list
            rs.DeleteObject(obj)

    # for i, obja in enumerate(new_list):
    # for j, objb in enumerate(new_list):
    # if(i != j):
    # if rs.IsCurve(obja) and rs.IsCurve(objb):

    # compare objects:

    return new_list
Ejemplo n.º 10
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)
Ejemplo n.º 11
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()
Ejemplo n.º 12
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)
Ejemplo n.º 13
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)