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

    How do you make plug-ins for sketchup

    Scheduled Pinned Locked Moved Developers' Forum
    103 Posts 25 Posters 9.0k Views 25 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
      remus
      last edited by

      thats interesting, more experimenting is needed!

      edit: perhaps in the morning. Its getting a bit late now πŸ˜‰

      http://remusrendering.wordpress.com/

      1 Reply Last reply Reply Quote 0
      • B Offline
        BTM
        last edited by

        model = Sketchup.active_model
        selection = model.selection
        #  -  -  -  -  -  -  -  -  -  -  -  -
           selection.each { |entity|
              if entity.typename == "Face"
              UI.openURL "http://www.sketchucation.com/forums/scf/"
           end
        }
        

        πŸ˜‰

        1 Reply Last reply Reply Quote 0
        • Chris FullmerC Offline
          Chris Fullmer
          last edited by

          Well, this is not the problem in question, but a selection will not contain an entity "Curve" for one thing. It contains edges though, and they might belong to a curve. So you can test if e.typename == "Edge" and then if true test if e.curve != false.

          (And this gets back to what Adam was bringing up and Jim also talked about in another post. I think instead of testing if each entity is an edge (which is how I still do it), perhaps test each entity if its part of a curve. (I don't know the best code to do that, but its something to think about).)

          I think that a selection can only hold DrawingElements (which does not include curves). I'm not sure why though.

          Chris

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

          1 Reply Last reply Reply Quote 0
          • B Offline
            BTM
            last edited by

            It probably got overrun by new posts, so here's my original question about translation

            my main issue (which I've been trying to figure out) is how to use the cursor to set the transformation, like the move tool does; click and drag. I thought I saw something on it once, but am still confused.

            1 Reply Last reply Reply Quote 0
            • Chris FullmerC Offline
              Chris Fullmer
              last edited by

              Oh, and BTM, in my opinion, as a fairly new Ruby scripter, making any script that interacts with the mouse is a bit challenging, especially at first. It requires making a class tool, and instantiating the tool, and making good use of methods, including pre-defined methods from the API. I'll try to write up a template for creating a new tool. But that is really a tutorial all of its own. (BTW, I said before I was working on a tutorial for beginning ruby, and its been put on hold because the methods for wiritng a tutorial for SketchUcation are currently not working....so I have to wait for the management to fix it.)

              If possible, I would avoid the mouse controlling the transform idea.

              Chris

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

              1 Reply Last reply Reply Quote 0
              • Chris FullmerC Offline
                Chris Fullmer
                last edited by

                To be more specific, I don't understand how to implement the inferencing system of SU. I have a sfew scripts that use inferencing, but I literally copied and pasted portions of those scripts from the query tool example that comes with SU. If you want to being working with inferencing, check out that tool.

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

                1 Reply Last reply Reply Quote 0
                • J Offline
                  Jim
                  last edited by

                  @adamb said:

                  [Slightly OT]

                  I've always been very careful to use Object#kind_of? rather than Object#class so that code works with any derived classes too. (Rather than just testing for an explicit class).

                  Good idea? Bad idea?

                  Adam

                  It's good when you explode a Group to reject things are not Drawinglements. Sometimes I get Loops in the exploded collection of entities.

                  
                  ents = group.explode
                  ents.reject!{ |e| unless e.is_a? Sketchup;;Drawingelement }
                  
                  

                  Hi

                  1 Reply Last reply Reply Quote 0
                  • J Offline
                    Jim
                    last edited by

                    @chris fullmer said:

                    (And this gets back to what Adam was bringing up and Jim also talked about in another post. I think instead of testing if each entity is an edge (which is how I still do it), perhaps test each entity if its part of a curve. (I don't know the best code to do that, but its something to think about).)
                    Chris

                    Look again at the Selection class, there are a couple methods that can help determine of a selection contains a Curve:

                    .is_curve? and .single_object?

                    Hi

                    1 Reply Last reply Reply Quote 0
                    • Chris FullmerC Offline
                      Chris Fullmer
                      last edited by

                      Here's an amusing illustration of what I mean when I say that I have avoided using the mouse in my scripts because it is complex (for me). Here's my scripts in the order that I've written them:

                      Loose to groups - no mouse interaction.
                      Random Painter - no mouse interaction
                      Greeble 1 and 2 - no mouse interaction
                      Color by Z - no mouse interaction
                      Onscreen Display - my first mouse interaction (inferencing) The code is 95% from the query tool. I still don't undesratnd how parts of it work πŸ˜†
                      Select Lines by Length - no mouse interaction
                      Three Line Tools - mouse interaction (inferencing, still copied from query)
                      Components onto Faces - no mouse interaction
                      Perpendicular Face Tools - mouse interaction (inferencing, still copied from query)
                      Scale and Rotate Multiple - no mouse interaction
                      Label Open Faces - no mouse interaction
                      Shape Bender - Mouse interaction written entirely on my own (select different objects with the mouse), but no inferencing

                      Anyhow, I've written about 12 scripts I've released and all of them avoid mouse input like the plague. The few that do allow for mouse input, the code is largely borrowed from the query tool, and still I don't understand how a few things in the code work πŸ˜„

                      Chris

                      But don't let my inabilities stop you by any means. If you want to learn it, go for it. It will probably make for lots of great threads about implementing inferencing, which the forum could use I think!

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

                      1 Reply Last reply Reply Quote 0
                      • B Offline
                        BTM
                        last edited by

                        Where do I find this "query tool"? The closest thing i can find is comptr.h, and 2 sketchyphysics files

                        1 Reply Last reply Reply Quote 0
                        • Chris FullmerC Offline
                          Chris Fullmer
                          last edited by

                          Jim, I'm a little confused. I thought you would be able to add a curve object to the selection set. But it returns this error:

                          (eval);6;in β€˜add’; wrong argument type (expected Sketchup;;Entity or Array of Sketchup;;Entity)
                          

                          But the API says that "Curve" is a subclass of the Entity class, just like DrawingElement. Why can't I add a curve object directly to the selection?

                          Chris

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

                          1 Reply Last reply Reply Quote 0
                          • Chris FullmerC Offline
                            Chris Fullmer
                            last edited by

                            Oh yea, the quesry tool is kind of hiding. It is in the utilities folder, and inside the utilitiestools.rb file. Starting on line 55.

                            Inside of SU it is under Tools > Utilities > Query Tool

                            But it only does point inference. It does not do all the inferencing you will want - like locking to an axis or anything with axex. Only single points. But its helpful for that,

                            Chris

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

                            1 Reply Last reply Reply Quote 0
                            • B Offline
                              BTM
                              last edited by

                              It's nowheres to be seen on my mac πŸ˜• Checked everywhere, it's just not there. 😐

                              1 Reply Last reply Reply Quote 0
                              • Chris FullmerC Offline
                                Chris Fullmer
                                last edited by

                                You looked in both your plugins folders? It also might be in the tools folder.

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

                                1 Reply Last reply Reply Quote 0
                                • jeff hammondJ Offline
                                  jeff hammond
                                  last edited by

                                  it's in there BTM

                                  utilitiestools.rb is the file name.. inside a folder called utilites which is in the plugins folder.

                                  when i get some more time, i'll show you a neat little finder trick to search for anything (unless of course you already know this and the file really isn't there)

                                  dotdotdot

                                  1 Reply Last reply Reply Quote 0
                                  • B Offline
                                    BTM
                                    last edited by

                                    Ah, found it. I whent right over the utilities folder, and never noticed it πŸ˜†

                                    1 Reply Last reply Reply Quote 0
                                    • jeff hammondJ Offline
                                      jeff hammond
                                      last edited by

                                      a couple examples of using the finder to find things.. it doesn't really fit in this thread but it does show a few things i might use if learning ruby..

                                      first, i try to search for perpendicular_face .. a standard search doesn't show anything but you'll notice i go into my search field and allow for a system search which will look at Macintosh HD... if you check the box then that search field will always remain in the menu (though you still have to use the + then include) .. on top of that, there are all sort of weird things you can search for -- lens aperture, song tempo, used dates etc.. as a side note, system search will also include web history so i can use this to easily find things from web pages i've been to..

                                      after the perpendicular_face example, i do a search for a piece of code (Geom::Vector3d).. you'll notice that it searches inside the files as well and you can select either 'file name' or 'content' .. if i open a file that showed up in the search, i can commandF and the search item is transferred to the apps search field.. makes it easy to find what i'm looking for in the exact location of the file..

                                      after that, i use coverflow on the results (i fit the window to my monitor for this so you can't see everything i'm doing.. just trying to show that i can look at all the rubies full size without actually opening them in an editor)..

                                      mess around with it.. note you can add multiple criteria to narrow the search.. also note you can mix up your searches (for instance, i found the query tool by typing 'query tool sketchup' and utilitestools.rb show up even though that exact wording doesn't appear in the text..
                                      hope this helps.. (and i hope the youtube compression doesn't make this too impossible to understand πŸ˜„ )

                                      [flash=700,420:2yjy0fg6]http://www.youtube.com/v/iM2qMaAvNpQ&hl=en&fs=1&rel=0&color1=0x006699&color2=0x54abd6&border=1[/flash:2yjy0fg6]

                                      dotdotdot

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

                                        A little script to draw the crudest catenary curve you've ever seen πŸ‘

                                        require "sketchup.rb"
                                        
                                        def y (xpos)
                                        
                                        sag = 2
                                        x=xpos
                                        
                                        (Math.cosh ((x/sag)))*sag
                                        
                                        end
                                        
                                        def cat_curve
                                        
                                        model = Sketchup.active_model
                                        entities = model.entities
                                        
                                        pt1 = [10,0,(y (10))]
                                        pt2 = [(20/3),0,(y ((20/3)))]
                                        pt3 = [(10/3),0,(y ((10/3)))]
                                        pt4 = [0,0,(y (0))]
                                        pt5 = [(-10/3),0,(y ((-10/3)))]
                                        pt6 = [(-20/3),0,(y ((-20/3)))]
                                        pt7 = [-10,0,(y (-10))]
                                        
                                        points = [pt1,pt2,pt3,pt4,pt5,pt6,pt7]
                                        
                                        catcurve = entities.add_curve (points)
                                        
                                        end
                                        
                                        UI.menu("PlugIns").add_item("Catenary Curve") {
                                          
                                          cat_curve
                                        }
                                        
                                        

                                        http://remusrendering.wordpress.com/

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

                                          @chris fullmer said:

                                          Jim, I'm a little confused. I thought you would be able to add a curve object to the selection set. But it returns this error:

                                          (eval);6;in β€˜add’; wrong argument type (expected Sketchup;;Entity or Array of Sketchup;;Entity)
                                          

                                          But the API says that "Curve" is a subclass of the Entity class, just like DrawingElement. Why can't I add a curve object directly to the selection?
                                          Chris

                                          To test if a given edge is part of a curve and then add all of those to the selection use something like

                                          selection.add(e.curve.edges) if e.typename=="Edge" and e.curve
                                          

                                          assuming you have pre-defined some of those variables !
                                          To add all of a given curve's edges to a selection use something like

                                          ### assuming crv is known to be a 'curve'
                                          selection.add(crv.edges)
                                          

                                          edge.curve returns either a Curve or ArcCurve object curve or arc/circle, and edge.curve.edges returns all of the 'curve's' edges... Matt's recent 'real_typename' Ruby adds an extra method to DrawingElement Edge to return Curve, Arc or Circle for those types - otherwise 'normal' typename...
                                          It might be a useful tester ?

                                          TIG

                                          1 Reply Last reply Reply Quote 0
                                          • Chris FullmerC Offline
                                            Chris Fullmer
                                            last edited by

                                            Remus, that is in fact the crudest catenary curve I've ever seen! πŸ˜„ Good job.

                                            @TIG - sure we can test an edge to see if its part of a curve. I'm specifically asking why you can't add a curveobjec to a selection. If you try, it returns that error I posted, stating it is expecting an Entity class object. But a curve is a subclass of Entity. So its error does not seem to be telling the truth or something. Does that mean they have specifically blocked the ability to add curve's and arccurves? OR did they really mean that it is expecting a DrawingElement?

                                            Chris

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

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

                                            Advertisement