コード例 #1
0
def offsetext():
    def RepresentsInt(s):
        try: 
            int(s)
            return True
        except ValueError:
            return False
    
    
    viste = rs.ViewNames()
    for viewport in viste:
        rs.ViewDisplayMode(viewport,"Shaded")
    diametro = rs.StringBox("dimensione della punta","10","scontornatura")
    if RepresentsInt(diametro):
        diametro = int(diametro)
    else:
        diametro = 10
    brep =  rs.GetObjects("dammi un solido",16)
    brepexp = rs.ExplodePolysurfaces(brep)
    get_val = rs.GetEdgeCurves("dammi le curve")
    surf_edge = []
    
    for i in get_val:
        surf_edge.append(i[0])
    surf_edge = rs.coerceguidlist(surf_edge)
    if len(surf_edge)>1:
        surf_edge = rs.JoinCurves(surf_edge,True)
    surface = rs.GetObjects("conferma la selezione",8,False,True,1,1)

    print surf_edge
    uv= []
    temp_edge = rs.ExplodeCurves(surf_edge,False)
    new_surface = rs.CopyObject(surface,(0,0,0))
    list_evpt =[]
    for i in temp_edge:
        evpt =rs.CurveMidPoint(i)
        print evpt
        list_evpt.append(evpt)
    for i in list_evpt:
        bord= rs.SurfaceClosestPoint(new_surface,i)
        uv.append(bord)
    for i in uv:
        rs.ExtendSurface(new_surface,i,diametro*10)
    edge = rs.OffsetCurveOnSurface(surf_edge,new_surface,-diametro)
    print edge
    if rs.CurveLength(edge)<rs.CurveLength(surf_edge):
        rs.DeleteObject(edge)
        edge =  rs.OffsetCurveOnSurface(surf_edge,new_surface,diametro)
    surf_edge = rs.ExplodeCurves(surf_edge,True)
    print edge
    
    rs.ObjectColor(edge,(0,0,255))
    for i in brepexp:
        rs.DeleteObject(i)
    for i in temp_edge:
        rs.DeleteObject(i)
    for i in surf_edge:
        rs.DeleteObject(i)
    
    rs.DeleteObjects([new_surface,surface])
コード例 #2
0
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)
コード例 #3
0
def TestOffset():
    curve = rs.GetEdgeCurves("dammi le curve")
    if curve is None: return False

    crvs = [curve[n][0] for n in range(len(curve))]
    newCurve = rs.JoinCurves(crvs, True)[0]

    reference = SubObjectSelect()
    surface = reference[0]
    point = reference[1]
    if surface is None: return False
    point = reference[1]
    if point is None: return False
    distance = 4
    offset = rs.OffsetCurveOnSurface(newCurve, surface, distance)
    if not offset: rs.OffsetCurveOnSurface(newCurve, surface, -1 * distance)
    return offset
コード例 #4
0
ファイル: offset.py プロジェクト: kellogio90/camrhino
new_surface = rs.CopyObject(surface, (0, 0, 0))
uv = []
temp_edge = rs.ExplodeCurves(surf_edge, False)

list_evpt = []
for i in temp_edge:
    evpt = rs.CurveMidPoint(i)
    print evpt
    list_evpt.append(evpt)
for i in list_evpt:
    bord = rs.SurfaceClosestPoint(new_surface, i)
    uv.append(bord)
for i in uv:
    rs.ExtendSurface(new_surface, i, diametro * 10)
edge = rs.OffsetCurveOnSurface(surf_edge, new_surface, -diametro)
print edge
if rs.CurveLength(edge) < rs.CurveLength(surf_edge):
    rs.DeleteObject(edge)
    edge = rs.OffsetCurveOnSurface(surf_edge, new_surface, diametro)
surf_edge = rs.ExplodeCurves(surf_edge, True)
print edge

rs.ObjectColor(edge, (0, 0, 255))
for i in brepexp:
    rs.DeleteObject(i)
for i in temp_edge:
    rs.DeleteObject(i)
for i in surf_edge:
    rs.DeleteObject(i)
コード例 #5
0
def create_bone(point, curve, length, width, radius, extend):

    if not extend: extend = 0.001
    curve_surface = rs.AddPlanarSrf(curve)
    if not curve_surface:
        exp_curves = rs.ExplodeCurves(curve)
        curve_surface = rs.AddEdgeSrf(exp_curves)
        rs.DeleteObjects(exp_curves)
        print("Surface problem")


