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

    lasersage

    @lasersage

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

    lasersage Unfollow Follow
    registered-users

    Latest posts made by lasersage

    • RE: Planes

      Well I thought that was a long shot as it was defined and used in the same def, but I'd forgotten about the initialize def. Sure enough @tr has got it!!!!
      Thanks very much.

      So its rotating and displaying it just as you'd expect, off floating in space to the side.
      I'll have a go at the translation code and see how that goes.

      Thanks very much guys, really pleased this is coming together.

      posted in Developers' Forum
      L
      lasersage
    • RE: Planes

      Well I added that line:
      tr=Geom::Transformation.rotation(ORIGIN, Z_AXIS, 0.degrees) if not perpvector
      right next to the other tr = Geom::..... line but its still doing the same thing.
      Do you think it'd help if I just sent you the full .rb file so you could where it runs too?

      It always seems to give the class as geom::transformation in the console, but whenever I uncomment the transform! line then it has trouble 😞

      posted in Developers' Forum
      L
      lasersage
    • RE: Planes

      Here's the code in full, I'd only held off posting it till now as I was keen to learn enough to fix it myself, but as this is getting frustrating I'll welcome any solutions πŸ˜„

      the initialization of the variables is hashed out because I changed it to initialize in the def initialize sub, rather than here. Not sure if that's good or not though as they might need to be "@point" to carry the value over.

      Hope you can decipher it with all the wordwraping, I tend to leave long lines and comments, I was going to tidy up the defunct code hashed out when I finally got it working.

      
      def onLButtonDown(flags, x, y, view)
          # When the user clicks the first time, we switch to getting the
          # second point.  When they click a second time we create the line
      	
      		#point=[], perpvector=[], angle=0.0, tr=nil
          if( @state == 0 )
              @ip1.pick view, x, y
              if( @ip1.valid? )
                  @state = 1
                  Sketchup;;set_status_text $exStrings.GetString("Select second point (top right)"), SB_PROMPT
                  @xdown = x
                  @ydown = y
      			face = @ip1.face
      			puts "facenormal " + face.normal.to_s
      			angle = Z_AXIS.angle_between(face.normal)
      			perpvector = Z_AXIS.cross(face.normal)
      			point = @ip1.position
      			tr = Geom;;Transformation.rotation(point,perpvector,angle) if perpvector.length!=0
      			#tr=Geom;;Transformation.rotation(ORIGIN, Z_AXIS, 90.degrees)
      			puts "point " + point.to_s, "angle " + angle.to_s, "perpvector " + perpvector.to_s, "transformation " + tr.to_s, "trans class " + tr.class.to_s, tr.class
      			
      			if face == nil
      				UI.messagebox "The points must be on the face of an object"
      				self.reset
      			end
              end
          else
              # create the line on the second click
              if( @ip2.valid? )
                  self.create_geometry(@ip1.position, @ip2.position,view)
      			@ip2.pick view, x, y
      			
      				model = Sketchup.active_model
      				entities = model.entities
      				master_group = entities.add_group()
      				#master_group = master_group.transform!(tr)
      				
      				numsquaresX = 10 	#number of squares in the X direction
      				xsize = 30			#size of squares in the X direction (mm)
      				xsize = xsize/25.4  #converts xsize into mm (from inches)
      				numsquaresY = 10	#number of squares in the Y direction
      				#ysize = 3			#size of squares in the Y direction
      				#ysize = ysize/25.4 #converts ysize into mm (from inches)
      				ysize = xsize		#as we're generally only dealing with squares, edit this line out and reinstate the two above lines for rectangles
      				zsize = xsize
      				z = 0
      				
      				x1 = @ip1.position.x
      				y1 = @ip1.position.y
      				z1 = @ip1.position.z
      				
      				xfinal = @ip2.position.x
      				yfinal = @ip2.position.y
      				zfinal = @ip2.position.z
      				
      				#puts x1, y1, z1, xfinal, yfinal, zfinal
      				if (xfinal - x1) > (25 * xsize)
      					largetest = UI.messagebox "You have selected a large area, this may make the program unstable. Suggest multiple smaller areas", MB_OKCANCEL
      					if largetest == 2
      						self.reset
      					end
      				end
      
      				while y1 < yfinal
      					y2 = y1 + ysize
      					while x1 < xfinal
      						x2 = x1 + xsize
      						pt1 = [x1, y1, z]									#plot the first line
      						pt2 = [x1, y2, z]									#plot the second line
      						pt3 = [x2, y2, z]									#plot the third line
      						pt4 = [x2, y1, z]									#plot the fourth line, back to start
      						#new_face = entities.add_face pt1, pt2, pt3, pt4	#plot a face on the square to make it visible
      						#group.entities.add_face pt1, pt2, pt3, pt4
      
      						group = master_group.entities.add_group
      						face = group.entities.add_face pt1, pt2, pt3, pt4
      												
      						x1 = x2 - (xsize * 0.08) #let the next spot begin at 92% of the way across the previous
      						Sketchup;;set_status_text $exStrings.GetString("Working"), SB_PROMPT
      						#puts "Point1 " + pt1.to_s, "Point2 " + pt2.to_s, "Point3 " + pt3.to_s, "Point4 " + pt4.to_s
      					end
      					y1 = y2 - (ysize * 0.08) #let the next spot begin at 92% of the way across the previous
      					#x1 = x1 - (xsize * 0.92 * xstep) #go back to initial x position for next line in y
      					x1 = @ip1.position.x
      				end
      			master_group.transform! tr
      			self.reset(view)
              end #end click 2
          end
          
          # Clear any inference lock
          view.lock_inference
      end
      

      let me know if you want me to send the complete .rb files, as this chunk of code wont run without the other def's around it

      posted in Developers' Forum
      L
      lasersage
    • RE: Planes

      when I added the =0.0, =nil etc. line of code nothing changed,
      and when I tried "trans class " + tr.class
      it gave me a cannot be displayed as string message, so I did tr.class.to_s and that gave me:
      point (503.690114mm, 371.165908mm, 943.266108mm)
      angle 1.5707963267949
      perpvector (1.0, -6.27276008913213e-015, 0.0)
      transformation #Geom::Transformation:0xba74610
      trans class Geom::Transformation
      Error: #<TypeError: no implicit conversion to Transformation>
      C:/Program Files/Google/Google SketchUp 7/Plugins/test5.rb:170:in transform!' C:/Program Files/Google/Google SketchUp 7/Plugins/test5.rb:170:in onLButtonDown'

      So it looks like the transformation is OK, but it doesn't like it when it calls transform! .
      My geom::transformation line is just after the first click but before the loop, my transform! line is after the loops.
      Any ideas?

      posted in Developers' Forum
      L
      lasersage
    • RE: Planes

      OK I've had a look at it but not really got anywhere 😞
      I've tried both:
      tr=Geom::Transformation.rotation(point, vector, angle)
      tr=Geom::Transformation.rotation(ORIGIN, Z_AXIS, 90.degrees)

      just to make sure there wasn't a problem here, and had
      puts "transformation " + tr.to_s
      put what looks like a reasonable output into the console.
      All OK, but whenever I run the program it bugs out to the old click drag click error message and the console shows:

      Error: #<TypeError: no implicit conversion to Transformation>
      C:/Program Files/Google/Google SketchUp 7/Plugins/test5.rb:117:in transform!' C:/Program Files/Google/Google SketchUp 7/Plugins/test5.rb:117:in onLButtonDown'

      So what it wrong with my transform! bit?
      I've tried it as:
      master_group = master_group.transform!(tr)
      &
      master_group.transform! tr

      after the loop and before it (straight after master_group is defined). None of it works, it always gives me this daft conversion message. But I'm convinced the first bit of code does give a valid transformation, so why does it then think it the wrong type or something?
      It can't just be down to where I'm placing the
      master_group.transform! tr
      line in the code can it?

      posted in Developers' Forum
      L
      lasersage
    • RE: Planes

      looks good thanks Tig.
      I'm off for the weekend now, but I've just sent all the files to my home email so I'll see if I can find time to have a bash at it in my own time.
      I'll let you know how it goes on monday.
      Thanks again for the help so far, I'd be stuck without it

      posted in Developers' Forum
      L
      lasersage
    • RE: Planes

      No worries Tig, the odd typo is bound to happen. Makes me feel more confident that I can work out the odd thing as well.

      So I've pasted in this stuff
      face = @ip1.face
      puts "facenormal " + face.normal.to_s
      rotationangle = Z_AXIS.angle_between(face.normal)
      perpvector = Z_AXIS.cross(face.normal)
      tr = Geom::Transformation.rotation(@ip1,perpvector,angle) if perpvector.length!=0

      before the loop, as "face" gets used for other stuff in the loop, and as you can see, changed point to @ip1 (the first click of the mouse). Hope that is a reasonable point to assume? I get that some significant translation might be required afterwards, but hopefully it'll still turn the plane to the right angle?

      But the
      tr = Geom::Transformation.rotation(@ip1,perpvector,angle) if perpvector.length!=0
      bit of code. I don't really get it. Presumably you can only rotate a group once you've already made it. I've tried cutting just this line and sticking it after the groups are formed, just after the loop, but it goes back to click and drag error.
      This line of code makes no mention of "master_group" so I don't really get how it works anyway.
      Do I need to call something like master_group.rotation = tr ?
      or did I misread your first comment on this thread and this line of code is purely to zero the plane and I actually need an entirely different line of code for the actual rotation.
      Sorry to be such a newb on this one πŸ˜•

      posted in Developers' Forum
      L
      lasersage
    • RE: Planes

      sweet I fixed it already,
      it was supposed to be entities.add_group not model.add_group, but it was a combination of that and having it within the loop when it only needed to be defined once.
      Awesome πŸ˜„
      Thanks for the help

      I'll see how much further I can get now...

      posted in Developers' Forum
      L
      lasersage
    • RE: Planes

      it doesn't seem to work 😞
      whenever I leave in the:
      master_group=model.add_group()
      line then my program get confused and starts reporting errors. I had set up error handling for click and drag rather than click move click, so it will only accept click move click. This code was lifted straight from the line tool example that comes with sketchup and was working fine before so is unlikely to be the cause.
      When I look online at the model tag (http://code.google.com/apis/sketchup/docs/ourdoc/model.html) it makes no mention of the add_group command.
      I've tried substituting entities for model, i.e. ... = entities.add_group() and even ... = model.entities.add_group, but neither of these work. They'll group individual spots but not the whole lot. What am I missing

      Thanks for persevering

      posted in Developers' Forum
      L
      lasersage
    • RE: Planes

      Thanks very much for the advice Tig,
      Reassured that I can rotate the plane I've been finishing up the code to draw from a start point to a finish point in 2d (I'd been holding off worried I'd have to undo it all to fiddle in some trig).
      I need each square to be moveable and deletable so I've set about grouping things:
      group = entities.add_group
      group.entities.add_face pt1, pt2, pt3, pt4
      This is within the loop so every spot (square) groups.
      Now my problem:
      I then need to add all of these groups to a master group temporarily to rotate and translate as you previously described.
      How do I do this? I'm a bit stuck, tried all sorts of combos of group.entities... but can't figure the right syntax. Online help files don't enlighten me much either 😞

      aside from that, grabbing the 3d vector of the face seems to have gone well:
      face = @ip1.face
      puts "facenormal " + face.normal.to_s
      rotationangle = Z_AXIS.angle_between(face.normal)
      puts "rotationangle " + rotationangle.to_s

      So thanks with that bit.
      Once I get this group issue solved then I'll see how the rest of it (rotation etc.) goes.

      Also a quick question, my computer is seriously slow to draw this. I'm sure my code is inefficient, do you think I'd gain much by drawing a 4 lines, grouping them, then copy paste and translating them each time rather than redrawing and regrouping. Its so tedious I've had to add:
      if (xfinal - x1) > (25 * xsize)
      largetest = UI.messagebox "You have selected a large area, this may make the program unstable. Suggest multiple smaller areas", MB_OKCANCEL
      if largetest == 2
      self.reset
      end
      end

      I'm sure you can see from my code how unfamiliar I am with this ruby malarkey πŸ˜„ trying to struggle on

      posted in Developers' Forum
      L
      lasersage