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

    New to Ruby and sketchup API, need some clarifications

    Scheduled Pinned Locked Moved Developers' Forum
    9 Posts 2 Posters 380 Views 2 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.
    • V Offline
      vtikka
      last edited by

      Hi All,

      I am new to Sketch up plugin development and also new to Ruby. I have experience with writing plugins for Autodesk products and other CAD platforms.

      I want to do something very simple like getting distance between points(similar to tap measure tool). I took the code from the LineTool example and able to get an understanding of its inner workings. My dilemma is how to get the distance from the Tool class to my wrapper class when user is done picking two points or hits cancel.

      Can I add some kind of observer when the tool is deactivated and read the length from the Tool class member variable?

      Even better will API let me use the Tape measure command from my code ?

      My second question is,
      from reading the API I see that you can have only one glue plane per component, is possible to have multiple glue plans for same components so that I can attach multiple components to a component.

      Thanks in advance.
      Tik.

      1 Reply Last reply Reply Quote 0
      • jolranJ Offline
        jolran
        last edited by

        There is a Tutorial here about pickhelp if that helps.

        http://sketchucation.com/forums/viewtopic.php?f=180&t=30232&p=450376&hilit=pickhelper#p450376

        To second question.

        You do mean glue to face? Only 1 face per component I'm afraid.

        If I'm wrong about this I will get very upset πŸ˜„

        However you can glue multiple components to 1 face. So maybe you can find a way
        to work things around in different way.


        2comps.jpg

        1 Reply Last reply Reply Quote 0
        • jolranJ Offline
          jolran
          last edited by

          I would like to add that different hierarchy's can be a solution to solve problem 2 maybe?

          For ex:


          compshierch.jpg

          1 Reply Last reply Reply Quote 0
          • V Offline
            vtikka
            last edited by

            @jolran said:

            I would like to add that different hierarchy's can be a solution to solve problem 2 maybe?

            For ex:

            Thanks for pointing me in the right direction, i will take a look at the pickhelper class. I like idea of creating a hierarchy of components to make them work there. Once again thanks for the help.

            Tik.

            1 Reply Last reply Reply Quote 0
            • jolranJ Offline
              jolran
              last edited by

              Glad to help!

              For gluebehavior you can have a look in my code in "Hatchfaces".
              (I don't know of any other scripts using that method.. πŸ˜• )

              BUT! be adviced, I'm novice programmer so there might be lack of style and
              best practices in there.

              1 Reply Last reply Reply Quote 0
              • V Offline
                vtikka
                last edited by

                @jolran said:

                Glad to help!

                For gluebehavior you can have a look in my code in "Hatchfaces".
                (I don't know of any other scripts using that method.. πŸ˜• )

                BUT! be adviced, I'm novice programmer so there might be lack of style and
                best practices in there.

                I am very new to Ruby programming as well. I am having very hard time with structuring my code. Here is a small example related to one of my problems. I created a component with some constraints and place this component in the model. Before placing the component, I want to get the length of the component by clicking two points in SU and use that length for my component length.

                To keep my code clean I am trying to separate my class into following folders or lets say module

                Module 1:- this has the UI related classes like my toolbar and commands

                Module 2:- this is supposed to have all the "Sketch up" api methods.

                Module 3:- In this module I want to keep all my components related classes.

                And this is how I always structured my plugin code in AutoCAD. With sketch up I want to do the same way but I am having hard with separation of code. In my API module I want to have a function lets say "get_length" which will call the tool class which does the mouse tracking etc and returns a length back when user is done picking two points or hits cancel. So far I have a class which is doing every thing i want to do related to getting the length. Only problem I am having is passing that length back to my api module when user is done. I am not sure how to get that length back, on the other hand I think I am over complicating this because of my lack of SU api knowledge.

                Here is code snippet from my API class.

                
                class Aqx_api
                	def self.getActiveModel
                		return Sketchup.active_model
                	end
                
                        def self.getLength
                		aqxGetLength = Aqx_Get_Length.new
                		getActiveModel.select_tool aqxGetLength				
                	end
                end
                
                # Class for getting the length which is based LineTool class from plugin examples.
                
                class Aqx_Get_Length    
                                
                       # This class has code from LineTool. So I am not pasting every thing here.
                end
                
                
                1 Reply Last reply Reply Quote 0
                • jolranJ Offline
                  jolran
                  last edited by

                  I will be careful with givin codehelp, every time I do some guru come to the rescue and override my faulty advice. πŸ˜„

                  Anyway, some ideas. Use if you like..

                  Unless you are making a Tool you don't really have to use Classes at all. Remember Sketchup API has already built in Classes. So you can make use of them. As long as you wrap your code inside modules.
                  But you do mention your want to build a tool. So you must then use a Class..

                  I havent programed any Tool yet so I standby and let someone else give you pointers about
                  that.
                  BUT!, be careful with using codesnippets from the API. They are supposed to be poorly written, and sometimes even false. Same goes for some of the old Google provided plugins that reside in the pluginfolder.

                  If I was you I would rather download a few plugin that reminds of what you want to do, from some of the more experienced experts around here. And have a poke around.

                  A good idea, (if you havent), is to download some of the Ruby code editors. With wich you can try snippets directly inside Sketchup. And also reload scripts.

                  There is also "Automatic Sketchup"(ebook), wich is a good startingpoint about using the API.
                  A bit old, though..
                  But it might help speed up the progress since you already have programming experience.

                  1 Reply Last reply Reply Quote 0
                  • V Offline
                    vtikka
                    last edited by

                    @jolran said:

                    If I was you I would rather download a few plugin that reminds of what you want to do, from some of the more experienced experts around here. And have a poke around.

                    A good idea, (if you havent), is to download some of the Ruby code editors. With wich you can try snippets directly inside Sketchup. And also reload scripts.

                    There is also "Automatic Sketchup"(ebook), wich is a good startingpoint about using the API.
                    A bit old, though..
                    But it might help speed up the progress since you already have programming experience.

                    Thanks for your thoughts and suggestions. I tried few different IDEs including eclipse and others Ruby editors and ended up settling with NotePad ++ because that is the only IDE that is working with SketchUp bridge plugin. I have already downloaded "Automatic Sketchup" ebook and it has been a great help so far.

                    I am looking at different plugin's code to get an understanding of code structuring etc. From your experience is it a good idea to use core ruby classes with Sketchup and I am not sure how it will effect the working of plugin on Macs.

                    Tik

                    1 Reply Last reply Reply Quote 0
                    • jolranJ Offline
                      jolran
                      last edited by

                      Notepad ++ is a good choice.
                      It's quite used around here I think. I use it to.
                      But I don't use bridge. I reload my scripts having robycode editor open all the time during developping. Can't remember why I do it this way 😳
                      Just letting you know there is that option to.

                      @unknownuser said:

                      From your experience is it a good idea to use core ruby classes with Sketchup and I am not sure how it will effect the working of plugin on Macs

                      (Like I said. My experience is poor, so don't take what I have written as solid good advice.
                      I must stress that. I just jump in and ask questions or give advice when maybe I should
                      keep my mouth shut. πŸ˜„ )

                      At some point you must use the API ? Doesent matter if youre on Mac or not.

                      What I meant was that if there already exist a method in the API, one should use it.
                      Most likely it will be a faster method then what you will create in Ruby.

                      Automatic Sketchup is really good for getting grasp of transformations and such. But you should really poke around other peoples scripts to get a feel of how to do things..

                      http://sketchucation.com/forums/viewtopic.php?f=180&t=25305

                      There are some recent performance tips here. And a few things to avoid.

                      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