sketchucation logo sketchucation
    • Login
    1. Home
    2. michaelazer
    3. Posts
    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
    M
    Offline
    • Profile
    • Following 0
    • Followers 0
    • Topics 3
    • Posts 15
    • Groups 1

    Posts

    Recent Best Controversial
    • RE: Draw shapes in a shape

      @tig said:

      You could pick your points in 3d, so the possibilities could get muddied.

      It's flat, so that's one obstacle out of the way.

      @tig said:

      You need to collect each newly made edge into another array called @edges

      Ok, so instead of connecting points using lines, should I do something like:

       
      edge = Sketchup.active_model.entities.add_line(@pts[@n-1], @pts[@n])
      line = edge.line
      
      

      Sorry to say, but I lost you after that 😒

      posted in Developers' Forum
      M
      michaelazer
    • Draw shapes in a shape

      Hi all, I'm really enjoying this forum. Thanks to all contributors.
      Ok, so I created a line tool that saves the coordinates of each point clicked. Find the code below:

      
      class PVSketch   
      	def activate
      		@model = Sketchup.active_model  
      		@ents = @model.active_entities
      		@view = @model.active_view
      		result = Sketchup.send_action "viewTop;"	
      		@ip = Sketchup;;InputPoint.new
      		@pts = []
      		@n = 0
          end
      
      	def onLButtonUp(flags,x,y,view)
      		@ip.pick(view,x,y)
      		if not @pts[0]
      			@pts << @ip.position
      		else
      			@pts << @ip.position
      			line = @ents.add_line @pts[@n-1], @pts[@n]
      		end
      		if @pts[0] && @ip.position==@pts[0] && @n != 0
      			tools = Sketchup.active_model.tools
      			tool = tools.pop_tool
      		end
      		@n = @n + 1
      	end
      end
      
      click2_cmd = UI;;Command.new("PV Sketch") {
      	Sketchup.active_model.select_tool PVSketch.new
      }
      
      tool_menu = UI.menu "Tools"
      tool_submenu = tool_menu.add_submenu "DrawLine"
      tool_submenu.add_separator
      tool_submenu.add_item click2_cmd
      
      

      It works perfectly, the next step is that I want to automatically fill the shape that the user drew with the maximum amount of rectangles, let's say 24cmx48cm. Can someone help me with that?

      posted in Developers' Forum
      M
      michaelazer
    • RE: Save coordinates in an array

      Thank you so much, Dan. Your tips solved the problem.
      Now, I have the program running, but I don't get the correct coordinates.
      I was expecting to get some positive and some negative, according to where I am from the axes.
      I clicked the 4 corners of the screen and I got the following, which doesn't look right:

      @unknownuser said:

      x: 46 y: 48 z: 48
      x: 53 y: 52 z: 46
      x: 54 y: 57 z: 46
      x: 52 y: 46 z: 56
      
      posted in Developers' Forum
      M
      michaelazer
    • RE: Count Certain Shapes

      Thanks, TIG. I think I mixed up with the logic of Sketchup.
      (1) Does count=faces.length count all faces on the screen OR in the array I made?
      (2) If a user deletes a face manually, will it be removed from the array? OR only from the screen?
      (3) If the answer to (2) is "only from the screen" does this mean that if I re-draw the array, will the shape that the user deleted get re-drawn?
      Thanks, again.

      posted in Developers' Forum
      M
      michaelazer
    • RE: Save coordinates in an array

      Thank you so much, Dan. Your tips solved the problem.
      Now, I have the program running, but I don't get the correct coordinates.
      I was expecting to get some positive and some negative, according to where I am from the axes.
      I clicked the 4 corners of the screen and I got the following, which doesn't look right:

      @unknownuser said:

      x: 46 y: 48 z: 48
      x: 53 y: 52 z: 46
      x: 54 y: 57 z: 46
      x: 52 y: 46 z: 56

      posted in Developers' Forum
      M
      michaelazer
    • RE: Save coordinates in an array

      After I got your comments I worked on my program, I wrote the following code:

      class MyTool
      	
      		# Initialization
      	def activate
      		@input = Sketchup;;InputPoint.new
      		@pts[]
      	end
      
      	# Respond to left click
      	def onLButtonDown flags, x, y, view
      		@input.pick view, x, y
      		sketchup;;set_status_text "Left click ", SB_VCB_LABEL
      		pos = @input.position
      		@pts << pos
      		str = "%.2f, %.2f,%.2f" % [pos.x, pos.y, pos.z]
      		Sketchup;;set_status_text str, SB_VCB_VALUE
      	end
      	
      end
      
      # Create Command object
      simple_cmd = UI;;Command.new("Click") {
      	Sketchup.active_model.select_tool MyTool.new
      }
      	
      #Add command to tools menu
      tool_menu = UI.menu "Tools"
      tool_menu.add_separator
      tool_menu.add_item simple_cmd	
      

      But still something is not right! I'm getting the following error:

      @unknownuser said:

      Error: #<NoMethodError: undefined method <<' for nil:NilClass> C:/Program Files/Google/Google SketchUp 8/Plugins/click.rb:14:in onLButtonDown'
      C:/Program Files/Google/Google SketchUp 8/Plugins/click.rb:14

      Can you please help me out? Thanks!

      posted in Developers' Forum
      M
      michaelazer
    • RE: Count Certain Shapes

      Thanks for your reply, TIG. I apologize if I wasn't clear.
      My program actually draws some rectangles, then the user deletes some of them.
      I need to count the number of rectangles left.

      posted in Developers' Forum
      M
      michaelazer
    • RE: Count Certain Shapes

      @tig said:

      Are the rectangles four edges each or faces or groups or component instances?

      Faces. I'll add faces using:

      rect = Sketchup.active_model.entities
      rect.add_face ([x1,y1,0],[x2,y2,0],[x3,y3,0],[x4,y4,0])
      

      @tig said:

      If edges/faces are they ever joined together?

      No.

      @tig said:

      Are they arranged so the edges are parallel to the axes?

      No. I was actually going to ask if there is a code to change the axes to make it parallel to the rectangles.

      @tig said:

      Is a rectangle 100x50 the same as one 50x100 ?

      Yes, but all rectangles are oriented the same direction. So, if 50x100 then all are 50x100, if 100x50 then all are 100x50.

      @tig said:

      Are the sizes you gave in inches - i.e. 100" and 50" - or some other units?

      It should be inchesI would like to make it inches, but in the code I put above, shouldn't the x's and y's be in pixels.
      Thanks TIG

      posted in Developers' Forum
      M
      michaelazer
    • Count Certain Shapes

      Hi all,
      I have a model that is full of different shapes. I need a function that would only count the number of rectangles with dimensions 100x50. Can someone help me with this? Thanks.

      posted in Developers' Forum
      M
      michaelazer
    • RE: Save coordinates in an array

      Really, Dan, I can't thank you enough. I think I now have my feet on the right path.
      I believe I will be a regular here on this forum. Again, many thanks to you and TIG.

      posted in Developers' Forum
      M
      michaelazer
    • RE: Save coordinates in an array

      Thanks Dan, I think I actually got addicted to Ruby πŸ˜„
      If I'm not asking for too much, I have a request and a question.
      Request: I theoretically understood both your comments, but can you write me a small piece of code or point me to a link to give me a practical example of how to use the resume(), activate(),new(), and initialize()? I got confused on where to put the code that I want to run when I click the Left Mouse button.
      Question: I don't understand what the @mod is. Is this a variable that Sketchup understands alone or do I need to declare it?
      Sorry, but after I thought I understood, I couldn't apply what I understood.
      Thanks a lot

      posted in Developers' Forum
      M
      michaelazer
    • RE: Save coordinates in an array

      I think I got it πŸ˜„ thank you so much TIG.
      I really appreciate your help.

      posted in Developers' Forum
      M
      michaelazer
    • RE: Save coordinates in an array

      Hi TIG, I really can't thank you enough, but probably I have major issues in understanding how the program is performing.
      I got the syntax onLButtonDown(flag,x,y,view) from the API, which I don't get, by the way.

      Why am I entering an X and a Y, if the idea behind the function is get the X and Y?

      Also, I don't understand what the flag is?

      And lastly, why do I need the view? do I get relative coordinates? so if I move the view I may get a duplicate point?
      Sorry TIG for the hassle.

      posted in Developers' Forum
      M
      michaelazer
    • RE: Save coordinates in an array

      Hi TIG,
      Thanks for your reply, but I'm still quite confused.

      mod = Sketchup.active_model # Open model
      ent = mod.entities # All entities in model
      sel = mod.selection # Current selection
      class MyTool
      	def activate
      		puts "Your tool has been activated."
      		@pts=[]
          end
          def onLButtonDown(flag, x, y, view)
      		ip1 = view.inputpoint x,y
      		@pt = ip1.position
      		@pts << @pt
      	end
      end
      
      my_tool = MyTool.new
      Sketchup.active_model.select_tool my_tool
      
      onLButtonDown(1,100,100,Sketchup.active_model.active_view)
      pts.each{|pt|puts pt}
      

      I get this error:
      Error: #<NoMethodError: undefined method `onLButtonDown' for main:Object>
      Sorry I'm still new.

      posted in Developers' Forum
      M
      michaelazer
    • Save coordinates in an array

      Hi all,

      I'm building a tool that should clone the line tool, but it should also save clicked coordinates in an array.
      So in other words, the user would click some points on the screen, a line should be drawn connecting the points he/she clicked, but also save these points in an array.
      I'm pretty sure it's easy, but I'm struggling with it.

      Thanks in advance,
      Mike

      posted in Developers' Forum
      M
      michaelazer
    • 1 / 1