Esempio n. 1
0
def checkCurvePosition(objs):
    layers = []
    for obj in objs:
        if rs.IsCurve(obj):
            if not isCurveOnCPlane(obj):
                # print "Curve {} not on Cplane".format(obj)
                rs.SelectObject(obj)
                appendLayer(layers, obj)

        elif rs.IsPoint(obj):
            if not isPointOnCplane(obj):
                # print "Curve {} not on Cplane".format(obj)
                rs.SelectObject(obj)
                appendLayer(layers, obj)
        else:
            print "object {} is not a curve or point".format(obj)

    # when an object is found on > 0 layers, prompt for proceed
    if len(layers) > 0:
        msg = "there were curves found on layers:\n"
        for layer in layers:
            msg = msg + "- " + layer + " \n"

        if rs.MessageBox(msg, 1) != 1:
            return False

    # else
    return True
Esempio n. 2
0
def CockpitWindowContours(Height=1.620, Depth=5):
    P1 = [0.000, 0.076, Height - 1.620 + 2.194]
    P2 = [0.000, 0.852, Height - 1.620 + 2.290]
    P3 = [0.000, 0.904, Height + 0.037]
    P4 = [0.000, 0.076, Height]
    CWC1 = rs.AddPolyline([P1, P2, P3, P4, P1])
    rs.SelectObject(CWC1)
    rs.Command("_FilletCorners 0.08 ")

    P1 = [0.000, 0.951, Height - 1.620 + 2.289]
    P2 = [0.000, 1.343, Height - 1.620 + 2.224]
    P3 = [0.000, 1.634, Height - 1.620 + 1.773]
    P4 = [0.000, 1.557, Height - 1.620 + 1.588]
    P5 = [0.000, 1.027, Height - 1.620 + 1.671]
    CWC2 = rs.AddPolyline([P1, P2, P3, P4, P5, P1])
    rs.SelectObject(CWC2)
    rs.Command("_FilletCorners 0.08 ")

    CWC3 = act.MirrorObjectXZ(CWC1)
    CWC4 = act.MirrorObjectXZ(CWC2)

    ExtPathId = rs.AddLine([0, 0, 0], [Depth, 0, 0])

    CWC1s = rs.ExtrudeCurve(CWC1, ExtPathId)
    CWC2s = rs.ExtrudeCurve(CWC2, ExtPathId)
    CWC3s = rs.ExtrudeCurve(CWC3, ExtPathId)
    CWC4s = rs.ExtrudeCurve(CWC4, ExtPathId)

    rs.DeleteObjects([CWC1, CWC2, CWC3, CWC4, ExtPathId])

    return CWC1s, CWC2s, CWC3s, CWC4s
Esempio n. 3
0
def CrossPlatformExtrudeSurface(SurfaceId, CurveId, Capped=True):
    # rs.ExtrudeSurface not implemented in Rhino for OS X

    if airconics_setup.RhinoVersion == 1:
        SolidId = rs.ExtrudeSurface(SurfaceId, CurveId, Capped)
    else:
        rs.SelectObject(CurveId)
        rs.Command("_SelNone")
        rs.SelectObject(SurfaceId)
        rs.Command("_ExtrudeSrfAlongCrv _SelPrev")
        SolidId = rs.LastCreatedObjects()
        rs.Command("_SelNone")

    return SolidId
Esempio n. 4
0
def main():


    print 'test' 
    
    objs = rs.GetObjects()
    vec_x = [10,0,0]

    # restore viewport Cplane
    p1 = rs.WorldXYPlane()
    rs.ViewCPlane(None, p1)    
    
    for obj in objs:
       
            
        
        if rs.IsBlockInstance(obj) and rs.BlockInstanceName(strObject):

        xform1 = rs.BlockInstanceXform(obj)
        crv = rs.AddCurve([ [0,0,0], [0,300,0] ])
        xfrom1_inv = rs.TransformObject( crv, (xform1) )

        rs.SelectObject(crv)
     
     
        vec1 = rs.CurveEndPoint(crv) - rs.CurveStartPoint(crv)
        print vec1, math.degrees(calcAngle(vec1, vec_x))
        
        

         
    
