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

Saving selection to file, and placing on the mouse pointer.

Scheduled Pinned Locked Moved Plugins
11 Posts 4 Posters 821 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.
  • H Offline
    honoluludesktop
    last edited by 5 Oct 2010, 23:48

    Is there any simple way of attaching a selection of entities, or group to the mouse pointer? The only method I have found that would do that is import model. So, my second question, is is there any simple way of making a skp of a selection, or group of entities? I looked at this too, but could only find a method to save the whole model. As a test, I even tried to delete everything except the selection, then saved it, but even with a different name, the system would not (recursive?? error) import it back into the current model.

    1 Reply Last reply Reply Quote 0
    • C Offline
      Chris Fullmer
      last edited by 6 Oct 2010, 04:42

      You can save a component definition out to a file with this:

      http://code.google.com/apis/sketchup/docs/ourdoc/componentdefinition.html#save_as

      So you could take the selection, then turn it into a component, save that out, then explode the component (or don't, whichever). And I'm trying to rememeber, but it seems like when you add a component instance to the model, SU will stick it to the cursor automatically (sticking the "instertion point to the cursor).

      So perhaps converting to components is the way to go in this case?

      Chris

      Lately you've been tan, suspicious for the winter.
      All my Plugins I've written

      1 Reply Last reply Reply Quote 0
      • T Offline
        thomthom
        last edited by 6 Oct 2010, 06:21

        Yes, if you make a ComponentDefinition out of your entities, then you can use model.place_component.
        http://code.google.com/apis/sketchup/docs/ourdoc/model.html#place_component

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

        1 Reply Last reply Reply Quote 0
        • H Offline
          honoluludesktop
          last edited by 6 Oct 2010, 10:19

          Thanks, I'll give that a try tomorrow.

          1 Reply Last reply Reply Quote 0
          • H Offline
            honoluludesktop
            last edited by 7 Oct 2010, 09:59

            In order to get the entities in my_selection into my_definition, and make the file my_component.skp, is it necessary to do it for every entity as follows?

            my_selection.each do |e|
              if e.is_a? Sketchup;;Entity
                face = []
                if e.is_a? Sketchup;;Face
                  face = e.vertices
                  my_definition.entities.add_face face
                end
                if e.is_a? Sketchup;;ComponentInstance
                  ci=e.definition
                  ti=e.transformation
                  my_definition.entities.add_instance(ci,ti)
                end
                #do if end for each entity type
                #
              end
            end
            
            success = my_definition.save_as "my_component"
            
            

            Or, is there an easier way? How do I make a curve an arc, or circle?

            1 Reply Last reply Reply Quote 0
            • H Offline
              honoluludesktop
              last edited by 7 Oct 2010, 20:50

              For those who may be interested, here is the whole snippet. Problem is the selection attaches itself to the mouse pointer by the model's origin. Should have thought of that:-( Anyway, you may remove the "commented out" in the code to erase the selection from the model. Although you can recover by ^z, It needs a automatic undo, if you quit before locating the selection.

              Another problem is that Su entities are faces and edges, so arcs and circles lose their geometric attributes. Although you can add_... them, they are not Sketchup::Entities. Actually still not sure how all that stuff works.

              model = Sketchup.active_model
              definitions = model.definitions
              entities = model.entities
              selection = model.selection
              
              definition = definitions.add "Selection" 
              my_definition = definitions.add "My Selection" 
              
              selection.each do |e|
                if e.is_a? Sketchup;;Entity
                  if e.is_a? Sketchup;;Face
                    my_definition.entities.add_face e.vertices 
                  end
              #   if e.is_a? Sketchup;;Curve
              #     result = my_definition.entities.add_curve e.vertices
              #   end
                  if e.is_a? Sketchup;;Edge
                    my_definition.entities.add_edges e.vertices
                  end
                  if e.is_a? Sketchup;;ComponentInstance
                    my_definition.entities.add_instance(e.definition,e.transformation)
                  end
                  if e.is_a? Sketchup;;Group
                    group = my_definition.entities.add_group
                    entities = e.explode
                    entities.each do |ge|
                      if ge.is_a? Sketchup;;Face
                        my_definition.entities.add_face ge.vertices
                      end
                      if ge.is_a? Sketchup;;Edge
                        my_definition.entities.add_edges ge.vertices
                      end
                    end
                  end
                  #e.erase!
                end
              end
              
              success = my_definition.save_as "mycomponent"
              
              show_summary = true  
              status = model.import "mycomponent.skp", show_summary
              
              File.delete("mycomponent.skp") 
              
              
              1 Reply Last reply Reply Quote 0
              • T Offline
                thomthom
                last edited by 8 Oct 2010, 07:13

                Why not group the selected entities and convert it into a component?

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

                1 Reply Last reply Reply Quote 0
                • H Offline
                  honoluludesktop
                  last edited by 8 Oct 2010, 07:32

                  OK, I'll give that a try.

                  1 Reply Last reply Reply Quote 0
                  • R Offline
                    rvs1977
                    last edited by 9 Oct 2010, 07:05

                    How to attach a group to the mousepointer:

                    First, I think, you have to use the "Tool"-class, because in this class you have the onMouseMove-method.
                    (see also \plugins\examples\linetool.rb - it shows in detail how to use the tool-class)

                    
                    class My_tool
                      def initialize # a good place to put variables. Notice the "@". It means you can see the variable
                                     # in the whole My_tool class. If no "@" it would only be visible inside the def.
                        @mod = Sketchup.active_model 
                        @ent = @mod.entities    
                        @state = 0
                             
                         @pts = []
                         @pts[0] = [0,0,0]
                         @pts[1] = [10,0,0]
                         @pts[2] = [10,20,0]
                         @pts[3] = [0,20,0] 
                         
                      end 
                    
                      def activate  # activates the tool    
                      end 
                    
                      def onMouseMove(flags, x, y, view) 
                         ip = Sketchup;;InputPoint.new
                         ip.pick view, x,y
                         ip = ip.position 
                    
                         if (@state == 0) # Create Wall_group 
                          @my_group = @ent.add_group
                          my_face = @my_group.entities.add_face @pts 
                          my_face.pushpull -10
                          
                          # ip is the input point from the mouse, converted to a 3d point 
                          point = Geom;;Point3d.new ip 
                          new_transform = Geom;;Transformation.new point  
                          @my_group.transformation = new_transform
                          @state = 1
                        end
                        if (@state == 1) # @my_group follow mousemove
                          Sketchup.status_text = "@state = 1 ; Inputpoint; ", ip
                          point = Geom;;Point3d.new ip 
                          new_transform = Geom;;Transformation.new (point)
                          @my_group.transformation =  new_transform
                        end
                    
                        if (@state == 2) # onLMouseButton place @my_group in choosen position
                          Sketchup.status_text = "@state = 2 ; Inputpoint; ", ip 
                          point = Geom;;Point3d.new ip 
                          new_transform = Geom;;Transformation.new (point)
                          @my_group.transformation =  new_transform
                          @ip1 = ip
                          UI.messagebox "that should do it, Honolulu ;) - Press space to exit"
                          @state = 3      
                        end
                         
                      end # onMouseMove
                      
                      def onLButtonDown (flags, x, y, view)
                        if (@state == 1)
                          @state = 2
                        end
                      end # onLButtonDown
                      
                    end # class My_tool
                    #------------------------------------
                    #------------------------------------
                    # Here you activate the defined tool in your program...
                    
                         mytool = My_tool.new 
                         Sketchup.active_model.select_tool mytool
                    
                    

                    Regards RVS ๐Ÿ˜„


                    Get a Ruby

                    1 Reply Last reply Reply Quote 0
                    • T Offline
                      thomthom
                      last edited by 9 Oct 2010, 15:19

                      If you just want to place the a component you can simply SU's use native tool model.place_component

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

                      1 Reply Last reply Reply Quote 0
                      • H Offline
                        honoluludesktop
                        last edited by 10 Oct 2010, 09:50

                        RVS, thanks for help with the snippit. I have another use for it.

                        tt, finally got to it, shoot, that was too easy:

                        my_def = definitions.add "My Selection" my_inst = @master_group.to_component my_def.entities.add_instance(my_inst.definition, my_inst.transformation) my_inst.erase! repeat = false model.place_component my_def, repeat

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

                        Advertisement