Esempio n. 1
0
def getStatus(c_1, c_2):
    # 0:ちょうどいい距離なのでそのまま
    # 1:遠すぎる
    # 2:近すぎる

    if rs.IsCircle(c_1) and rs.IsCircle(c_2):
        radius_1 = rs.CircleRadius(c_1)
        radius_2 = rs.CircleRadius(c_2)

        #print(radius_1)
        #print(radius_2)

        pt_1 = rs.CircleCenterPoint(c_1)
        pt_2 = rs.CircleCenterPoint(c_2)

        #print(pt_1)
        #print(pt_2)

    #追加スクリプト↓
    dis_1_2 = rs.Distance(pt_1, pt_2)
    #print(dis_1_2)
    #追加スクリプト↑

    if (dis_1_2 == radius_1 + radius_2):
        status = 0
    if (radius_1 + radius_2 < dis_1_2):
        status = 1
    if (dis_1_2 < radius_1 + radius_2):
        status = 2

    return status  #returnで「数値」を返している。
Esempio n. 2
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. 3
0
        def FromEdgetoPlane():
            PointPlane = []
            CurveIdList = []
            Brep = []
            edges = rs.GetEdgeCurves()
            if edges:
                for edgeinfo in edges:

                    Brep.append(edgeinfo[1])
                    CurveIdList.append(edgeinfo[0])

            for CurveId in CurveIdList:

                if rs.IsCircle(CurveId):

                    Pt = rs.CircleCenterPoint(CurveId)
                    Normal = rs.CurveNormal(CurveId)
                    LenghtNormal = rs.VectorLength(Normal)
                    LenghNormal = self.m_foronumero.Text
                    LenghNormal = int(LenghNormal)
                    Normal = (LenghNormal * Normal[0], LenghNormal * Normal[1],
                              LenghNormal * Normal[2])
                    PtStill = rs.AddPoint(Pt)

                    Ptmoved = rs.MoveObject(Pt, Normal)
                    Ptmoved = rs.coerce3dpoint(Ptmoved)
                    PtStill = rs.coerce3dpoint(PtStill)

                    PointPlane.append([
                        PtStill[0], PtStill[1], PtStill[2], Normal[0],
                        Normal[1], Normal[2]
                    ])
                    #PointPlane.append([Ptmoved[0],Ptmoved[1],Ptmoved[2],Normal[0],Normal[1],Normal[2]])
            return (PointPlane, Brep)
    def getStatus(self, y_c_i):
        #TODO:getDistanse関数を使う
        if rs.IsCircle(self.circle_obj) and rs.IsCircle(y_c_i.circle_obj):
            radius_1 = rs.CircleRadius(self.circle_obj)
            radius_2 = rs.CircleRadius(y_c_i.circle_obj)

        m_p = rs.CircleCenterPoint(self.circle_obj)
        y_p = rs.CircleCenterPoint(y_c_i.circle_obj)
        dis_1_2 = rs.Distance(m_p, y_p)

        if (dis_1_2 == radius_1 + radius_2):
            status = 0
        if (radius_1 + radius_2 < dis_1_2):
            status = 1
        if (dis_1_2 < radius_1 + radius_2):
            status = 2
        return status
Esempio n. 5
0
def ExportLighthouseSensorsToJSON(filename):
    print "Writing", filename

    #objectIds = rs.GetObjects("Select Sensors",rs.filter.curves,True,True)
    #if( objectIds==None ): return3

    # Find all circle and all lines in scene
    circles = []
    lines = []
    for obj in rs.AllObjects():
        # Skip hidden objects, and invisible layers
        # TODO: Recuse up layet hierarchy?
        if rs.IsObjectHidden(obj):
            continue
        layer = rs.ObjectLayer(obj)
        if layer and not rs.IsLayerVisible(layer):
            continue

        if rs.IsCurve(obj):
            if rs.IsCircle(obj):
                circles.append((obj, rs.CircleCenterPoint(obj)))
            elif rs.IsLine(obj):
                verts = rs.PolylineVertices(obj)
                if len(verts) == 2:
                    lines.append((obj, verts))

    print 'found', len(circles), 'sensor candidates (circles) in scene'
    print 'found', len(lines), 'sensor candidates (normals) in scene'

    modelJSON = {'modelNormals': [], 'modelPoints': []}

    # TODO: Better sort order? Perhaps based on winding around origin?
    for circleObj, circleCenter in reversed(circles):
        for line, lineVerts in lines:
            pos, normal = GetSensorPosAndNormal(circleCenter, lineVerts)
            if pos is None:
                continue
            else:
                modelJSON['modelNormals'].append([float(x) for x in normal])
                modelJSON['modelPoints'].append(
                    [float(x) / 1000.0 for x in pos])
                break
    modelJSON['channelMap'] = range(len(modelJSON['modelNormals']))

    print "Extracted", len(modelJSON['channelMap']), "sensors"

    if len(modelJSON['modelNormals']) > 0:
        outputFile = file(filename, 'w')
        jsonText = json.dumps(modelJSON, indent=4, sort_keys=True)
        outputFile.write(jsonText)
        outputFile.close()

        print "Wrote", filename
    else:
        print "Error: No sensors found in scene"
