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

    Where to start?

    Scheduled Pinned Locked Moved Developers' Forum
    44 Posts 4 Posters 780 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.
    • R Offline
      rumcajs
      last edited by

      @dan rathbun said:

      @rumcajs said:

      Follow the guide and you will be much happier.

      The frustration is from the Interactive guide, because it didn't work in the fully meaning of ruby console. SO I could not check what I did. But I closed the window, and moved.

      1 Reply Last reply Reply Quote 0
      • R Offline
        rumcajs
        last edited by

        @thomthom said:

        I recommend new plugin developers to read this one first: http://www.thomthom.net/thoughts/2012/01/golden-rules-of-sketchup-plugin-development/

        Well, helpful. I found one plugin in my folder, which is in global namespace.

        
        #this part is taken (after a little modification) directly from the script Skin by Darrel Belvin so all credit is his (hope he doesn't mind me posting this)
        def clean_up
        	Sketchup.active_model.start_operation "Clean-up"
        	ss = Sketchup.active_model.selection.collect
        	erasee = []
        	ss.each {|e|
        		if (e.typename=="Edge")
        			if((e.faces.length==0)|| (e.faces.length==2 && e.faces[0].material==e.faces[1].material && e.faces[0].normal.parallel?(e.faces[1].normal)))
        				erasee.push e
        			end
        		end
        	}
        	erasee.each {|e|
        		e.erase! if(e.deleted? == false)
        	}
        	Sketchup.active_model.commit_operation
        	return
        end
        if not (file_loaded? "cleanup.rb")
        	clean = UI.menu("Plugins")
        	clean.add_item("Clean-up") {clean_up}
        end
        
        
        1 Reply Last reply Reply Quote 0
        • R Offline
          rumcajs
          last edited by

          I go through SU examples.

          So Utilities - Create Faces ... utilitiestools.rb

          
          ss = Sketchup.active_model.selection
             
          # Get an Array of all of the selected Edges
          edges = ss.find_all { |e| e.kind_of?(Sketchup;;Edge) }
          
          

          So here the "e" means output of the find_all method, so what the loop produces in the moment of its cycle. I thought that it is definition of the input or some argument for input! But recalled that I asked on it on previous page. It seems to me that it is like loop, similar like .each { |e| e.some.action.here}

          1 Reply Last reply Reply Quote 0
          • Dan RathbunD Offline
            Dan Rathbun
            last edited by

            edges holds the output of the find_all method, which is a new Array of the items that were found.

            |e| is the block parameter list, which is passed into the block by the Ruby keyword yield.
            The number of block parameters can vary from one block method to another.

            This is an example of what the find_all method would look like, if it was written in Ruby (but it is actually written in C.)

            class MyArray
            
              def find_all
                raise(ArgumentError,"no block given!",caller) unless block_given?
                found = []
                self.each {|item|
                  # call the block using yield, passing in item
                  # if the block returns true via yield,
                  # push the item into the found array.
                  found << item if yield(item)
                }
                return found
              end
            
            end
            

            I'm not here much anymore.

            1 Reply Last reply Reply Quote 0
            • thomthomT Offline
              thomthom
              last edited by

              @rumcajs said:

              Well, helpful. I found one plugin in my folder, which is in global namespace.

              
              > if (e.typename=="Edge")
              > 
              

              Not only is it in global namespace - it uses typename to identity the type of entity (which many plugin does because the API docs sets a very poor example.) .typename is very very slow - avoid at all cost! More details: http://www.thomthom.net/thoughts/2011/12/never-ever-use-typename/

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

              1 Reply Last reply Reply Quote 0
              • R Offline
                rumcajs
                last edited by

                @thomthom said:

                Not only is it in global namespace - it uses typename to identity the type of entity (which many plugin does because the API docs sets a very poor example.) .typename is very very slow - avoid at all cost!

                Exactly. I am reading it just in the first link (http://forums.sketchucation.com/viewtopic.php?f=180&t=10142) in the first response in this thread.

                1 Reply Last reply Reply Quote 0
                • Dan RathbunD Offline
                  Dan Rathbun
                  last edited by

                  Use puts statements in the code, to output to the Ruby Console.

                  I'm not here much anymore.

                  1 Reply Last reply Reply Quote 0
                  • Dan RathbunD Offline
                    Dan Rathbun
                    last edited by

                    @rumcajs said:

                    I would like to see what contains @iptemp.

                    It is an Sketchup::InputPoint instance object. See the API dictionary.

                    I'm not here much anymore.

                    1 Reply Last reply Reply Quote 0
                    • R Offline
                      rumcajs
                      last edited by

                      What debug tools and methods can I use to debug method?

                      Example, utilitiestool.rb
                      class TrackMouseTool
                      method onMouseMove

                      
                      @iptemp.pick view, x, y
                      
                      

                      I would like to see what contains @iptemp.

                      Is it possible to show dialog box or pause code?

                      1 Reply Last reply Reply Quote 0
                      • R Offline
                        rumcajs
                        last edited by

                        If I change code of the plugin, will it be refreshed automatically or must I reload the plugin and how?

                        1 Reply Last reply Reply Quote 0
                        • thomthomT Offline
                          thomthom
                          last edited by

                          @rumcajs said:

                          If I change code of the plugin, will it be refreshed automatically or must I reload the plugin and how?

                          Reload it manually.

                          load 'myfile.rb'

                          Though I think Jim created a utility to autoreload after changes where detected. Never used it though as I prefer the manual control.

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

                          1 Reply Last reply Reply Quote 0
                          • R Offline
                            rumcajs
                            last edited by

                            OK. Works. So I tried:

                            @iptemp.pick view, x, y
                            puts @iptemp
                            
                            

                            #Sketchup::InputPoint:0xd0fe6fc

                            So the input point is in hexadecimal format? If I would want to read it, I would need to add method to convert to decimal, right? I tried:
                            puts @iptemp.hex
                            returns error

                            1 Reply Last reply Reply Quote 0
                            • thomthomT Offline
                              thomthom
                              last edited by

                              No - the hex number you see there is the hexadecimal version of the object id. Ruby convention.

                              Refer to the API manual and you find InputPoint.position
                              https://developers.google.com/sketchup/docs/ourdoc/inputpoint#position

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

                              1 Reply Last reply Reply Quote 0
                              • R Offline
                                rumcajs
                                last edited by

                                Ah, now it works.

                                puts @iptemp.position
                                

                                Something I miss in the reference manual. From different languages I am used to see above every method a list of similar or related methods/links.... Is here some similar page which gives such kind of information / organized in different way? Or is this the only source?

                                1 Reply Last reply Reply Quote 0
                                • R Offline
                                  rumcajs
                                  last edited by

                                  What does mean $ is it global variable? I thought it is array, but now I see they use it in different way.

                                  This:

                                  results = inputbox prompts, values, $exStrings.GetString("Cost Estimate")
                                  

                                  What is inputbox, does not look like method of global scope

                                  1 Reply Last reply Reply Quote 0
                                  • thomthomT Offline
                                    thomthom
                                    last edited by

                                    @rumcajs said:

                                    Is here some similar page which gives such kind of information / organized in different way? Or is this the only source?

                                    Each class list all its methods.

                                    List of classes:
                                    https://developers.google.com/sketchup/docs/classes

                                    List of methods:
                                    https://developers.google.com/sketchup/docs/methods

                                    Object Diagram:
                                    https://developers.google.com/sketchup/docs/diagram

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

                                    1 Reply Last reply Reply Quote 0
                                    • thomthomT Offline
                                      thomthom
                                      last edited by

                                      @rumcajs said:

                                      What does mean $ is it global variable? I thought it is array, but now I see they use it in different way.

                                      This:

                                      results = inputbox prompts, values, $exStrings.GetString("Cost Estimate")
                                      

                                      What is inputbox, does not look like method of global scope

                                      $ is global variables, yes. Avoid them.

                                      inputbox is an alias for UI.inputbox defined in sketchup.rb which comes with SketchUp. (I use UI.inputbox simply because of potential problems of relying on the methods in the global namespace.)

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

                                      1 Reply Last reply Reply Quote 0
                                      • R Offline
                                        rumcajs
                                        last edited by

                                        Hm. I see. Sketchup.rb is short, so it will not be problem to remember it. And where is definited UI?

                                        1 Reply Last reply Reply Quote 0
                                        • thomthomT Offline
                                          thomthom
                                          last edited by

                                          @rumcajs said:

                                          And where is definited UI?

                                          That's from the API - defined in C++.
                                          Look to the documentation: https://developers.google.com/sketchup/docs/ourdoc/ui

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

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

                                          Advertisement