Resolve [Ruby help] Script for create window sills

Resolve [Ruby help] Script for create window sills

Postby benj59380 » Fri Nov 08, 2019 2:04 pm

Hello , Today I wanted Creat script for window sills

my approach is create face manuel
click for select

run script
( part 1 : select face , creat color , Push -30 mm
Part 2 : select vertical face for push +30)

Part 1 work , but Part 2 fail :(

But Ruby = SyntaxError help me please for resolve the problem ;)
thank you in advance , Benjamin


#part 1
model = Sketchup.active_model
ent = model.entities
sel = model.selection
ad = sel.ent

faces = []

sel.each do |e|
faces <<e if e.is_a? Sketchup::Face
end

faces.each do |appui|

appuicolor = Sketchup::Color.new(238,130,238)
appui.material = appuicolor
appui.back_material = appuicolor

status = appui.pushpull(-30.mm , true)

end
#part 2

ad.each do |e|

s=Sketchup.active_model.selection;
a=s.to_a;s.clear;
a.grep(Sketchup::Face).each{|f|s.add(f)if f.normal.z==0}

faces.each do |facade|

status = facade.pushpull(30.mm )


end
0
Last edited by benj59380 on Tue Nov 12, 2019 9:06 am, edited 1 time in total.

benj59380 
 

Re: [Ruby help] Script for create window sills

Postby sdmitch » Sat Nov 09, 2019 7:40 pm

Part 1 works if you delete or comment out the ad=sel.ent statement which is invalid.

Part 2 doesn't work because the faces created by the pushpull operation are not automatically added to the selection. Also you reuse the faces array which only contains the original faces selected.

Here is how I would do it
Code: Select all
mod = Sketchup.active_model
ent = mod.active_entities
sel = mod.selection
SKETCHUP_CONSOLE.clear
appuicolor = Sketchup::Color.new(238,130,238)
sel.grep(Sketchup::Face).each do |appui|
  appui.material = appuicolor
  appui.back_material = appuicolor
  old = ent.to_a
  status = appui.pushpull(-30.mm , true)
  new = ent.to_a - old
  new.grep(Sketchup::Face).select{|f|f.normal.z==0}.each{|f|f.pushpull 30.mm}
end
0
Nothing is worthless, it can always be used as a bad example.

http://sdmitch.blogspot.com/
User avatar
sdmitch 
PluginStore Author
PluginStore Author
 

Re: [Ruby help] Script for create window sills

Postby benj59380 » Tue Nov 12, 2019 8:27 am

hello , Thank you SDMITCH for help ;)

cordially Benj
0

benj59380 
 

SketchUcation One-Liner Adverts

by Ad Machine » 5 minutes ago



Ad Machine 
Robot
 



 

Return to Developers' Forum

Who is online

Users browsing this forum: aksh13, satinka and 6 guests

Visit our sponsors: