• Login
sketchucation logo sketchucation
  • Login
πŸ€‘ SketchPlus 1.3 | 44 Tools for $15 until June 20th Buy Now

Re: [Plugin] Another Mirror Ruby

Scheduled Pinned Locked Moved Plugins
31 Posts 15 Posters 37.0k Views
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.
  • A Offline
    arjunmax09
    last edited by 16 Feb 2010, 12:00

    I installed the icon made by matt666 in my plugins directory and made the requisite changes to the plugin as specified on this forum. The icon is showing in my SketchUp Interface. Unfortunately when I select a group, click on the mirror icon, select two axis for mirroring. ....nothing happens 😞

    i've modified the plugin like this...

    # Name ;          Mirror 3.0 ###
    
    # Description ;   Mirrors Selection at Point, Line or Plane
    
    # Author ;        Originally by Frank Wiesner
    #				  BUT NOTE from v2.6 it's been TIG tweaked and rewritten...###
    
    # Usage ;         1. Make Selection (Any Entites allowed)###
    #                 2. Select 'Mirror Selection' from Plugins Menu 
    #					 or from Context Menu or your ShortCut Key ###
    #                 3. If here's no Selection then dialog informs ###
    #                 4. Pick a Point and RETURN to Mirror at the Point
    #                 5. Pick a Second Point and RETURN to Mirror at the Line
    #                 6. Pick a Third Point to Mirror at the Plane
    #                 7. Final Option is Erase Original ? ###
    #					 If Yes then Highlighting of Selection passes to Copies
    #					 (Note; Erase is undo-able separately from the Mirroring) ###
    
    # Type ;      	Script
    
    # History;      
    #				3.0  05 Aug  2006 ### TIG Ending rewritten to avoid rare bugsplats.
    #				2.9  03 Aug  2006 ### TIG Start;commit loops to avoid rare bugsplats.
    #				2.8  26 July 2006 ### TIG re-tweaked - Rewritten to be MUCH simpler.
    #										Mirroring of ANY Entity Selection works properly.
    #				2.7  23 July 2006 ### TIG tweaked - Rewritten generally.
    #										Now processes Multiple selections of Groups and/or 
    #										Components, but warns if any 'loose' (UnGrouped) 
    #										Faces in Selection as they might lose any RePostioned 
    #										Texture data, interfere etc.  
    #				2.6  22 July 2006 ### TIG tweaked - Context menu added IF ONE group/compo.  
    #                                       Warns about selection IF NOT ONE group/compo.  
    #                                       Materials now preserved in mirrored copy BUT you will 
    #									    need to group selection to preserve material positioning 
    #										- although this is define-able it is not find-able from 
    #										the orignal face info !  
    #                                       Final option to Erase of Original Group/Compo.
    #                 2.5  (8.Jul.2oo5)  - bugfix; faces with holes reduce now to a single face
    #                                    - major code rewrite (dropped @clondedObject hash, heavy 
    #                                      use of groups during construction,...
    #                                    - more redundant constructions, but seems to be more robust
    #                                    - WARNING; POLYGONS DO NOT WORK VERY WELL
    #                 2.4  (5.Jul.2oo5)  - all unnecessary edges created by the add_faces_from_mesh() 
    #                                      method are erased! faces with holes mirror now perfectly.
    #                 2.3  (4.Jul.2oo5)  - fixed "mirror at plane" error
    #                 2.2  (2.Jul.2oo5)  - works in group editting mode
    #                                    - prevents picking of identical points
    #                 2.1  (1.Jul.2oo5)  - fixed "undo group" bug
    #                                    - code cleanup
    #                 2.0  (30.Jun.2oo5) - new tool-like interface
    #                 1.4  (29.Jun.2oo5) - arc bug fixed
    #                                    - code simplified (clone_selection() removed)
    #                 1.3  (24.Jun.2oo5) - can handle faces with holes in it (although more edges 
    #                                      are drawn than nessesary)
    #                                    - correct orientation of mirrored faces 
    #                                    - supports arcs (at least works for circles), curves and groups
    #                 1.2  (20.Jun.2oo5) - axis and origin selection algorithm does not rely on tool tips any more.
    #                 1.1  (19.Jun.2oo5) - fix coplanar point bug
    #                                    - better tooltips
    #                                    - supports mirror at lines (edges, axis, construction lines)
    #                                    - mirror-at-plane code simplified
    #                 1.o  (10.Jun.2oo5) - first version
    
    require 'sketchup.rb'
    class MirrorTool
    
        def initialize
            @MIRROR_AT_POINT = 1
            @MIRROR_AT_LINE = 2
            @MIRROR_AT_PLANE = 3
            @numPrecision = 0.00001
        end
        def reset
            @pts = []
            @state = 0
            @transformationType = nil
            @trans = nil
            @point = nil
            @line = nil
            @linev = nil
            @plane = nil
            @planeNormal = nil
            @pointOnPlane = nil
            @curvesDone = Hash.new()
            @cloneGroup = nil
            @ip = Sketchup;;InputPoint.new
            @ip1 = Sketchup;;InputPoint.new
            @ip2 = Sketchup;;InputPoint.new
            @ip3 = Sketchup;;InputPoint.new
            @ip = Sketchup;;InputPoint.new
            Sketchup;;set_status_text "Mirror;  Pick First Point"###
            @drawn = false
        end
        def activate
            ###Sketchup.send_action("showRubyPanel;")
            self.reset
            ss=Sketchup.active_model.selection
            if ss.empty?
                Sketchup;;set_status_text "Mirror; NO Selection !"###
        		UI.messagebox("Select Something BEFORE Using the Mirror Tool.")###v2.8
                Sketchup.active_model.select_tool nil
            end
        end
        def deactivate(view)
            view.invalidate if @drawn
            @ip1 = nil
            @ip2 = nil
            @ip3 = nil
        end
        def onMouseMove(flags, x, y, view)
            case @state
            when 0 # getting the first end point
                @ip.pick view, x, y
                if( @ip.valid? && @ip != @ip1 )
                    @ip1.copy! @ip
                end
                view.invalidate
                view.tooltip = @ip.tooltip if @ip.valid?
            when 1 # getting the second end point
                @ip.pick view, x, y, @ip1
                if( @ip.valid? && @ip != @ip2 )
                    @ip2.copy! @ip
                    @pts[1] = @ip2.position
                end
                view.invalidate
                view.tooltip = @ip.tooltip if @ip.valid?
            when 2 # getting the third end point
                @ip.pick view, x, y, @ip2
                if( @ip.valid? && @ip != @ip3 )
                    @ip3.copy! @ip
                    @pts[1] = @ip3.position
                end
                view.invalidate
                view.tooltip = @ip.tooltip if @ip.valid?
            end
        end
        def onLButtonDown(flags, x, y, view)
            @ip.pick view, x, y
            if( @ip.valid? )
                case @state
                when 0
                    if( @ip.valid? )
                        @pts[0] = @ip.position
                        Sketchup;;set_status_text "Mirror;  Hit RETURN to Mirror at Point or Pick Point 2"
                        @state = 1
                    end
                when 1
                    if( @ip.valid? && @ip != @ip1 )
                        @pts[1] = @ip.position
                        @state = 2
                        Sketchup;;set_status_text "Mirror;  Hit RETURN to Mirror at Line or Pick Point 3"
                    end
                when 2
                    if( @ip.valid? && @ip != @ip1 && @ip != @ip2 )
                        @pts[2] = @ip.position
                        @state = 3
                        mirror()
                    end
                end
            end
        end
        def onCancel(flag, view)
            view.invalidate if @drawn
            reset
        end
        def draw(view)
            if( @ip.valid? && @ip.display? )
                @ip.draw(view)
                @drawn = true
            end
            if( @state == 1 )
                view.set_color_from_line(@ip1, @ip)
                view.draw(GL_LINE_STRIP, @ip1.position, @ip.position)
                @drawn = true
            elsif( @state == 2 )
                view.drawing_color = "gray"
                view.draw(GL_LINE_STRIP, @ip1.position, @ip2.position)
                view.set_color_from_line(@ip2, @ip)
                view.draw(GL_LINE_STRIP, @ip2.position, @ip.position)
                @drawn = true
            end
        end
        def onKeyDown(key, repeat, flags, view)
            if( key == CONSTRAIN_MODIFIER_KEY && repeat == 1 )
                @shift_down_time = Time.now
                if( view.inference_locked? )
                    view.lock_inference
                elsif( @ip.valid? )
                    view.lock_inference @ip
                end
            end
        end
        def onKeyUp(key, repeat, flags, view)
            if( key == CONSTRAIN_MODIFIER_KEY && view.inference_locked? && (Time.now - @shift_down_time) > 0.5 )
                view.lock_inference
            end
            if( key == 13)
                mirror()
                self.reset
            end
        end
        
        def mirror()
            case @state
            when 1
                @transformationType = @MIRROR_AT_POINT
                @point = @ip1.position.clone
                @trans = Geom;;Transformation.scaling(@point, -1.0)
                Sketchup.active_model.start_operation "Mirror at Point"
            when 2
                @transformationType = @MIRROR_AT_LINE
                @line = [@ip1.position, @ip2.position] 
                @linev = Geom;;Vector3d.new(@ip2.position.x-@ip1.position.x, @ip2.position.y-@ip1.position.y, @ip2.position.z-@ip1.position.z)
                Sketchup.active_model.start_operation "Mirror at Line"
            when 3
                @transformationType = @MIRROR_AT_PLANE
                @plane = Geom.fit_plane_to_points(@ip1.position, @ip2.position, @ip3.position) 
                @planeNormal = Geom;;Vector3d.new(@plane[0], @plane[1], @plane[2])
                @planeNormal.normalize!
                @pointOnPlane = @ip1.position
                Sketchup.active_model.start_operation "Mirror at Plane"
            end
            ###
            ss=Sketchup.active_model.selection###
        	sents=[]
        	ss.each{|e|sents.push(e)}
        	copy_group=Sketchup.active_model.active_entities.add_group(sents)
            new_group=copy_group.copy
            nents=[]
            new_group.entities.each{|e|nents.push(e)}
            new_center = new_group.bounds.center.clone
            mirror_point(new_center)
            t=nil
            t = Geom;;Transformation.scaling(new_center,-1,-1,-1)if @state==1
            t = Geom;;Transformation.rotation(new_center,@linev,Math;;PI)if @state==2
            tt=nil
            if @state==3
               xxx=@planeNormal.normalize.to_a[0].abs*-1
               yyy=@planeNormal.normalize.to_a[1].abs*-1
               zzz=@planeNormal.normalize.to_a[2].abs*-1
               xxx=1 if xxx>0
               yyy=1 if yyy>0
               zzz=1 if zzz>0
               xxx=-1 if xxx<=0 
               yyy=-1 if yyy<=0
               zzz=-1 if zzz<=0
               t = Geom;;Transformation.scaling(new_center,xxx,yyy,zzz)
               tt= Geom;;Transformation.rotation(new_center,@planeNormal,Math;;PI)
            end#if
            new_group.transform!(t)if t###mirror
            new_group.transform!(tt)if tt###
            transVec = Geom;;Vector3d.new(new_center.x-new_group.bounds.center.x, new_center.y-new_group.bounds.center.y, new_center.z-new_group.bounds.center.z) 
            t = Geom;;Transformation.translation(transVec)
            new_group.transform!(t)###then move
            ### ending dialog...
        	Sketchup;;set_status_text "Mirror; Erase Original Selection ?"###
        	if UI.messagebox("Erase Original Selection ? ",MB_YESNO,"")==6
        	   ### 6=YES 7=NO
        	   Sketchup.active_model.commit_operation###v2.9
          	   Sketchup.active_model.start_operation "Mirror; Erase Original Selection"
        	    Sketchup.active_model.selection.clear
          	    copy_group.erase!
        	    new_group.explode
          	    nents.each{|e|Sketchup.active_model.selection.add(e)if e.valid?}###v3.0
        	   Sketchup.active_model.commit_operation
          	else
               Sketchup.active_model.selection.clear
               new_group.explode
               copy_group.explode
               sents.each{|e|Sketchup.active_model.selection.add(e)if e.valid?}###v3.0
               Sketchup.active_model.commit_operation###v2.9
        	end#if
        	###
            self.reset
            Sketchup.send_action "selectSelectionTool;"
    
        end#def
        
        def mirror_point(new_p)
            if (@transformationType == @MIRROR_AT_PLANE)
                if (!new_p.on_plane?(@plane))
                    mirrorp = new_p.project_to_plane(@plane)
                    @trans = Geom;;Transformation.scaling(mirrorp, -1.0)
                    new_p.transform!(@trans)
                end
            elsif (@transformationType == @MIRROR_AT_LINE)
                if (!new_p.on_line?(@line))
                    mirrorp = new_p.project_to_line(@line)
                    @trans = Geom;;Transformation.scaling(mirrorp, -1.0)
                    new_p.transform!(@trans)
                end
            elsif (@transformationType == @MIRROR_AT_POINT)
                if (!(new_p == @point))
                    new_p.transform!(@trans)
                end
            end
        end#def
        
    end # class MirrorTool
    
    ### menus ##############################################################
        if( not file_loaded?("mirror3.0.rb") )
           tb = UI;;Toolbar.new("Mirror")
           cmd = UI;;Command.new("MI") { Sketchup.active_model.select_tool MirrorTool.new }
           cmd.large_icon = cmd.small_icon = File.join(File.dirname(__FILE__),"MI.png")
           cmd.tooltip = cmd.status_bar_text = "Mirror"
           tb.add_item(cmd)
           UI.menu("Plugins").add_item("Mirror Selection") { Sketchup.active_model.select_tool MirrorTool.new }
           UI.add_context_menu_handler do | menu |
              if Sketchup.active_model.selection
                 menu.add_separator
                 menu.add_item("Mirror Selection") { Sketchup.active_model.select_tool MirrorTool.new }
              end
           end
           state = tb.get_last_state
           if(state == TB_NEVER_SHOWN)
              tb.show
           elsif (state == TB_VISIBLE)
              tb.restore
           end
        end
        file_loaded("mirror3.0.rb")
    

    when you fail at something....you haven't really failed...you've found one way the thing will not work out

    1 Reply Last reply Reply Quote 0
    • thomthomT Offline
      thomthom
      last edited by 16 Feb 2010, 12:07

      arjunmax09: All formatting is lost like that. Use the [code] tag to mark up code. Or preferably, when you got a longer piece of code like that, just upload the .rb file.

      Thomas Thomassen β€” SketchUp Monkey & Coding addict
      List of my plugins and link to the CookieWare fund

      1 Reply Last reply Reply Quote 0
      • TIGT Offline
        TIG Moderator
        last edited by 16 Feb 2010, 12:17

        Please remove one of your duplicated posts - one is more than long enough ! [done, thanks]
        Also, please put long bits of code inside a code/code-block - it keeps its formating and is easier to read/copy.

        Your toolbar/menu part works fine for me - so you must have edited something else within the main text ???
        Just copy your new part [below '###menus###...'] and then paste it over the equivalent section in a copy of the original script - it should then work...
        Note that the last version is 3.1...

        Are you picking suitable axes, points to actually give a 'mirror' ?

        TIG

        1 Reply Last reply Reply Quote 0
        • A Offline
          arjunmax09
          last edited by 17 Feb 2010, 11:05

          @tig said:

          Please remove one of your duplicated posts - one is more than long enough ! [done, thanks]
          Also, please put long bits of code inside a code/code-block - it keeps its formating and is easier to read/copy.

          Your toolbar/menu part works fine for me - so you must have edited something else within the main text ???
          Just copy your new part [below '###menus###...'] and then paste it over the equivalent section in a copy of the original script - it should then work...
          Note that the last version is 3.1...

          Are you picking suitable axes, points to actually give a 'mirror' ?

          yeah i'm picking the right axes, points to give a mirror.... only to find nothing...

          πŸ˜• uh.... TIG I know zilch about ruby... I just followed the instructions given on the forum to modify my mirror plugin... but nothin' happened... I'm unable to understand the instructions that ur givin' on this post. Is it necessary that I keep the old mirror ruby in my folder as well as the new one... i.e. 2 ruby files for mirror in my plugins folder??

          when you fail at something....you haven't really failed...you've found one way the thing will not work out

          1 Reply Last reply Reply Quote 0
          • TIGT Offline
            TIG Moderator
            last edited by 17 Feb 2010, 11:24

            You only need one 'version' of the script.
            It is a self-contained file with everything it needs inside it [unless of course it's the toolbar version which then needs the button's image file too]

            Temporarily remove one of the scripts and see if the other one works...
            Also try opening the Ruby Console [Windows Menu] and type in [or easier copy/paste it]

            Sketchup.active_model.select_tool(MirrorTool.new)

            then <enter> key.

            Does the mirror tool then work or print an error etc ? πŸ˜•
            Do you get prompted for the axes etc ?
            What does the Ruby Console say when you run the tool in the four available ways - from Plugins Menu, Toolbar, Right-click Context-Menu and Typing in the command as above ?

            Do you pick three discrete points that form something to mirror about - say one point on the group and then a point on the green axis and one on then blue axis ? You should then get a copy made and a request to keep/erase the original...

            TIG

            1 Reply Last reply Reply Quote 0
            • A Offline
              arjunmax09
              last edited by 17 Feb 2010, 11:30

              @tig said:

              You only need one 'version' of the script.
              It is a self-contained file with everything it needs inside it [unless of course it's the toolbar version which then needs the button's image file too]

              Temporarily remove one of the scripts and see if the other one works...
              Also try opening the Ruby Console [Windows Menu] and type in [or easier copy/paste it]

              Sketchup.active_model.select_tool(MirrorTool.new)

              • <enter> key.

              Does the mirror tool then work or print an error etc ? πŸ˜•

              No ... it doesn't ....My older version of mirror plugin works just fine [i haven't tweaked it for the icon]... ..Can you upload your tweaked mirror script [ the one that uses the icon]so that i can use it????

              and... one more question..... I don't know ruby... is there a standard string that can be added to a ruby script so that i can make its custom toolbar or buttons work...??? I really hate scrolling through the plugins menu to get the one i want to use...

              when you fail at something....you haven't really failed...you've found one way the thing will not work out

              1 Reply Last reply Reply Quote 0
              • TIGT Offline
                TIG Moderator
                last edited by 17 Feb 2010, 11:34

                See my edited post...
                Have you removed the 'working version' and retried in case they are clashing ?
                I actually don't have a toolbar version as I always use a shortcut key to run it. 😒

                TIG

                1 Reply Last reply Reply Quote 0
                • A Offline
                  arjunmax09
                  last edited by 18 Feb 2010, 04:12

                  @tig said:

                  See my edited post...
                  Have you removed the 'working version' and retried in case they are clashing ?
                  I actually don't have a toolbar version as I always use a shortcut key to run it. 😒

                  Yeah... i've removed my 'workin version' and retried ....... the problem persists....

                  Actually this is what happening...

                  The objects that i want to mirror get recreated as a group on the spot itself. suppose i have a cube and next to it a sphere is there....

                  i select the sphere and cube using the shift key...

                  next i click on mirror button

                  next... i draw a line along green axis

                  now... i draw my path across blue axis...

                  ..... the two objects get grouped together on the spot...

                  i can't seem to figure out the problem 😞

                  when you fail at something....you haven't really failed...you've found one way the thing will not work out

                  1 Reply Last reply Reply Quote 0
                  • TIGT Offline
                    TIG Moderator
                    last edited by 18 Feb 2010, 09:15

                    It groups them to do the mirroring then explodes the group back as it was - if it's working...

                    I have decided I will add the tool button to the script for you and ensure it's working, then post it.

                    Can you post the .png button image for me please... ❓
                    EDIT: no need I found it...

                    TIG

                    1 Reply Last reply Reply Quote 0
                    • TIGT Offline
                      TIG Moderator
                      last edited by 18 Feb 2010, 09:57

                      Here's v3.2 with the toolbar option added.
                      Otherwise the script's workings are unchanged.
                      It's been fully tested and works when activated from the Menu, the Context-Menu, a Shortcut or the new Toolbar.
                      If the MI.png file is not found with the .rb file then the toolbar is NOT made.
                      You can activate this new 'Mirror' toolbar from View>Toolbars.
                      Put these 2 files into 'Plugins' - you can omit MI.png [or rename] it if you don't want a toolbar.Mirror.rbMI.png
                      πŸ€“
                      EDIT: NOTE THAT THE LATEST VERSION IS NOW AVAILABLE HERE http://forums.sketchucation.com/viewtopic.php?p=276512#p276512

                      TIG

                      1 Reply Last reply Reply Quote 0
                      • broomstickB Offline
                        broomstick
                        last edited by 19 Feb 2010, 15:57

                        I think a variant of the Mirror Plugin, should consider creating a toolbar with 3 buttons: each one would perform the mirror simmetrically to one of the axis, asking before the operation to click on the plane to define the start of the mirror line.

                        It would work similarly to rot90 plugin, but for the mirror.

                        I hate myself for not being able to code, otherwise I'd do it myself!

                        1 Reply Last reply Reply Quote 0
                        • I Offline
                          ideas_arte
                          last edited by 19 Feb 2010, 23:55

                          Thank you very much, a basic tool and very useful!

                          1 Reply Last reply Reply Quote 0
                          • B Offline
                            bjack56
                            last edited by 17 Mar 2010, 17:48

                            Thank you...works great, once I figured out to "right-click.save as" the image. 😍

                            1 Reply Last reply Reply Quote 0
                            • B Offline
                              Ben Ritter
                              last edited by 6 May 2010, 14:30

                              Thanks for the script. However, I get a Bug Splat when I do not erase the original. I do not have this problem with SU 6. I'm running SU7.

                              1 Reply Last reply Reply Quote 0
                              • D Offline
                                dedmin
                                last edited by 17 May 2010, 12:59

                                Bugsplat with Outliner open! SU7.

                                1 Reply Last reply Reply Quote 0
                                • L Offline
                                  lapx
                                  last edited by 1 Sept 2010, 15:37

                                  I'm getting the bugsplat as well and I'm using Su6. It worked fine before. But not working these days?
                                  It occurs when answering "no" to erase original. BUGSPLAT! everytime.

                                  1 Reply Last reply Reply Quote 0
                                  • L Offline
                                    lapx
                                    last edited by 1 Sept 2010, 20:36

                                    There error occurs with all three scrpits that I have: mirror 3[1].0rb , mirror2.8.rb and mirror.rb.
                                    I tested each one while temporarily renaming the others and each one failed with a bugsplat.
                                    Might there be conflicts with some other script(s)? 😲

                                    1 Reply Last reply Reply Quote 0
                                    • D Offline
                                      dedmin
                                      last edited by 3 Oct 2010, 12:34

                                      Can the Bugsplat when Outliner is open be fixed? I always forget about this and crash SketchUP!

                                      2010-10-03_152559.jpg

                                      1 Reply Last reply Reply Quote 0
                                      • TIGT Offline
                                        TIG Moderator
                                        last edited by 3 Oct 2010, 13:54

                                        You have to 'roll-up' the Outliner window to avoid a splat - it's a known issue with Sketchup itself... not any tool per se... You should never use any tool that makes and deletes instances in succession with the Outliner 'rolled-down'...
                                        I have posted an updated version here http://forums.sketchucation.com/viewtopic.php?p=276512#p276512

                                        Don't worry about the 'group.make_unique is deprecated...' error messages - it's a known mistake in the API error reporting, and Thomthom has been pressing to get it removed - you DO need to use group.make_unique in some circumstances...

                                        TIG

                                        1 Reply Last reply Reply Quote 0
                                        • D Offline
                                          dedmin
                                          last edited by 3 Oct 2010, 14:17

                                          I see - thanks TIG!

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

                                          Advertisement