if __name__ == "__main__":
    main();
Esempio n. 5
0
def selectObjperVolume(ids, targetV):
    volumes = []
    objs = [rs.coercegeometry(id) for id in ids]
    for i, obj in enumerate(objs):
        if isinstance(obj, Rhino.Geometry.Brep):
            if obj.IsSolid:
                volumes.append((rs.SurfaceVolume(obj)[0], ids[i]))
        elif isinstance(obj, Rhino.Geometry.Extrusion):
            if obj.IsSolid:
                volumes.append((rs.SurfaceVolume(obj)[0], ids[i]))
        elif isinstance(obj, Rhino.Geometry.Mesh):
            if obj.IsClosed:
                volumes.append((rs.MeshVolume([obj])[1], ids[i]))

    if len(volumes) > 0:
        subtractL = []
        for i, v in enumerate(volumes):
            subtractL.append((abs(v[0] - targetV), v[0], v[1]))

        subtractL.sort()
        rs.SelectObject(subtractL[0][2])
        print "Selected object with %s %s volume" % (subtractL[0][1],
                                                     unitSystem())
        return subtractL[0][2]

    else:
        print "No closed object selected"
        return None
Esempio n. 6
0
        def exportBrep(Brep, folder):

            Brep = Brep[0]
            rs.SelectObject(Brep)
            file = folder + "\\" + self.m_textbox.Text + "solido" + ".step"
            extension = ".step"
            export = rs.Command("_-Export " + file + " _Enter")
Esempio n. 7
0
    def setNormalVec(self):
        #set normal vector from selected base surface
        #if selected base surface isn't planar, return False

        self.baseSurface = rs.GetSurfaceObject(
            "Select surface to be addded object")
        if self.baseSurface == None:
            return False

        rs.SelectObject(self.baseSurface[0])

        if not rs.IsSurfacePlanar(self.baseSurface[0]):
            print(
                "Selected Surface is not planar\nPlease select planar surface")
            return False

        print("Confirm direction to add object")
        rs.Command("Dir")

        self.normalVec = rs.SurfaceNormal(self.baseSurface[0], [0, 0])

        rs.UnselectAllObjects()

        self.setAngleOfBaseSurface()

        return True
Esempio n. 8
0
def checkCurvePosition(objs):
    layers = []
    selection = []
    for obj in objs:
        if rs.IsCurve(obj):
            if not isCurveOnCPlane(obj):
                # print "Curve {} not on Cplane".format(obj)
                selection.append(obj)
                appendLayer(layers, obj)

        elif rs.IsPoint(obj):
            if not isPointOnCplane(obj):
                # print "Curve {} not on Cplane".format(obj)
                rs.SelectObject(obj)
                appendLayer(layers, obj)
        else:
            print "object {} is not a curve or point. {}".format(
                obj, rs.ObjectType(obj))

    if len(selection) > 0:
        rs.SelectObjects(selection)

    # when an object is found on > 0 layers, prompt for proceed
    if len(layers) > 0:
        msg = "there were non-planar or elevated curves found on layers:\n"
        for layer in layers:
            msg = msg + "- " + layer + " \n"

        msg = msg + '\n Do you want to proceed?'

        if rs.MessageBox(msg, 1) != 1:
            return False

    # else
    return True
