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

    Mac and Windows 'New Model' differences...

    Scheduled Pinned Locked Moved Developers' Forum
    17 Posts 4 Posters 1.5k Views 4 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.
    • D Offline
      driven
      last edited by driven

      I'm looking at ways to optimise some code and have made a couple of methods that both work on a mac...

      however, I had reports from testers that neither work on a PC...

      Is it possible to have either work on a PC?

      the example writes a skp to your Desktop, unless you change the path...

      to run, paste code into RC and hit return...

      then type auto_create and hit return...

      # Test file is 5MB,  first is quicker if selection is empty?...
      def empty_selection
      	new_skp = File.expand_path("~/Desktop/john_test1.skp")
      	begin
               # original stays open and new opens in front [0.14629]
      	  Sketchup.active_model.save_copy(new_skp)
      	rescue # for un-saved original
                # original closes and new opens on mac [1.222455]
      	  Sketchup.active_model.save(new_skp)
      	end
              # next is not needed for either save or save_as on mac
              # Sketchup.open_file(new_skp) #with save_copy() original stays open [1.920228]
              # just show the ruby works in the new window...
      	Sketchup.active_model.rendering_options['BackgroundColor'] = 'red'
      end
      
      # faster than collecting and deleting unwanted entities on large complex models...
      # I have I mac cocoa utility to avoid using .send_action(), 
      # but this is a little faster and 'should' be cross platform...
      def with_selection
      	new_skp = File.expand_path("~/Desktop/john_test2.skp")
      	Sketchup.send_action('selectSelectionTool;') # copy needs a trigger on mac for copy to work
      	Sketchup.send_action('copy;')
      	Sketchup.send_action('newDocument;')
      	Sketchup.send_action('pasteInPlace;')
      	sel = Sketchup.active_model.selection
      	view = Sketchup.active_model.active_view
      	view.zoom(sel)
             # original stays open time depends on the selection size...
      	Sketchup.active_model.save(new_skp)
              # just show the ruby works in the new window...
      	Sketchup.active_model.rendering_options['BackgroundColor'] = 'green'
      end
      
      def auto_create
      	t1 = Time.now
      	sel = Sketchup.active_model.selection
      	sel.empty? ? empty_selection ; with_selection
      	p time = Time.now - t1
      	UI.messagebox(time)
      end
      
      

      when I look at other examples I can't spot what I'm missing...

      john

      learn from the mistakes of others, you may not live long enough to make them all yourself...

      1 Reply Last reply Reply Quote 0
      • G Offline
        Garry K
        last edited by

        auto_create
        Error: #<NameError: undefined local variable or method sel' for main:Object> <main>:26:in with_selection'
        <main>:36:in auto_create' <main>:in <main>'
        SketchUp:1:in `eval'

        1 Reply Last reply Reply Quote 0
        • D Offline
          driven
          last edited by

          cheers for testing Garry, I chopped the bit out of a bigger plugin and missed re-defining sel for the new model

          i.e. sel = Sketchup.active_model.selection

          I updated the example code...

          did it produce a model?

          before fixing that, on the mac I get the new skp, then the sel error shows in RC...

          i.e. it doesn't stop the new skp happening...

          john

          learn from the mistakes of others, you may not live long enough to make them all yourself...

          1 Reply Last reply Reply Quote 0
          • sdmitchS Offline
            sdmitch
            last edited by

            empty_selection works on PC and SU2014.

            with_selection seems to work but not really. Perhaps because I can't find the 'copy:','newDocument:', and 'pasteInPlace:' .send_action options in the API.

            However the 'newDocument:' option must work since I end up with an empty untitled model.

            Also 'sel' needs to be passed to the with_selection method or changed to @sel.

            Nothing is worthless, it can always be used as a bad example.

            http://sdmitch.blogspot.com/

            1 Reply Last reply Reply Quote 0
            • D Offline
              driven
              last edited by

              @sdmitch said:

              empty_selection works on PC and SU2014.

              that's good news, maybe I had another glitch in the full plugin...

              @unknownuser said:

              with_selection seems to work but not really. Perhaps because I can't find the 'copy:','newDocument:', and 'pasteInPlace:' .send_action options in the API.

              they should all exist, but I may need to use the numeric values on a PC?
              I recall, checking them all for Dan and thought PC's could use either...

              @unknownuser said:

              However the 'newDocument:' option must work since I end up with an empty untitled model.

              @unknownuser said:

              good start...

              Also 'sel' needs to be passed to the with_selection method or changed to @sel.

              you need to re-define sel or the @sel would refer to the original skp not the new one [on mac at least]...

              I did update the code for that, did it still not work?

              thanks for testing...
              john

              learn from the mistakes of others, you may not live long enough to make them all yourself...

              1 Reply Last reply Reply Quote 0
              • sdmitchS Offline
                sdmitch
                last edited by

                I had already made the 'sel' change in my copy of the code.

                Like before, the file created on the desktop is the same for with_selection and empty_selection. With_selection leaves me with an empty Untitled model.

                I get no errors output to the RC.

                Nothing is worthless, it can always be used as a bad example.

                http://sdmitch.blogspot.com/

                1 Reply Last reply Reply Quote 0
                • D Offline
                  driven
                  last edited by

                  does finding the send actions work the same on a PC?

                  i.e. if I set 'copy' as a Shortcut, and then run Sketchup.get_shortcuts the wording returned can be used as a send_action string?

                  john

                  learn from the mistakes of others, you may not live long enough to make them all yourself...

                  1 Reply Last reply Reply Quote 0
                  • D Offline
                    driven
                    last edited by

                    I removed the previous send_action()'s but added in Sketchup.send_action('makeGroup:') which should work on both platforms...

                    on a mac I get this, does it work the same on a PC?

                    auto_create.gif

                    ##########################################################################################
                    # first is quicker if selection is empty?...
                    def empty_selection
                    	new_skp = File.expand_path("~/Desktop/john_test1.skp")
                    	begin
                    	  Sketchup.active_model.save_copy(new_skp) # [0.14629]
                    	rescue # for un-saved original
                    	  Sketchup.active_model.save(new_skp) # original closes [1.222455]
                    	end
                    	Sketchup.open_file(new_skp) #with save_copy() original stays open [1.920228]
                    	Sketchup.active_model.rendering_options['BackgroundColor'] = 'red'
                    end
                    
                    # faster than collecting and deleting unwanted items...
                    def with_selection
                    	new_skp = File.expand_path("~/Desktop/john_test2.skp")
                     	sel = Sketchup.active_model.selection
                    	ins = sel[0].to_component
                    	defn = ins.definition
                    	# named only to check if it's been undone...
                    	defn.name = "Explode Me Later"
                    	defn.save_as(new_skp)
                    	# revert original
                    	3.times {Sketchup.undo}
                    	Sketchup.open_file(new_skp) # original stays open time depends on the selection size...
                    	Sketchup.active_model.rendering_options['BackgroundColor'] = 'green'
                    end
                    
                    def auto_create
                    	t1 = Time.now
                    	sel = Sketchup.active_model.selection
                    	sel.empty? ? empty_selection ; with_selection
                    	p time = Time.now - t1
                    	UI.messagebox(time)
                    end
                    
                    

                    john

                    learn from the mistakes of others, you may not live long enough to make them all yourself...

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

                      Your undocumented:
                      Sketchup.send_action("makeGroup:")
                      doesn't work on [my] PC - BUT:
                      Sketchup.send_action(21182)
                      does work on [my] PC [but of course that doesn't work on MAC !]

                      But if you are working with creating a group from a Selection, then you can use the cross-platform API methods, thus:
                      group = Sketchup.active_model.active_entities.add_group( Sketchup.active_model.selection.to_a ); Sketchup.active_model.selection.add( group )
                      which mimics those other platform specific 'send_actions' on either OS...

                      TIG

                      1 Reply Last reply Reply Quote 0
                      • G Offline
                        Garry K
                        last edited by

                        auto_create
                        0.12499
                        1

                        I get a big red screen - that is all
                        My default template is set to mm with a precision of 0.001

                        1 Reply Last reply Reply Quote 0
                        • D Offline
                          driven
                          last edited by

                          cheers Tig, I may have gotten there eventually...

                          this works on the mac as suggested...

                          do I need to close the original on a PC for the new one to open with geometry and green background?

                          it's driving nuts as every version I've tried runs on a mac, and each one has been faster that the last...

                          # faster than collecting and deleting unwanted items...
                          def with_selection
                          	new_skp = File.expand_path("~/Desktop/john_test2.skp")
                           	sel = Sketchup.active_model.selection
                                  group = Sketchup.active_model.active_entities.add_group( sel.to_a )
                                  Sketchup.active_model.selection.add( group ) if sel.length > 0
                          	ins = group.to_component
                          	defn = ins.definition
                          	# named only to check if it's been undone...
                          	defn.name = "Explode Me Later"
                          	defn.save_as(new_skp)
                          	# revert original
                          	3.times {Sketchup.undo}
                          	Sketchup.open_file(new_skp) # original stays open time depends on the selection size...
                            # re-define for new skp...
                          	Sketchup.active_model.rendering_options['BackgroundColor'] = 'green'
                          end
                          

                          learn from the mistakes of others, you may not live long enough to make them all yourself...

                          1 Reply Last reply Reply Quote 0
                          • D Offline
                            driven
                            last edited by

                            @Garry, the template shouldn't matter...

                            I just can't figure out why you don't get the geometry...

                            This is just a tiny part of a working mac plugin that I'm now porting to PC...

                            on the mac it can grab 100 mixed items from a 1000 item file and cleanly add them to a new model...

                            one test file took 6 hrs to process and delete the 900 unwanted entities, where this take seconds...

                            john

                            learn from the mistakes of others, you may not live long enough to make them all yourself...

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

                              On a PC an instance of SketchUp is opened for separate for each SKP.
                              On a MAC one instance of SketchUp opens all SKPs.
                              So on a PC, if you you use:
                              Sketchup.open_file("C:/users/tig/desktop/a.skp")
                              its opens that SKP file, BUT closes the current one !
                              But you could use:
                              UI.openURL("file:///#{full_path_to_skp}")
                              which, on a PC, will open the specified SKP in a new instance of SketchUp [and it'll probably work on a MAC, but then it'll be using the same SketchUp]...

                              TIG

                              1 Reply Last reply Reply Quote 0
                              • D Offline
                                driven
                                last edited by

                                @tig said:

                                ...But you could use:
                                UI.openURL("file:///#{full_path_to_skp}")
                                which, on a PC, will open the specified SKP in a new instance of SketchUp [and it'll probably work on a MAC, but then it'll be using the same SketchUp]...

                                it works exactly the same as open_file on a mac...

                                you can pass the new model to the next ruby method...

                                on a PC, I assume a new instance would need manual intervention to carry on to step 2 of any ruby script?

                                Are there ways around that?

                                I'm starting to see why 'component_edit_window' has so many observers...

                                john

                                learn from the mistakes of others, you may not live long enough to make them all yourself...

                                1 Reply Last reply Reply Quote 0
                                • D Offline
                                  driven
                                  last edited by

                                  @tig said:

                                  ...
                                  So on a PC, if you use:
                                  Sketchup.open_file("C:/users/tig/desktop/a.skp")
                                  its opens that SKP file, BUT closes the current one !
                                  ...

                                  on re-reading this and it may be all I need...

                                  i.e. opens the new_skp [containing the selection] in the current ruby session...

                                  Is that what happens?

                                  keeping the original open isn't a requirement, in fact I'm wanting to preserve intact, and run my actual tool which is destructive on the copy/sub-set...

                                  john

                                  learn from the mistakes of others, you may not live long enough to make them all yourself...

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

                                    Yes, opening a second SKP in the same SketchUp preserves the current Ruby settings from the first SKP.

                                    If you open up a second SketchUp, then the first SKP's Ruby set up is potentially in accessible.
                                    Of course, in the first SKP you could write some 'defaults' out to SketchUp [i.e. into the PC Registry], and read those back in, while inside the second SKP, but you then need to load/run some code ?

                                    TIG

                                    1 Reply Last reply Reply Quote 0
                                    • D Offline
                                      driven
                                      last edited by

                                      cheers Tig,

                                      the plugin runs my 'selector' tool after new_skp has been cleaned up...

                                      the 'selector' can be scaled, rotated or moved before running the cuts...

                                      any solids remain solids afterwards...

                                      sixSectoins.gif

                                      I need a PC version to attract more testers...

                                      john

                                      learn from the mistakes of others, you may not live long enough to make them all yourself...

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

                                      Advertisement