Oops, your profile's looking a bit empty! To help us tailor your experience, please fill in key details like your SketchUp version, skill level, operating system, and more. Update and save your info on your profile page today!
π£οΈ Road Profile Builder | Generate roads, curbs and pavements easily Download
I have a trouble in the code,and need help.thanks!
-
require'sketchup.rb' class Model def create_model UI.messagebox('The number of the building less than 6!') prompts=["length of land","width of land","The number of building","building length","building width","building height","Spacing"] input=UI.inputbox prompts,"Create model" lengthl,widthl,number,blength,bwidth,bheight,spacing=input amount=0 model=Sketchup.active_model entities=model.entities if(amount>6) then UI.messagebox('The number of the building more than 6!') pt1=[0,0,0] pt2=[0+bwidth,0,0] pt3=[0+blength,0+bwidth,0] pt4=[0,0+blength,0] new_face=entities.add_face pt1,pt2,pt3,pt4 new_face.pushupull bheight end end UI.menu("Plugins").add_item("creat_model"){ object=Model.new() object.create_model }I want to Creat Geometry by the code,but I can't find out where the error.
-
I wouldn't mess with the Model class... make it a simple tool... Here's a reworked version... ### marks changes - several small errors and a typo !!!
require 'sketchup.rb' def create_model()### ###UI.messagebox('The number of the building less than 6!') ### why here ? ### set up some starting defaults - change as you want... @lengthl=100.m if not @length1 @widthl=50.m if not @widthl @number=4 if not @number @blength=10.m if not @blength @bwidth=5.m if not @bwidth @bheight=5.m if not @bheight @spacing=5.m if not @spacing prompts=["Length of Land; ","Width of Land; ","The Number of Building; ","Building Length; ","Building Width; ","Building Height; ","Building Spacing; "]### defaults=[@lengthl,@widthl,@number,@blength,@bwidth,@bheight,@spacing] input=UI.inputbox(prompts,defaults,[],"Create Model") ### note extra items return nil if not input ### @lengthl,@widthl,@number,@blength,@bwidth,@bheight,@spacing=input ### amount=@number ### ??? model=Sketchup.active_model entities=model.active_entities ### if amount>6 UI.messagebox('The number of building is more than 6 !')### why ??? else model.start_operation("Create Model")### for the 'undo' x=0;y=0 ### also don't muddle the width/height !!! amount.times{|i| pt1=[x,y,0]### pt2=[x+@bwidth,y,0]### pt3=[x+@bwidth,y+@blength,0]### pt4=[x,y+@blength,0]### new_face=entities.add_face(pt1,pt2,pt3,pt4) new_face.pushpull(-@bheight) ### pushUpull typo !!! -ve = pull up as the face is reversed... x=x+@bwidth+@spacing ### set in a line ### you can mess on with x & y spacings and number of buildings etc... ### presumably you'll also use the 'Land' sizes somewhere ? } ### model.commit_operation ### end#if ### end#def ### if not file_loaded?(File.basename(__FILE__)) ### so only get menu item once... UI.menu("Plugins").add_item("Create Model"){create_model} ### end#if ### file_loaded(File.basename(__FILE__)) ### -
Thank you very much!It is greate help to me!

Advertisement