Esempio n. 9
0
def export(ids, file_path, file_name, file_type, doc):
    """
    Exports Rhino geometry to a file.

    :param ids: Geometry ID
    :param file_path: File directory
    :param file_name: File name
    :param file_type: File extension
    :param doc: Grasshopper document
    :return: True on success.
    """

    sel_ids = ""
    for i in range(len(ids)):
        sel_ids += "_SelId %s " % ids[i]

    file_name_and_type = file_name + file_type
    final_path = chr(34) + file_path + '\\' + file_name_and_type + chr(34)

    command_string = "_-Export " + sel_ids + "_Enter " + final_path + \
                     " _Enter _Enter _Enter"
    echo = False
    done = rs.Command(command_string, echo)

    sc.doc = rc.RhinoDoc.ActiveDoc
    rs.SelectObject(ids)
    rs.Command("_Delete", True)
    sc.doc = doc

    if done:
        return True
    else:
        return False
Esempio n. 10
0
def ptCheck(a):
    #determines if the submitted point is a point object in space or array value
    #if object is 
    
    #designation implemented to determine if it is not a point object
    designation = 0
    
    try:
        if rs.ObjectType(a) == 1: #collect point object value
            b = rs.coerce3dpoint(a)
        elif rs.ObjectType(a)!= 1: #item is not a point
            designation = 1
    except:
        #item already an array object for use
        b = a
    
    #exporting value
    if designation == 0:
        return b
    #not a point object
    else:
        rs.UnselectAllObjects()
        print "Collecting point value but is another object type"
        rs.SelectObject(a)
        exit()
Esempio n. 11
0
 def set_up_bad_type_selection():
     g.Grammar.clear_all()
     f.Frame.new()
     r.Rule.add_first()
     line = rs.AddLine((0, 0, 0), (10, 10, 0))
     lpoint = rs.AddTextDot('textdot', (5, 5, 0))
     rs.SelectObject(line)
Esempio n. 12
0
 def set_up_bad_type_preselection():
     g.Grammar.clear_all()
     f.Frame.new()
     r.Rule.add_first()
     line = rs.AddLine((0, 0, 0), (20, 20, 0))
     text = rs.AddText('label', (10, 10, 0), 2)
     rs.SelectObject(line)
Esempio n. 13
0
def MakeBlockUniqueButton():
    try:
        block = rs.GetObject("Select block to make unique",
                             rs.filter.instance,
                             preselect=True)
        if block is None: return

        defaultName = utils.UpdateString(rs.BlockInstanceName(block))

        looping = True
        while looping:
            newName = rs.StringBox("Enter new block name",
                                   default_value=defaultName,
                                   title='MakeUnique')
            if newName is None: return
            if rs.IsBlock(newName):
                print "Block name already exists"
            elif len(newName) == 0:
                print "Must specify a name"
            else:
                looping = False

        if newName is None: return

        rs.EnableRedraw(False)
        newBlock = MakeBlockUnique(block, newName)
        rs.EnableRedraw(True)
        rs.SelectObject(newBlock)
        return True
    except:
        return False
Esempio n. 14
0
def RunCommand(is_interactive):
    ringSize = rs.GetReal("Ring size", 8.5, 0, 16)
    center = rs.GetPoint("Location")

    plane = rs.MovePlane(rs.ViewCPlane(), center)
    radius = (11.63 + 0.8128 * ringSize) * 0.5
    objId = rs.AddCircle(plane, radius)
    rs.SelectObject(objId)
