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

    Planes

    Scheduled Pinned Locked Moved Developers' Forum
    23 Posts 5 Posters 726 Views 5 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.
    • L Offline
      lasersage
      last edited by

      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

      1 Reply Last reply Reply Quote 0
      • L Offline
        lasersage
        last edited by

        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?

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

          You make a transformation and apply it to the group.
          ...So...
          define or get point, vector and angle
          ...then...
          tr=Geom::Transformation.rotation(point,vector,angle)
          ...then...
          master_group.transform!(tr)
          The ! at the end of the transform method changes the original object if tr is a transformation.
          If you add puts tr.class what do you get - it looks like it's not a real transformation to me ...
          The second one with the values set shouldwork OK ?
          Pre-set the variables you use outside of all of your 'do loops' or {} blocks - e.g point=[], vector=[], angle=0.0, tr=nil etc near the start of the script...
          It might be that they are not getting transfered between the loops - setting them first means they will be...
          β˜€

          TIG

          1 Reply Last reply Reply Quote 0
          • L Offline
            lasersage
            last edited by

            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?

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

              Add these lines after the transformation ' tr' is supposedly made
              puts tr.class return nil
              The Ruby Console should shown what tr is - don't mess on with t o_s etc.
              It should just say it's a Geom::Transformation - nothing else...
              The return nil just stops execution at that point so you don't have to wait for a later failure...
              You seem to be messing up something called trans and something called tr here πŸ˜• can you publish the part of the code so we can see what is going wrong ?
              What is trans ?
              Are you somehow putting stuff into an array (==[]) in error ?

              TIG

              1 Reply Last reply Reply Quote 0
              • L Offline
                lasersage
                last edited by

                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

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

                  Looks like you need to have tr defined no matter what e.g.
                  tr=Geom::Transformation.rotation(ORIGIN, Z_AXIS, 0.degrees) if not perpvector
                  so that transform!(tr) always has something to work on ?

                  TIG

                  1 Reply Last reply Reply Quote 0
                  • L Offline
                    lasersage
                    last edited by

                    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 😞

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

                      PM me the ruby and I'll try and look at it later today... πŸ˜•

                      TIG

                      1 Reply Last reply Reply Quote 0
                      • C Offline
                        cjthompson
                        last edited by

                        I think the problem is that you define tr in a seperate place than you use it. try replacing tr with @tr.

                        1 Reply Last reply Reply Quote 0
                        • L Offline
                          lasersage
                          last edited by

                          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.

                          1 Reply Last reply Reply Quote 0
                          • 1
                          • 2
                          • 2 / 2
                          • First post
                            Last post
                          Buy SketchPlus
                          Buy SUbD
                          Buy WrapR
                          Buy eBook
                          Buy Modelur
                          Buy Vertex Tools
                          Buy SketchCuisine
                          Buy FormFonts

                          Advertisement