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.
    • C Offline
      Click Draw
      last edited by

      Is Ruby on Rails the same as Ruby?

      Thanks,
      Jeff

      Have I mentioned how much of a laugh I get out of some of the Signatures on here!

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

        Rails is like an extension of regular ruby. So Ruby is the main language, and rails is a "ruby gem". Its still the same language, but it adds more features and functionality especially developed for web developers (I think).

        Chris

        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

          How about a "heal" script that joins broken, but co-linear edges?

          Hi

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

            I think all those suggestions can be written in 10 lines of code or less. So they are good compact examples too.

            Some of the more efficient programmers might be able to pull them off in one or two lines, but for me 10 or less would be good. It might take more than that too of course.

            Chris

            EDIT: 10 lines doesn't include any menu system implemenetation. Since I write everything in Jim's WebConsole, there's no need to make a menu for it until I'm ready to save it as a ruby file.

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

            1 Reply Last reply Reply Quote 0
            • C Offline
              Click Draw
              last edited by

              So literature to buy if one was to, Ruby or ruby on rails? Sounds like ruby on rails would be the next step or more advanced than ruby?
              Thanks,

              Jeff

              Have I mentioned how much of a laugh I get out of some of the Signatures on here!

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

                Rails is not Ruby. Rails is a web application framework written in Ruby. Forget about Rails if you're interested in Ruby for SketchUp.

                You can't go wrong with the Pickaxe book. However, I don't believe you need to purchase anything as there is plenty of material online to get quite in-depth.

                @click draw said:

                So literature to buy if one was to, Ruby or ruby on rails? Sounds like ruby on rails would be the next step or more advanced than ruby?
                Thanks,

                Jeff

                Hi

                1 Reply Last reply Reply Quote 0
                • C Offline
                  Click Draw
                  last edited by

                  Gotcha, thank you. Good advise.

                  Cheers,

                  Jeff

                  Have I mentioned how much of a laugh I get out of some of the Signatures on here!

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

                    @chris fullmer said:

                    pushpull all faces in the model

                    😞 AAHHHHH!!!! It took me HOURS to find the typename function!!!!!!!!!!!!!!!!!!! 😠
                    ...but at least I know now 😐

                    model = Sketchup.active_model
                    entities = model.active_entities
                    #  -  -  -  -  -  -  -  -  -  -  -  -
                    entities.each { |entity| 
                       if entity.typename == "Face"
                       entity.pushpull 10
                       end
                    }
                    
                    

                    (WHY can't it be easier to find things on the sketchup ruby API list????)
                    Also, it gives weird, unexpected results sometimes: it seems to pushpull the new faces it makes too ❓

                    1 Reply Last reply Reply Quote 0
                    • AdamBA Offline
                      AdamB
                      last edited by

                      [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

                      Developer of LightUp Click for website

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

                        Awesome!

                        My theory on why it pushpulls some new faces is because it is going through .each entitiy in the entities list. Well, its a dynamic list of the entities in the model, so as soon as you pushpull a face, it creates new faces and adds them somewhere to that entities list. It might be to a part of the list the it has already processed, so it won't do those faces. Or they might get added towards the end of the list to a part that has not yet been processed, so it will pushpull those when it reaches them.

                        The way to counter that is instead of pushpulling all faces as you find them, add them to an array. Then once you've gone through all the entities and found all the faces, then run through the faces array and pushpull them.

                        Another check you might want to add is a vildity check to make sure the face you are about to pushpull is valid. Say you have more intricate geometry with original faces facing eachother. Then if one gets pushpulled first to the exact distance that it overlafs the other face, you might very vell end up deleting the other face, and it will give an error when you try to pushpull it. So if you do something like

                        faces.each do |face| face.pushpull( 100 ) if face.valid? end

                        Then it will skip faces that have been deleted in the proces of pushpulling other faces.

                        And the API gets much easier to work with after a while. I promise. Just for fun, read through the methods in a cuple of classes everyday. And re-read them often. Its helpful.

                        Well done,

                        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

                          I have no idea, I'm just learning the sketchup API; maybe Chris will come by and give you his input.

                          ... Anyways, now I'm trying to figure out how to make a transformation tool like the move tool. Any tips?

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

                            @unknownuser said:

                            I have no idea, I'm just learning the sketchup API; maybe Chris will come by and give you his input.

                            Oh goodness, I don't know that. Adam is part of the brains around here. I was hoping to learn from the responses from one of the other programmers. I'm just a hack, I really know very little about the technical ins and outs. Jim posted an interesting idea that I think is related to the question though. It can be found here:

                            301 Moved Permanently

                            favicon

                            (www.sketchucation.com)

                            @unknownuser said:

                            ... Anyways, now I'm trying to figure out how to make a transformation tool like the move tool. Any tips?

                            Transformations are still the bane of my life. Little by little I feel like I'm getting control of them, but that is only after a few rather involved transformation scripts. I think I keep writing them because I'm a glutton for punishment.

                            The idea is that you first create a transformation object. You then apply that to what you want to transform. There are lots of ways to make transformation objects. And different types of entities want to be transformed differently.

                            For a simple move, start with just moving whatever is selected. Make it so you select geometry, then run the script and it moves the geometry. Easy enough.

                            1. define the selection to move
                              selection = Sketvhup.active_model.selection
                            2. Define the transformation. It will be a translation transformation. this is the example in the API:

                            @unknownuser said:

                            vector = Geom::Vector3d.new 0,1,0
                            t = Geom::Transformation.translation vector

                            The translation transformation needs a vector to determine how to move your object. The vector in the example is 1 unit on the y axis. You can make it 100 units on the y axis, 10 on x, and -200 on z. That would be [10,100,-200], for example. And it would move your selection from where it sits, that distance, on each axis.
                            3. Apply that transformation to your selection.
                            t = Geom::Transformation.new([10,100,-200]) entities.transform_entities(t, selection)

                            I have not tested the code there might be a glitch or two, but I think this will get you started.

                            Chris

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

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

                              A complete rip off of BTMs code:

                              model = Sketchup.active_model
                              entities = model.selection
                              #  -  -  -  -  -  -  -  -  -  -  -  -
                              entities.each { |e| 
                                 if e.typename == "Face"
                                 e.pushpull 10
                                 end
                              }
                              

                              http://remusrendering.wordpress.com/

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

                                then change it around and make it erase all faces instead of pushpulling them πŸ˜„

                                Chris

                                Edit: you literally just copied and pasted, awesome!

                                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

                                  That's good, but 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.

                                  *I started writing this before remus's post. I see you used the 'selection' method, I guess that would fix the whole pushpull-resulting-faces issue I had.(that's what they're called, methods, right? I can never remember...)

                                  *I started that last part before Chris posted πŸ˜’ and Chris, why won't it work to just replace e.pushpull 10 with e.clear! ?

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

                                    ...but I DID manage to get it to reverse faces πŸ˜‰

                                    model = Sketchup.active_model
                                    selection = model.active_entities
                                    #  -  -  -  -  -  -  -  -  -  -  -  -
                                       selection.each { |entity|
                                          if entity.typename == "Face"
                                          entity.reverse!
                                       end
                                    }
                                    

                                    Why does reverse! work, but not clear! ?

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

                                      give em some credit chris, i had to type 'selection' as well πŸ˜„

                                      http://remusrendering.wordpress.com/

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

                                        πŸ˜„

                                        .clear! will empty an array, it does not erase anyhing from the model. Glad you found the erase! method.

                                        You can also go through and put everything to erase into an array of entities, then use

                                        entities.erase_entities my_array_of_entities

                                        to delete them all in one shot. Apparently some people have ran into bugsplats when erasing entities one at a time like you've done in your example.

                                        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

                                          ...Nevermind. I found in the parent directory; erase! 🀣( How didn't I notice that?)

                                          model = Sketchup.active_model
                                          selection = model.active_entities
                                          #  -  -  -  -  -  -  -  -  -  -  -  -
                                          selection.each { |entity|
                                          if entity.typename == "Face"
                                          entity.erase!
                                          end
                                          }
                                          
                                          1 Reply Last reply Reply Quote 0
                                          • Chris FullmerC Offline
                                            Chris Fullmer
                                            last edited by

                                            @remus said:

                                            give em some credit chris, i had to type 'selection' as well πŸ˜„

                                            Heh, I didn't notice that you switched it around to use the selection set instead of all entities. Well done πŸ˜„ Now make it smart enough to use the selection set if it exists, and if not, use all entities.

                                            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