Esempio n. 15
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 ()
Esempio n. 16
0
def GetPointDynamicDrawFuncSelect(sender, args):
    # pt1 = Rhino.Geometry.Point3d(0,0,0)
    # pt2 = Rhino.Geometry.Point3d(10,10,0)
    # args.Display.DrawLine(pt1, args.CurrentPoint, System.Drawing.Color.Red, 2)
    # args.Display.DrawLine(pt2, args.CurrentPoint, System.Drawing.Color.Blue, 2)

    rs.UnselectAllObjects()

    cursPos = rs.GetCursorPos()
    viewSize = rs.ViewSize()
    stepSize = int(viewSize[1] / _NUM_LAYER)

    obj_Layer1 = 'Layer: 000001 Wall1'
    obj_Layer2 = 'Layer: 000002 Wall1'
    settings = Rhino.DocObjects.ObjectEnumeratorSettings()

    settings.NameFilter = obj_Layer1
    ids_L1 = [rhobj.Id for rhobj in scriptcontext.doc.Objects.GetObjectList(settings)]

    settings.NameFilter = obj_Layer2
    ids_L2 = [rhobj.Id for rhobj in scriptcontext.doc.Objects.GetObjectList(settings)]

    z_L1 = rs.BoundingBox(ids_L1[0])[0][2]
    z_L2 = rs.BoundingBox(ids_L2[0])[0][2]

    zVal = viewSize[1] - cursPos[3][1]

    z_level = int(zVal / stepSize)

    segmentList = ['Wall',
                   'DenseInfill',
                   'SparseInfill',
                   'Brim',
                   'Skirt',
                   'Support']

    zero_str = '000000'

    settings = ObjectEnumeratorSettings()

    for segment in segmentList:
        i = 0
        while 1:
            i += 1
            obj_LayerZ = str('Layer: ' + zero_str[:-len(str(z_level))] + str(z_level) + ' ' + segment + str(i))
            try:
                settings.NameFilter = obj_LayerZ
                ids_LZ = [rhobj.Id for rhobj in scriptcontext.doc.Objects.GetObjectList(settings)]
                if len(ids_LZ) == 0:
                    break
                rs.SelectObject(ids_LZ)

            except:
                print 'not found'

    args.Display.DrawDot(args.CurrentPoint, 'Layer ' + str(z_level) + ' - Distance ' + str(z_L2 - z_L1) + ' mm')
    Rhino.Display.RhinoView.Redraw(scriptcontext.doc.Views.ActiveView)
    Rhino.RhinoApp.Wait()
Esempio n. 17
0
def AddTEtoOpenAirfoil(AirfoilCurve):
    # If the airfoil curve given as an argument is open at the trailing edge, it adds
    # a line between the ends of the curve and joins this with the rest of the curve.
    if rs.IsCurveClosed(AirfoilCurve) == False:
        EP1 = rs.CurveEndPoint(AirfoilCurve)
        rs.ReverseCurve(AirfoilCurve)
        EP2 = rs.CurveEndPoint(AirfoilCurve)
        rs.ReverseCurve(AirfoilCurve)
        Closure = rs.AddLine(EP1, EP2)
        rs.UnselectAllObjects()
        rs.SelectObject(Closure)
        rs.SelectObject(AirfoilCurve)
        rs.Command("_Join ")
        LO = rs.LastCreatedObjects()
        AirfoilCurve = LO[0]
        rs.UnselectAllObjects()

    return AirfoilCurve
Esempio n. 18
0
def setCurveDir(objs):
    rs.UnselectAllObjects()
    count = 0
    count2 = 0

    for obj in objs:
        if rs.IsCurve(obj) and rs.IsCurveClosed(obj):

            # 1 = CW, -1 = CCW, 0 = N/A
            # -1 if the curve's orientation is counter-clockwise
            # 0 if unable to compute the curve's orientation
            if rs.ClosedCurveOrientation(obj) == 0:

                if DEBUG_FLIPCUVRVE:
                    rs.SelectObject(obj)
                    return False

                count2 += 1
            if rs.ClosedCurveOrientation(obj) == 1:
                rs.ReverseCurve(obj)
                count += 1

                if DEBUG_FLIPCUVRVE:
                    rs.SelectObject(obj)

                # normal = rs.CurveNormal(obj)
                # if normal and normal[2] < 0:
                # count += 1
                # rs.ReverseCurve(obj)
                # rs.SelectObject(obj)

    rs.EnableRedraw(True)
    rs.EnableRedraw(False)

    print "reversed curves  " + str(count) + " curves"

    if DEBUG_FLIPCUVRVE:
        rs.MessageBox("reversed curves  " + str(count) + " curves")

    if count2 > 0:
        rs.MessageBox("Curve direction of " + str(count) +
                      " curves could not be determined")

    return True
