Esempio n. 1
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
def innerPanel():
    objs = rs.GetObjects("Select objects to add frame to", filter = 24, group = True,preselect = True)
    if objs is None:
        return
    dist = rs.GetReal("Offset Distance")
    if dist is None:
        return
    rs.EnableRedraw(False)
    
    srfs = []
    
    for obj in objs:
        if rs.IsPolysurface(obj):
            srfs = srfs + rs.ExplodePolysurfaces(obj)
        else:
            srfs.append(rs.CopyObject(obj))
    
    for srf in srfs:
        if rs.IsSurfacePlanar(srf):
            edgeCrvs = rs.DuplicateEdgeCurves(srf)
            border = rs.JoinCurves(edgeCrvs, True)
            innerEdge = rs.OffsetCurveOnSurface(border, srf, dist)
            #rs.SplitBrep(srf, innerEdge)
            rs.AddPlanarSrf(innerEdge)
            rs.DeleteObject(innerEdge)
            rs.DeleteObject(border)
        else:
            print "A surface was not planar"
    rs.DeleteObjects(srfs)
    rs.EnableRedraw(True)
Esempio n. 3
0
def write_strip_data(layer, point_ind):
    # get all surfaces on layer
    strips = rs.ObjectsByLayer(layer)
    strip_ind = 1
    strip_dict = {}
    for strip in strips:
        # get only surfaces
        if rs.IsSurface(strip):
            if rs.IsSurfacePlanar(strip):
                strip_dict['Strip=' + layer + str(strip_ind)] = []
                strip_brep = rs.coercebrep(strip)
                edges = Rhino.Geometry.Brep.DuplicateEdgeCurves(strip_brep)
                edge_ids = []
                ind = 0
                for edge in edges:
                    edge_id = sc.doc.Objects.AddCurve(edge)
                    if edge_id:
                        rs.ObjectName(edge_id, 'active' + str(ind))
                        edge_ids.append(edge_id)
                        ind += 1
                # Get strip geometry
                # change color to help find strip
                rs.ObjectColor(strip, color=(255, 0, 255))
                start_edge = rs.GetObject('Select start edge.', 4, False,
                                          False, active_strip_filter)
                start_length = rs.CurveLength(start_edge)
                sp = rs.CurveMidPoint(start_edge)
                rs.ObjectName(rs.AddPoint(sp), name='SP_' + str(point_ind))
                end_edge = rs.GetObject('Select end edge.', 4, False, False,
                                        active_strip_filter)
                end_length = rs.CurveLength(end_edge)
                ep = rs.CurveMidPoint(end_edge)
                rs.ObjectName(rs.AddPoint(ep), name='SP_' + str(point_ind))
                # Clean up
                rs.DeleteObjects(edge_ids)
                rs.ObjectColor(strip, color=(128, 0, 128))
                # write to json
                start = {
                    'Point': point_ind,
                    'GlobalX': round(sp.X, 4),
                    'GlobalY': round(sp.Y, 4),
                    'WALeft': round(start_length * 0.5, 4),
                    'WARight': round(start_length * 0.5, 4),
                    'Autowiden': 'No'
                }
                point_ind += 1
                end = {
                    'Point': point_ind,
                    'GlobalX': round(ep.X, 4),
                    'GlobalY': round(ep.Y, 4),
                    'WBLeft': round(end_length * 0.5, 4),
                    'WBRight': round(end_length * 0.5, 4),
                }
                strip_dict['Strip=' + layer + str(strip_ind)].append(start)
                strip_dict['Strip=' + layer + str(strip_ind)].append(end)
                point_ind += 1
                strip_ind += 1
    return strip_dict
Esempio n. 4
0
def CutModel_Button():
    objs = rs.GetObjects("Select objects to cut", preselect=True)
    if objs is None: return

    srf = rs.GetObject("Select cutting surface", rs.filter.surface)
    if srf is None: return
    if rs.IsSurfacePlanar(srf) == False:
        print "Cutting surface must be planar"
        return None

    rs.EnableRedraw(False)
    result = CutModel(objs, srf)
    if result:
        utils.SaveToAnalytics('Drawing-cut Model')
    utils.SaveFunctionData('Drawing-Cut Model',
                           [__version__, len(objs), result])
    rs.EnableRedraw(True)