sketchucation logo sketchucation
    • Login
    1. Home
    2. michaelazer
    ℹ️ Licensed Extensions | FredoBatch, ElevationProfile, FredoSketch, LayOps, MatSim and Pic2Shape will require license from Sept 1st More Info
    M
    Offline
    • Profile
    • Following 0
    • Followers 0
    • Topics 3
    • Posts 15
    • Groups 1

    michaelazer

    @michaelazer

    10
    Reputation
    1
    Profile views
    15
    Posts
    0
    Followers
    0
    Following
    Joined
    Last Online

    michaelazer Unfollow Follow
    registered-users

    Latest posts made by michaelazer

    • 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