Esempio n. 6
0
    def SetPlanarCurve(self, type="Any", guid=None):
        if (type == "Any"): prompt = "Select a planar pitch curve"
        elif (type == "Circle"): prompt = "Select the pitch circle"

        newCurve = rs.GetCurveObject(prompt, True,
                                     True) if guid is None else [guid]
        if (newCurve is None):
            Rhino.RhinoApp.WriteLine("Exit: No curve was selected")
            return False
        isPlanar = rs.IsCurvePlanar(newCurve[0])
        if (isPlanar == False):
            newCurve = None
            Rhino.RhinoApp.WriteLine("Exit: Selected curve was not planar")
            return False

        self.curve = newCurve  #Accept the curve into the object because the curve exists and it is planar
        self.isClosed = rs.IsCurveClosed(self.curve[0])
        self.normal = rs.CurveNormal(
            self.curve[0])  #For non planar curves the script already exited.

        self.isCircle = rs.IsCircle(self.curve[0])
        if (type == "Circle" and self.isCircle != True):
            Rhino.RhinoApp.WriteLine("Exit: Selected curve was not a circle")
            return False

        self.crvLen = rs.CurveLength(self.curve[0])
        if (self.isCircle == True):
            Rhino.RhinoApp.WriteLine("Selected: Circle")
            self.origin = rs.CircleCenterPoint(self.curve[0])
            self.plane = rs.PlaneFromNormal(
                self.origin, self.normal,
                rs.CurveStartPoint(self.curve[0]) -
                self.origin)  #PlaneFromNormal(origin, normal, xaxis=None)
            self.SetPD()  #Propagate the value updates
            self.SetBC()  #Propagate the value updates
            return
        if (self.isClosed == True):
            Rhino.RhinoApp.WriteLine(
                "Selected: Closed non-circular planar curve")
            return
        else:
            Rhino.RhinoApp.WriteLine("Selected: Open planar curve")
Esempio n. 7
0
def FromEdgetoPlane():
    PointPlane = []
    CurveIdList = []
    Brep = []
    edges = rs.GetEdgeCurves()
    if edges:
        for edgeinfo in edges:
            Brep.append(edgeinfo[1])
            CurveIdList.append(edgeinfo[0])


#    print CurveIdList
    for CurveId in CurveIdList:

        if rs.IsCircle(CurveId):
            #            print "Sono un cerchio"
            Pt = rs.CircleCenterPoint(CurveId)
            Normal = rs.CurveNormal(CurveId)
            LenghtNormal = rs.VectorLength(Normal)
            LenghNormal = rs.GetString("give me the lengh of the hole", "100")
            LenghNormal = int(LenghNormal)
            Normal = (LenghNormal * Normal[0], LenghNormal * Normal[1],
                      LenghNormal * Normal[2])
            print Normal
            PtStill = rs.AddPoint(Pt)
            Ptmoved = rs.MoveObject(Pt, Normal)
            Ptmoved = rs.coerce3dpoint(Ptmoved)
            PtStill = rs.coerce3dpoint(PtStill)
            #            print Ptmoved
            #            print PtStill

            PointPlane.append([
                PtStill[0], PtStill[1], PtStill[2], Normal[0], Normal[1],
                Normal[2]
            ])
            #PointPlane.append([Ptmoved[0],Ptmoved[1],Ptmoved[2],Normal[0],Normal[1],Normal[2]])
    return (PointPlane, Brep)