Forgot password?

Create an account!

Forum

« back

RhinoScript – 1st rhino script

Messages

Please log in to write a message.

  • 12. skippy (Sep 24, 2013 19.16):

    thx a lot, I swap to grasshopper it's a wonderfull tool where I can use a parametric inputs to generate perfectly my projection system and my screens.
    great thanks for your help.
    Seb

  • 11. pulgarata (Sep 11, 2013 20.59):

    I would do it this way.
    1.To join surfaces and name the object

               
            Dim sup(4),SrfJoin
            sup(0) = Rhino.AddSrfPt(superficie1)
            sup(1) = Rhino.AddSrfPt(superficie2)
            sup(2) = Rhino.AddSrfPt(superficie3)
            sup(3) = Rhino.AddSrfPt(superficie4)
            sup(4) = Rhino.AddSrfPt(superficie5)
           
            SrfJoin = Rhino.JoinSurfaces(sup, True)
           
            Rhino.ObjectName SrfJoin, "Proyector"


    2.To naming the imported objects:

           Rhino.Command "_Import C:\rhino_object\F12.3dm"
            Dim ObjetoImportado
            ObjetoImportado = Rhino.FirstObject
            Rhino.ObjectName ObjetoImportado, "ObjetoImportado"

    3.Then play in rhino (move, rotate, etc) and To intersect the objects make a new script

            Proyector=Rhino.ObjectsByName ("Proyector")
            ObjetoImportado=Rhino.ObjectsByName ("ObjetoImportado")
            'or screen=Rhino.ObjectsByName ("Screen")...
            Rhino.IntersectBreps Proyector, ObjetoImportado

    if you want more interactivity, you should try with "grasshopper"

  • 10. skippy (Sep 11, 2013 19.04):

    Thx but I had the same pb,
    by the way I change my method and use an excel spreed sheet. it works pretty well

    Option Explicit
    'Script written by <insert name>
    'Script copyrighted by <insert company name>
    'Script version mardi 10 septembre 2013 10:31:17

    Call Main()

    Sub Main()
           
            drawPyramid

           
    End Sub

    Sub drawPyramid

            Dim FileName, file, excel
            FileName = Rhino.OpenFileName("Select Excel File", "Excel Files (*.xls)|*.xls||")
            If isNull(FileName) Then Exit Sub

            Set excel = CreateObject("Excel.Application")
            excel.Visible = True
            excel.Workbooks.Open(FileName)
            Set file = excel.ActiveSheet

            Dim proj:proj = file.Cells(3, 3).Value
            Dim ratioH:ratioH = file.Cells(3, 4).Value
            Dim ratioV:ratioV = file.Cells(4, 4).Value
            Dim lens:lens = file.Cells(8, 3).Value
            Dim verticalShift:verticalShift = file.Cells(8, 4).Value
            Dim horizontalShift:horizontalShift = file.Cells(9, 4).Value
            Dim screenHeight:screenHeight = file.Cells(6, 3).Value

            excel.UserControl = True
                   
            Dim pt(4), kRatio
           
            kRatio = ratioH / ratioV * screenHeight
            pt(0) = Array(0.0, 0.0, 0.0)
            pt(1) = Array(kRatio * horizontalShift / 100, lens * kRatio, screenHeight * (1 - verticalShift / 100))
            pt(2) = Array(kRatio * (horizontalShift / 100 - 1), lens * kRatio, screenHeight * (1 - verticalShift / 100))
            pt(3) = Array(kRatio * (horizontalShift / 100 - 1), lens * kRatio, -screenHeight * verticalShift / 100)
            pt(4) = Array(kRatio * horizontalShift / 100, lens * kRatio, -screenHeight * verticalShift / 100)
                   
            Dim superficie1:superficie1 = Array(pt(0), pt(1), pt(2))
            Dim superficie2:superficie2 = Array(pt(0), pt(2), pt(3))
            Dim superficie3:superficie3 = Array(pt(0), pt(3), pt(4))
            Dim superficie4:superficie4 = Array(pt(0), pt(4), pt(1))
            Dim superficie5:superficie5 = Array(pt(1), pt(2), pt(3), pt(4))
           
            Rhino.AddSrfPt superficie1
            Rhino.AddSrfPt superficie2
            Rhino.AddSrfPt superficie3
            Rhino.AddSrfPt superficie4
            Rhino.AddSrfPt superficie5
                   
            Select Case proj
                    Case "F12"
                            Rhino.Command "_Import C:\rhino_object\F12.3dm"
     
                    Case "F22"
                            Rhino.Command "_Import C:\rhino_object\F22.3dm"
     
                    Case "F32"
                            Rhino.Command "_Import C:\rhino_object\F32.3dm"
                    Case Else
                            Rhino.Command "_Import"
            End Select             

           
    End Sub

    now I created faces, I d like play with, how I can use them
    I d like to make 1 group with all the faces
    I d like to intersect to a screen shape
    etc...
    how I can have a pointer

           Rhino.AddSrfPt superficie1
            Rhino.AddSrfPt superficie2
            Rhino.AddSrfPt superficie3
            Rhino.AddSrfPt superficie4

    same thing to the imported object
    thx
    Seb

  • 9. pulgarata (Sep 11, 2013 13.46):

    Hi Skippy,
    "Rhino.GetOption" get options for users, but does not keep.
    You must save them somehow. Here i save the options as "DocumentData". At the beginning of the "script" i wrote an "if" to take the saved options (if any) or default options.

            Const OPT_SGL = 0
            Const OPT_BLN = 1
            Const OPT_INT = 2
            Const OPT_DBL = 3
            Const OPT_LST = 4
     
            Dim proj, ratioH, ratioV, lens, verticalShift, horizontalShift, screenHeight
            Dim lst, opt, rc, i

            Dim def(6)
           
            If isnull(Rhino.GetDocumentData("Data", "Proj")) Then
                    def(0) = 1
                    def(1) = 16
                    def(2) = 10
                    def(3) = 0.92
                    def(4) = 50
                    def(5) = 50
                    def(6) = 2000
            Else
                   
                    def(0) = Rhino.GetDocumentData("Data", "proj")
                    def(1) = Rhino.GetDocumentData("Data", "ratioH")
                    def(2) = Rhino.GetDocumentData("Data", "ratioV")
                    def(3) = Rhino.GetDocumentData("Data", "lens")
                    def(4) = Rhino.GetDocumentData("Data", "verticalShift")
                    def(5) = Rhino.GetDocumentData("Data", "horizontalShift")
                    def(6) = Rhino.GetDocumentData("Data", "screenHeight")
                   
            End If
           
                   
            lst = Array("F12", "F22", "F32", "Other")
           
            proj = Array(OPT_LST, "Proj", lst, def(0))
            ratioH = Array(OPT_INT, "ratioH", def(1), "New value", 1, 100)
            ratioV = Array(OPT_INT, "ratioV", def(2), "New value", 1, 100)
            lens = Array(OPT_DBL, "lens", def(3), "New value", 0.0, 100.0)
            verticalShift = Array(OPT_INT, "verticalShift", def(4), "New value", 0, 110)
            horizontalShift = Array(OPT_INT, "horizontalShift", def(5), "New value", 0, 100)
            screenHeight = Array(OPT_INT, "screenHeight", def(6), "New value", 1, 10000)

            opt = Array(proj, ratioH, ratioV, lens, verticalShift, horizontalShift, screenHeight)

            rc = Rhino.GetOption("Projector options", opt)
                   
            Rhino.SetDocumentData "Data", "proj", rc(0)
            Rhino.SetDocumentData "Data", "ratioH", rc(1)
            Rhino.SetDocumentData "Data", "ratioV", rc(2)
            Rhino.SetDocumentData "Data", "lens", rc(3)
            Rhino.SetDocumentData "Data", "verticalShift", rc(4)
            Rhino.SetDocumentData "Data", "horizontalShift", rc(5)
            Rhino.SetDocumentData "Data", "screenHeight", rc(6)
           
            If IsArray(rc) Then

                    For Each i In rc
                           
                            Call Rhino.Print(i)

                    Next

            End If

  • 8. skippy (Sep 10, 2013 22.16):

    Hello,
    I moved forward, I add parametric value. but something is wrong because If I change any value there is no effect and I can change only one value each time.

            Const OPT_SGL = 0
            Const OPT_BLN = 1
            Const OPT_INT = 2
            Const OPT_DBL = 3
            Const OPT_LST = 4
     
            Dim proj, ratioH, ratioV, lens, verticalShift, horizontalShift, screenHeight
            Dim lst, opt, rc, i

            lst = Array("F12", "F22", "F32", "Other")
            proj = Array(OPT_LST, "Proj", lst, 1)
            ratioH = Array(OPT_INT, "ratioH", 16, "New value", 1, 100)
            ratioV = Array(OPT_INT, "ratioV", 10, "New value", 1, 100)
            lens = Array(OPT_DBL, "lens", 0.92, "New value", 0.0, 100.0)
            verticalShift = Array(OPT_INT, "verticalShift", 50, "New value", 0, 110)
            horizontalShift = Array(OPT_INT, "horizontalShift", 50, "New value", 0, 100)
            screenHeight = Array(OPT_INT, "screenHeight", 2000, "New value", 1, 10000)


            opt = Array(proj, ratioH, ratioV, lens, verticalShift, horizontalShift, screenHeight)

            rc = Rhino.GetOption("Projector options", opt)

            If IsArray(rc) Then

                    For Each i in rc

                            Call Rhino.Print(i)

                    Next

            End If
  • 7. Hanno (Sep 10, 2013 22.09):

    Hi pulgarata,

    many thanks for your contributions. However, we encourage our users to write in English so that more people can follow the discussions. Thanks for understanding!

    Hanno

  • 6. pulgarata (Sep 10, 2013 18.12):

    A mi me parece perfectamente posible.
    Puedes guardar información (lens, offset) como "Rhino.ObjectData" o "Rhino.DocumentData" para tener feedback entre Rhino y la GUI.
    La GUI la puedes crear con Rhino.htmlBox
    Suerte!

  • 5. skippy (Sep 10, 2013 17.30):

    Thx again,
    Can you tell me if its possible or complexe what I plan to do.
    it's a projection system plugin
    I have to create a gui or to use an xml database where I will fill in all projector, optical specification (lens, offset)
    I will draw a screen and slice the pyramid to the screen
    like the screenshot I made with sketchup

    1st rhino script
  • 4. tos (Sep 10, 2013 15.01):

    Hi.
    I thought another program.

    Call Main()
    Sub Main()
            Dim pt(4)
            pt(0) = Array(0.0, 0.0, 0.0)    'datum point
            pt(1) = Array(-0.5, 0.5, 1.0)
            pt(2) = Array(0.5, 0.5, 1.0)
            pt(3) = Array(0.5, -0.5, 1.0)
            pt(4) = Array(-0.5, -0.5, 1.0)
           
            makeLine(pt)
            makeSrf(pt)
    End Sub

    Sub     makeLine(pts)
            Dim     i
            For i=1 To 4
                    Rhino.AddLine pts(0), pts(i)
                    Rhino.AddLine pts(i), pts((i Mod 4) + 1)
            Next
    End Sub

    Sub     makeSrf(pts)
            Dim     i, corner(2)
            Dim corner2

            corner2 = Array(pts(1), pts(2), pts(3), pts(4))
            Rhino.AddSrfPt corner2

            corner(0) = pts(0)
            For i = 1 To 4
                    corner(1) = pts(i)
                    corner(2) = pts((i Mod 4) + 1)
                    Rhino.AddSrfPt corner
            Next   
    End Sub
  • 3. skippy (Sep 10, 2013 13.56):

    Perfect it works
    great thanks

  • 2. pulgarata (Sep 10, 2013 13.39):

    Hola,
    A mi me funcionó esto:

    Dim pt(4)
            pt(0) = Array(0.0, 0.0, 0.0)
            pt(1) = Array(-0.5, 0.5, 1.0)
            pt(2) = Array(0.5, 0.5, 1.0)
            pt(3) = Array(0.5, -0.5, 1.0)
            pt(4) = Array(-0.5, -0.5, 1.0)
       
            Dim superficie1:superficie1=Array(pt(0),pt(1),pt(2))
            Dim superficie2:superficie2=Array(pt(0),pt(2),pt(3))
            Dim superficie3:superficie3=Array(pt(0),pt(3),pt(4))
            Dim superficie4:superficie4=Array(pt(0),pt(4),pt(1))
            Dim superficie5:superficie5=Array(pt(1),pt(2),pt(3),pt(4))
           
            Rhino.AddSrfPt superficie1
            Rhino.AddSrfPt superficie2
            Rhino.AddSrfPt superficie3
            Rhino.AddSrfPt superficie4
            Rhino.AddSrfPt superficie5

    Saludos,

  • 1. skippy (Sep 10, 2013 11.17):

    Hello,
    Just for introduction, I m working in projection system area.
    couple of years, I dev a plugin for sketchup to be able to design automaticaly a simple system.
    My plugin made the projector pyramid and load the projector shape.
    but I had some limitation.
    I d like to do the same thing with rhino script.
    I m able to draw the pyramid using edge but not surface like I need to intersect later to the screen.
    stupid question how I can draw a surface between 3 points

            Dim pt(3)
            pt(0) = Array(0.0, 0.0, 0.0)
            pt(1) = Array(-0.5, 0.5, 1.0)
            pt(2) = Array(0.5, 0.5, 1.0)
            pt(3) = Array(0.5, -0.5, 1.0)
            pt(4) = Array(-0.5, -0.5, 1.0)
           
            Rhino.AddLine pt(0), pt(1)
            Rhino.AddLine pt(0), pt(2)
            Rhino.AddLine pt(0), pt(3)
            Rhino.AddLine pt(0), pt(4)
            Rhino.AddLine pt(1), pt(2)
            Rhino.AddLine pt(2), pt(3)
            Rhino.AddLine pt(3), pt(4)
            Rhino.AddLine pt(4), pt(1)

    I try to use without sucess
    Rhino.AddSrfPt fonciton.
    any help please
    thx
    best regards
    seb

Recommend

Why are these buttons gray?