🍰
Grasshopper ES por BetweenRealities
  • Using and Generating Documentation
    • GitHub
    • Discord
      • Speckle Webhooks
    • Speckle Client
  • Potencial technological implementations
  • 🧞Compute
    • Introducción a Grasshopper
      • Customizar Entorno
        • VSCode
      • Rhinoceros 3d
      • Hops
      • Galapagos
    • Modelos Informados
      • Comportamiento Estructural
        • Automatizar cálculo Python
      • OOP
      • Rhino Inside Revit
        • Revit
          • Modelado 3d en Revit
          • Certificación profesional Revit
      • Energía
    • Procesos Urbanos
      • Automatizar Qgis
      • Librerías Python
      • Librerías Grasshopper
      • Stable Diffusion
    • Programación
      • RhinoPython
        • Anatomía del script
        • Python básico
        • Tuples, listas y diccionarios
        • Operadores y funciones
        • Ejecución condicional
        • Geometría
        • Clases
      • Multithread
  • 🪅Database
    • Lenguaje Python
      • Types and operations
      • Statements and syntax
      • Function and generators
      • Modules and packages
      • Classes and OPP
      • Exception and tools
      • Advance topics
    • Análisis de la Información
      • Comparison with SQL
      • Comparison with R / R libraries
      • Pandas
    • Abrir Acceso
      • Rest API Abierta
    • Blockchain Descentralización
  • 🕸️COLLECT
    • Captura de Datos
      • Raspberry Pi
        • Encendido y apagado automático
      • Arduino
      • UAS
      • Fotogrametría
        • Crashes
    • Técnicas Machine Learning
      • Clasificación
      • Computer Vision
    • Computación en la Nube
      • Contenedores
      • Azure
      • Ubuntu Server Deploy
      • PostgreSQL Server
      • Rhino Compute Deploy
  • 🍭INTERACT
    • Introducción a Unreal Engine
      • Ejecutar Python
      • Datasmith
      • Materiales
        • Crear PBR
        • Materiales Introducción
      • Iluminación
        • Iluminación Introducción
        • Raytraced Iluminación Cinemática
      • Assets Management
    • Interacción Inmersiva
      • Blueprints
        • Blueprints estandar
        • Blueprints Introducción
        • Diseño Nivel
      • Packaging
      • Performance
    • Interfaces Bidimensionales
Con tecnología de GitBook
En esta página

¿Te fue útil?

  1. Compute
  2. Programación
  3. RhinoPython

Ejecución condicional

Conditional execution

  • if: what if questions for varying complexities. Nested conditions. A good way to solve nesting conditions is iterate (if, elif, else).

  

        dblCurveLength = rs.CurveLength(strObjectID)

                if (dblCurveLength != None):

                        if (dblCurveLength < rs.UnitAbsoluteTolerance()):

                                rs.DeleteObject(strObjectID)

                        elif (dblCurveLength < (10 * rs.UnitAbsoluteTolerance())):

                                rs.SelectObject(strObjectID)

                        else:

                                rs.UnselectObject(strObjectID)
  • looping: conditional looping keep repeating until some condition is met. Incremental loops will run a predefined number of times. (there are more). Conditional looping 'do...loop' if we don't abort the loop, omit the break statement or the condition never happen the loop will continue forever. Incremental loops when the number of iterations is known in advance (item in group or range)

  

        ## Conditional looping

        import rhinoscriptsyntax as rs

        import datetime as dt

  

        def viewportclock():

                now = dt.datetime.now()

                textobject_id = rs.AddText(str(now), (0,0,0), 20)

                if textobject_id is None: return                        # cast operation for a datetime object is a well known and solid operation, we do not have to check for a Null variable and we can put it 'inline'

                rs.ZoomExtents(None, True)

                while True:

                        rs.Sleep(1000)

                        now = dt.datetime.now()

                        rs.TextObjectText(textobject_id, str(now))

  

        if __name__=="__main__":

                viewportclock() # function is called. Python files can act as either reusable modules or a standalone programs

  
  

        import rhinoscriptsyntax as rs

        # Iteratively scale down a curve until it becomes shorter than a certain length

  

        def fitcurvetolength():

                curve_id = rs.GetObject("Select a curve to fit to length", rs.filter.curve, True, True)

                if curve_id is None: return

                length = rs.CurveLength(curve_id)

                length_limit = rs.GetReal("Length limit", 0.5 * length, 0.01 * length, length)

                if length_limit is None: return

                while True:

                        if rs.CurveLength(curve_id)<=length_limit: break

                        curve_id = rs.ScaleObject(curve_id, (0,0,0), (0.95, 0.95, 0.95))

                        if curve_id is None:

                                print "Something went wrong..."

                                return

                print "New curve length: ", rs.CurveLength(curve_id)

  

        if __name__=="__main__":

                fitcurvetolength()

  
  

        # Incremental looping

        import math

        import rhinoscriptsyntax as rs

  

        pi = math.Pi()

        dblTwistAngle = 0.0

  

        rs.EnableRedraw(False)

        for z in rs.frange(0.0, 5.0, 0.5):

                dblTwistAngle = dblTwistAngle + (pi/30)

                for a in rs.frange(0.0, 2*pi, (pi/15)):

                        x = 5 * math.sin(a + dblTwistAngle)

                        y = 5 * math.cos(a + dblTwistAngle)

                        rs.AddSphere([x,y,z], 0.5)

  

        rs.EnableRedraw(True)
AnteriorOperadores y funcionesSiguienteGeometría

Última actualización hace 2 años

¿Te fue útil?

🧞