Esempio n. 19
0
 def set_up_good_arg():
     g.Grammar.clear_all()
     f.Frame.new()
     r.Rule.add_first()
     line = rs.AddLine((0, 0, 0), (10, 10, 0))
     lpoint = rs.AddTextDot('textdot', (10, 10, 0))
     text = rs.AddText('text', (5, 5, 0), 2)
     message = "Select the rule name tag"
     rule_name_tag = rs.GetObject(message)
     rs.SelectObject(rule_name_tag)
Esempio n. 20
0
def Run(objs, dir, ext):
    rs.EnableRedraw(False)
    rs.UnselectAllObjects()
    for i in range(len(objs)):
        obj = objs[i]
        filepath = dir + "/exported" + str(i) + "." + ext
        rs.SelectObject(obj)
        rs.Command("!_-Export \"" + filepath + "\" -Enter -Enter")
        rs.UnselectAllObjects()
    rs.EnableRedraw(True)
def flipBowtie(srf_id, pts_for_srf, N2):
    # corrects for Rhino bug by flipping "bow tie" surfaces
    # I know there is a more consise way to code this,
    # but this is easy

    rs.SelectObject(srf_id)  # select surface
    rs.Command("-_projecttocplane " + "Yes " + "-_Enter ")
    proj_id = rs.GetObject(preselect=True)

    return pts_for_srf
 def _get_rule_name(self):
     """Prompts the user to select a rule name tag, if one is not already 
     selected. Returns:
         str             the name of a rule
     """
     while not self._a_rule_name_tag_is_selected():
         rule_name_tag = self._get_rule_name_tag()
         rs.SelectObject(rule_name_tag)
     rule_name = self._get_rule_name_from(rule_name_tag)
     return rule_name
Esempio n. 23
0
def objBatchExport():
    selection = rs.GetObjects(preselect=True)
    rs.EnableRedraw(False)
    for i, obj in enumerate(selection):
        e_file_name = "{}\{}.obj".format(filepath,
                                         'target' + rs.ObjectName(obj))
        rs.UnselectAllObjects()
        rs.SelectObject(obj)
        rs.Command('-_Export "{}" _Enter _Enter'.format(e_file_name), True)
    rs.EnableRedraw(True)
Esempio n. 24
0
def objBatchExport():
    selection = rs.GetObjects(preselect=True)
    folder = rs.BrowseForFolder(rs.WorkingFolder())

    rs.EnableRedraw(False)
    for i, obj in enumerate(selection):
        e_file_name = "{}-{}.obj".format("habibi", i)
        rs.UnselectAllObjects()
        rs.SelectObject(obj)
        rs.Command('-_Export "{}" _Enter'.format(e_file_name), True)
    rs.EnableRedraw(True)
Esempio n. 25
0
def CreateCircle(circumference=None):
    center = rs.GetPoint("Center point of circle")
    if center:
        plane = rs.MovePlane(rs.ViewCPlane(), center)
        length = circumference
        if length is None: length = rs.GetReal("Circle circumference")
        if length and length > 0:
            radius = length / (2 * math.pi)
            objectId = rs.AddCircle(plane, radius)
            rs.SelectObject(objectId)
            return length
    return None
def applyVrayMatToLayer(layer, matName):
    """
    applies vray mat to a layer
    input: layer, single layer name - matName: Vray mat string e.g. /glass_architectural
    returns: None
    """
    srf = rs.AddSphere([0,0,0], 1)
    rs.SelectObject(srf)
    rs.Command("-_visApplyMaterial "+matName)
    matIndex = rs.ObjectMaterialIndex(srf)
    rs.LayerMaterialIndex(layer, matIndex)
    rs.DeleteObject(srf)
    return None
