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

    I have a trouble in the code,and need help.thanks!

    Scheduled Pinned Locked Moved Developers' Forum
    3 Posts 2 Posters 151 Views 2 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.
    • W Offline
      winzard
      last edited by

      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.

      1 Reply Last reply Reply Quote 0
      • TIGT Offline
        TIG Moderator
        last edited by

        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__)) ###
        

        TIG

        1 Reply Last reply Reply Quote 0
        • W Offline
          winzard
          last edited by

          Thank you very much!It is greate help to me! 👍

          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