Change variable after certain number of loops
-
@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
-
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
-
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.
-
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`
-
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 -
@davesexcel said:
Just a side note, is there a "clear All" code that can run at the beginning of this code?
for exampleclear_all#< clears everything on the screen.
In SU2014 and up: just type
cls
-
@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.entitiesThanks,
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. -
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... -
Right on thanks.
-
@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..
Advertisement