def matIndexByMatName(matName):
    rs.EnableRedraw(False)
    circle = rs.AddCircle([0, 0, 0], 5)
    srf = rs.AddPlanarSrf(circle)
    #rs.ObjectMaterialIndex(srf, material_index =8)
    rs.SelectObject(srf)
    rs.Command("-_visApplyMaterial " + matName)
    matIndex = rs.ObjectMaterialIndex(srf)
    rs.DeleteObject(circle)
    rs.DeleteObject(srf)
    #obj = rs.coercerhinoobject(srf)
    #obj.Attributes.MaterialIndex = 8
    #print obj.Attributes.MaterialIndex
    rs.EnableRedraw(True)
    return matInd
Esempio n. 28
0
def processBrepObject(gBrep0, idx_rgFaceA, idx_rgFaces_Filter=None, bPrimitives=None, bNurbsSrfs=None, fTolerance=None, bCopy=None, bEcho=None, bDebug=None):
    """
    """
    
    if bPrimitives is None: bPrimitives = Opts.values['bPrimitives']
    if bNurbsSrfs is None: bNurbsSrfs = Opts.values['bNurbsSrfs']
    if fTolerance is None: fTolerance = Opts.values['fTolerance']
    if bEcho is None: bEcho = Opts.values['bEcho']
    if bDebug is None: bDebug = Opts.values['bDebug']
    
    rdBrep0 = sc.doc.Objects.FindId(gBrep0) if Rhino.RhinoApp.ExeVersion >= 6 else sc.doc.Objects.Find(gBrep0)
    rgBrep0 = rdBrep0.Geometry
    
    rc = getFaces(
            rgBrep0=rgBrep0,
            bPrimitives=bPrimitives,
            bNurbsSrfs=bNurbsSrfs,
            idx_rgFaceA=idx_rgFaceA,
            idx_rgFaces_Filter=idx_rgFaces_Filter,
            bMergeAll=True,
            fTolerance=fTolerance,
            bEcho=bEcho,
            bDebug=bDebug,
    )
    if rc is None: return
    idx_rgFs_B0_Pass, rgShapeA = rc
    
    if rgBrep0.Faces.Count == len(idx_rgFs_B0_Pass):
        print "Entire brep matches the face."
        bSelected = rs.SelectObject(gBrep0)
        rgBrep0.Dispose()
        return bSelected
    else:
        if Rhino.RhinoApp.ExeVersion >= 6:
            xBrepObject.selectFaces(rdBrep0, idx_rgFs_B0_Pass)
            rgBrep0.Dispose()
        else:
            # Rhino V5.
            rc = xBrepObject.extractFaces(
                    gBrep0,
                    idxFaces=idx_rgFs_B0_Pass,
                    bCurrentLayer=False,
                    bByLayerColor=False,
                    bAddOnlyMonofaces=True,
                    bEcho=bEcho,
                    bDebug=bDebug)
            rgBrep0.Dispose()
            return None if rc is None else rc[0]
Esempio n. 29
0
    def explode(objs, li):
        for obj in objs:
            if rs.IsBlockInstance(obj):

                # DIRTY FIX FOR RHINO 5-SR14 522.8390 (5-22-2017)
                # temp_objs = rs.ExplodeBlockInstance(obj)

                rs.UnselectAllObjects()
                rs.SelectObject(obj)
                rs.Command("Explode" , False)
                temp_objs = rs.LastCreatedObjects()

                explode(temp_objs, li)
            else:
                li.append(obj)

        return li
Esempio n. 30
0
def array_between():


    rs.SelectObject(u)
    m=rs.GetObject('select the curve for path')
    amount = rs.GetInteger('How many objects in array')
    if not amount: return
    p=rs.DivideCurveEquidistant(m,amount,True)
    for i in p:
        point1 = i
        for x in p:
            point2 = x
            vector = rs.VectorCreate(point2, point1)
            copyvec = rs.VectorDivide(vector, amount - 1)

    for v in range(1, amount):
        copy = rs.CopyObject(u, copyvec * v)

    rs.UnselectObject(u)