#         circle = rs.AddCircle(rs.CurveAreaCentroid(curve)[0],10000)
#         planar_surface = rs.AddPlanarSrf(circle)
#         projected_curve = rs.ProjectCurveToSurface(curve,planar_surface,(0,0,-1))
#         if not projected_curve: rs.ProjectCurveToSurface(curve,planar_surface,(0,0,1))
#         if not projected_curve: print "noooooo"
#         curve_surface = rs.AddPlanarSrf(projected_curve)
#         rs.DeleteObjects([circle,planar_surface,curve])
#         curve = rs.JoinCurves(rs.DuplicateEdgeCurves(curve_surface, select=False))
#         if not curve_surface: print "WARNING"

    main_point_param = rs.CurveClosestPoint(curve, point)
    curve_normal = rs.CurveNormal(curve)
    curve_plane = rs.CurvePlane(curve)
    tangent = rs.CurveTangent(curve, main_point_param)
    center_curve = rs.AddLine((0, 0, 0), rs.VectorScale(tangent, length))
    rs.RotateObject(center_curve, (0, 0, 0), 90, curve_normal)
    rs.MoveObject(center_curve, rs.VectorCreate(point, (0, 0, 0)))
    if not rs.IsPointOnSurface(curve_surface, rs.CurveEndPoint(center_curve)):
        rs.RotateObject(center_curve, point, 180, curve_normal)
    normal = rs.VectorScale(tangent, 10000)
    normal_inverted = rs.VectorReverse(normal)
    side_curve = rs.OffsetCurveOnSurface(center_curve, curve_surface,
                                         width / 2)
    if not side_curve:
        side_curve = rs.OffsetCurveOnSurface(center_curve, curve_surface,
                                             -width / 2)
    side_curves = [
        side_curve,
        rs.RotateObject(
            side_curve, rs.CurveMidPoint(center_curve), 180,
            rs.VectorCreate(rs.CurveStartPoint(center_curve),
                            rs.CurveEndPoint(center_curve)), True)
    ]
    #side_curves = [side_curve,rs.MirrorObject(side_curve,rs.CurveStartPoint(center_curve),rs.CurveEndPoint(center_curve), True)]
    #side_curves = [rs.OffsetCurveOnSurface(center_curve,curve_surface, width/2),rs.OffsetCurveOnSurface(center_curve,curve_surface, -width/2)]
    for side_curve in side_curves:
        rs.ExtendCurveLength(side_curve, 0, 0, 2)
        rs.ObjectColor(side_curve, (255, 0, 0))
    perimeter_curve = rs.AddCurve([
        rs.CurveStartPoint(side_curves[0]),
        rs.CurveEndPoint(side_curves[0]),
        rs.CurveEndPoint(side_curves[1]),
        rs.CurveStartPoint(side_curves[1]),
        rs.CurveStartPoint(side_curves[0])
    ], 1)
    inside_curve = rs.OffsetCurve(perimeter_curve,
                                  rs.CurveAreaCentroid(perimeter_curve)[0],
                                  radius * .7)
    external_curve = rs.OffsetCurve(perimeter_curve,
                                    rs.CurveAreaCentroid(perimeter_curve)[0],
                                    -extend)

    e_points = [
        rs.CurvePoints(external_curve)[0],
        rs.CurvePoints(external_curve)[3]
    ]
    e_perimeter_curve = rs.AddCurve([
        rs.CurveEndPoint(side_curves[1]),
        rs.CurveEndPoint(side_curves[0]), e_points[0], e_points[1],
        rs.CurveEndPoint(side_curves[1])
    ], 1)

    center_plane_a = rs.PlaneFromPoints(
        rs.CurvePoints(inside_curve)[2],
        rs.CurvePoints(inside_curve)[1],
        rs.CurvePoints(inside_curve)[3])
    center_plane_b = rs.PlaneFromPoints(
        rs.CurvePoints(inside_curve)[1],
        rs.CurvePoints(inside_curve)[0],
        rs.CurvePoints(inside_curve)[2])

    circles = [
        rs.AddCircle(center_plane_a, radius + RADIUS_TOLERANCE),
        rs.AddCircle(center_plane_b, radius + RADIUS_TOLERANCE)
    ]

    bone_curve = rs.CurveBooleanUnion(
        [e_perimeter_curve] +
        circles) if extend else rs.CurveBooleanUnion([perimeter_curve] +
                                                     circles)
    rs.DeleteObjects([
        inside_curve, center_curve, perimeter_curve, curve_surface,
        e_perimeter_curve, external_curve
    ] + side_curves + circles)
    return bone_curve