sketchucation logo sketchucation
    • Login
    ℹ️ Licensed Extensions | FredoBatch, ElevationProfile, FredoSketch, LayOps, MatSim and Pic2Shape will require license from Sept 1st More Info

    Change variable after certain number of loops

    Scheduled Pinned Locked Moved Developers' Forum
    14 Posts 5 Posters 652 Views 5 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • sdmitchS Offline
      sdmitch
      last edited by

      @davesexcel said:

      @sdmitch said:

      Did you mean when i=e? Because i is never going to equal d(rise).

      Yep, you are correct,
      I wonder if it might be easier to find the back face and pushpull it e-(e-0.5)
      How do you pushpull the back face only?

      I'm not sure which one is the "back" face is but you just need face criteria that only matches the one of interest. Like in the case of the edges to be softened, they had to be of length "a".

      By the way, e-(e-0.5) = 0.5.

      Nothing is worthless, it can always be used as a bad example.

      http://sdmitch.blogspot.com/

      1 Reply Last reply Reply Quote 0
      • D Offline
        davesexcel
        last edited by

        @sdmitch said:

        By the way, e-(e-0.5) = 0.5.

        Oh ya, I guess it would be e-0.5 so it would have to be pushpulled -(e-0.5)

        I keep getting pushpull stuck in the head.

        What I am looking for is on the last loop make b=0.5

        Thanks

        I have tried adding k into the mix mix with no success, now b is 0.5 on all the loops.

            prompts = ["length", "Run","height","Rise","Total Rises"]
            defaults = [36.0,10.0,1.0,7.75,7]
            input = UI.inputbox prompts, defaults, "Tread."
        
        
            
                a,b,c,d,e=input
        
                k = 0 #<<--- start k=0
                ent = Sketchup.active_model.entities
                for i in 0..e-1
                if k=e-1 then #<<<----if k=e-1
                b = 0.5
                end#<<<---
                ent.add_line [0,(b+1)+i*b,0+i*d-1], [0,(1.5+i*b),0+i*d-1]
                ent.add_line [0,1.5+i*b,0+i*d-1], [0,1.5+i*b,-d+(i*d)-1]
                ent.add_line [0,1+i*b,0+i*d-1], [0,1+i*b,-d+(i*d)-1]
                ent.add_line [0,1+i*b,-d+(i*d)-1], [0,1.5+i*b,-d+(i*d)-1]
                edg = ent.add_line [0,1+i*b,-1+i*d],[0,0.5+i*b,-1+i*d];vrt1=edg.end#<-----
                ent.add_arc [0,0.5+i*b,-c/2.0+(i*d)],[0,0,-1],[-1,0,0],c/2.0,0,180.degrees,20
                edg = ent.add_line [0,0.5+i*b,0+i*d],[0,b+(i*b)+1,0+i*d];vrt2=edg.start#<----_
                edg=ent.add_line [0,b+1+i*b,-c+i*d],[0,b+1+i*b,0+i*d]
                edg.find_faces; face=edg.faces[0]
        
             
                face.pushpull -a
                edgs=vrt1.edges.reject!{|e| e.length<a};edgs[0].soft=true#<-----
                edgs=vrt2.edges.reject!{|e| e.length<a};edgs[0].soft=true#<-----
                    #group1 = ent.add_group face.all_connected
                k=k+1#<<---add 1 to k
        end
          
        
        
        
        1 Reply Last reply Reply Quote 0
        • D Offline
          davesexcel
          last edited by

          Alright I can get the b=0.5 on the last loop but can't get it to the correct location, because I changed b to 0.5 !!!.

              prompts = ["length", "Run","height","Rise","Total Rises"]
              defaults = [36.0,10.0,1.0,7.75,7]
              input = UI.inputbox prompts, defaults, "Tread."
              
                  a,b,c,d,e=input
          
                  k = 0 #<<--- start k=0
                  ent = Sketchup.active_model.entities
                  for i in 0..e-1
                  if k>e-2 then #<<<----if k=e-1
                  b = 0.5
                  end#<<<---
          		k=k+1
                  ent.add_line [0,(b+1)+i*b,0+i*d-1], [0,(1.5+i*b),0+i*d-1]  
                  ent.add_line [0,1.5+i*b,0+i*d-1], [0,1.5+i*b,-d+(i*d)-1]
                  ent.add_line [0,1+i*b,0+i*d-1], [0,1+i*b,-d+(i*d)-1]
                  ent.add_line [0,1+i*b,-d+(i*d)-1], [0,1.5+i*b,-d+(i*d)-1]
                  edg = ent.add_line [0,1+i*b,-1+i*d],[0,0.5+i*b,-1+i*d];vrt1=edg.end
                  ent.add_arc [0,0.5+i*b,-c/2.0+(i*d)],[0,0,-1],[-1,0,0],c/2.0,0,180.degrees,12
                  edg = ent.add_line [0,0.5+i*b,0+i*d],[0,b+(i*b)+1,0+i*d];vrt2=edg.start
                  edg=ent.add_line [0,b+1+i*b,-c+i*d],[0,b+1+i*b,0+i*d]
                  edg.find_faces; face=edg.faces[0]
          
               
                  face.pushpull -a
                  edgs=vrt1.edges.reject!{|e| e.length<a};edgs[0].soft=true
                  edgs=vrt2.edges.reject!{|e| e.length<a};edgs[0].soft=true
                      #group1 = ent.add_group face.all_connected
                  
          end
            
          
          
          1 Reply Last reply Reply Quote 0
          • sdmitchS Offline
            sdmitch
            last edited by

            Two things.

            The if k=e-1 failed because the proper syntax is if k==e-1.

            Because you use a multiple of b to define the location, changing it for the last one requires a different formula. Shorten the For loop to e-2 and copy and modify the code in the loop to create the last step with b=0.5.

            Nothing is worthless, it can always be used as a bad example.

            http://sdmitch.blogspot.com/

            1 Reply Last reply Reply Quote 0
            • D Offline
              davesexcel
              last edited by

              Excellent, thanks for the suggestion...it worked.

              Just a side note, is there a "clear All" code that can run at the beginning of this code?
              for example

              ` clear_all#< clears everything on the screen.

              prompts = ["length", "width","height","Rise"]
              defaults = [36.0,10.0,1.0,7.75]
              input = UI.inputbox prompts, defaults, "Tread."

              if input == false
              UI.messagebox("All Must Be Entered")
              else
              a,b,c=input
              #UI.messagebox("Tread input accepted!, #{input}!")
              end
              
              ent = Sketchup.active_model.entities
              ent.add_line [0,b-c/2,0],[0,0,0]
              ent.add_arc [0,0,c/2.0],[0,0,-1],[-1,0,0],c/2.0,0,180.degrees,20
              ent.add_line [0,0,c],[0,b-c/2,c]
              edg=ent.add_line [0,b-c/2,c],[0,b-c/2,0]
              edg.find_faces; face=edg.faces[0]
              #face = ent.add_face [0,0,0], [a,0,0], [a,b,0], [0,b,0]
              #face.reverse!
              face.pushpull -a`
              
              1 Reply Last reply Reply Quote 0
              • jolranJ Offline
                jolran
                last edited by

                One idea is starting using groups to organize your geometry.
                Clearing everything on the screen, sounds like a dangerous approach to me.
                Just a simple tip..

                ents = Sketchup.active_model.entities
                gp = ents.add_group
                ent = gp.entities

                1 Reply Last reply Reply Quote 0
                • tt_suT Offline
                  tt_su
                  last edited by

                  @davesexcel said:

                  Just a side note, is there a "clear All" code that can run at the beginning of this code?
                  for example

                  clear_all#< clears everything on the screen.

                  In SU2014 and up: just type cls

                  1 Reply Last reply Reply Quote 0
                  • D Offline
                    davesexcel
                    last edited by

                    @jolran said:

                    One idea is starting using groups to organize your geometry.
                    Clearing everything on the screen, sounds like a dangerous approach to me.
                    Just a simple tip..

                    ents = Sketchup.active_model.entities
                    gp = ents.add_group
                    ent = gp.entities

                    Thanks,
                    I'm just trying to find a way not to have to keep pressing 'Ctrl & "A" then delete, every time I want to test a code.

                    1 Reply Last reply Reply Quote 0
                    • D Offline
                      driven
                      last edited by

                      for testingyour code you can use

                      Sketchup.active_model.entities.clear!
                      

                      but have another look at TT's notes and the API at wrapping your code in a Start Operation...
                      then use your Undo shortcut...

                      learn from the mistakes of others, you may not live long enough to make them all yourself...

                      1 Reply Last reply Reply Quote 0
                      • D Offline
                        davesexcel
                        last edited by

                        Right on thanks.

                        1 Reply Last reply Reply Quote 0
                        • jolranJ Offline
                          jolran
                          last edited by

                          @unknownuser said:

                          Thanks,
                          I'm just trying to find a way not to have to keep pressing 'Ctrl & "A" then delete, every time I want to test a code.

                          Ah, right! Understood.

                          Well TT and Driven got the answers already.

                          Another handy plugin is using Alex Ruby-code editor.
                          You don't have to wrap code in Start Operation cause there's an inbuilt Play and Undo button. Very useful for testing loose code snippets. Copy and paste from Notepad for ex..

                          1 Reply Last reply Reply Quote 0
                          • 1 / 1
                          • First post
                            Last post
                          Buy SketchPlus
                          Buy SUbD
                          Buy WrapR
                          Buy eBook
                          Buy Modelur
                          Buy Vertex Tools
                          Buy SketchCuisine
                          Buy FormFonts

                          Advertisement