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

    Plugin(export attributes to csv)

    Scheduled Pinned Locked Moved Developers' Forum
    16 Posts 4 Posters 819 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.
    • J Offline
      Jim
      last edited by

      The error message is correct - export2csv is not a variable or function - it is never defined. You get the same error if you enter random characters in the Ruby Console.

      Enter Export2cvs.new to start the plugin from the Ruby Console (the same as how it is executed from the menu and Toolbar.)

      Hi

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

        Also, the Array class already has a .dot method - no need to add one to the Geom::Point3d class.

        http://code.google.com/apis/sketchup/docs/ourdoc/array.html#dot

        In fact, it is best not to add or change methods of any of the API classes because those changes may cause other plugins to fail, or worse - to have subtle errors which may go undetected.

        Hi

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

          @jim said:

          The error message is correct - export2csv is not a variable or function - it is never defined. You get the same error if you enter random characters in the Ruby Console.

          Enter Export2cvs.new to start the plugin from the Ruby Console (the same as how it is executed from the menu and Toolbar.)

          ...OR alternatively you could make a 'shortcut' method
          def export2cvs(); Export2cvs.new(); end
          outside of the Export2cvs class and then typing export2cvs will also run the tool...

          TIG

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

            @unknownuser said:

            ...outside of the Export2cvs class

            You don't want to do that either. Adding a top-level method adds it to the look-up chain for all Ruby objects. So there is a minute chance that if another dev happens to have a export2csv method and makes a mistake (a typo, for example) it is possible that the top-level method gets found and executed instead. This can occur even if the other dev's method is correctly namespaced.

            Hi

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

              @jim said:

              @unknownuser said:

              ...outside of the Export2csv class

              You don't want to do that either. Adding a top-level method adds it to the look-up chain for all Ruby objects. So there is a minute chance that if another dev happens to have a export2csv method and makes a mistake (a typo, for example) it is possible that the top-level method gets found and executed instead. This can occur even if the other dev's method is correctly namespaced.

              I know it IS inadvisable to add new methods directly to the top-level, BUT even the API Ruby Examples show this way... so IF this guy is making a script for limited use and he has few other scripts loading then he's unlike to have a clash... BUT perhaps a less common name would be safer, AND of course even the class itself Export2csv.new() might have been used by someone else too... so then it'd be best to have a module holding that class, as it would then be extra-extra safe ! Then you'd have to type TetsuyahishidaTools::Export2csv.new(), BUT then it is very-very unlikely to have been duplicated by anyone else!!
              Simply use a module to hold the class like this...

              module TetsuyahishidaTools
                class Export2csv
                  def initialize()
                    #...
                  end#methods
                end#class
                ###
                class Export2tsv ### another Tool!
                  #...
                end#class
              end#module
              

              This way you can have several tools under the 'TetsuyahishidaTools' module...

              PS: Please remove me [(c) TIG] as the 'blame' for this script in the header 😉

              TIG

              1 Reply Last reply Reply Quote 0
              • T Offline
                tetsuyahishida
                last edited by

                Thank you for your reply.

                jim
                The user and he said typing"export2csv.new" solved the problem.
                He was typing "export2csv"

                TIG
                I've immedeately modified the authority. Sorry about my insensitiveness.

                Still I got three questions

                First, does "::"of "TetsuyahishidaTools::Export2csv.new()"
                stands for scope resolution operator?If not, what does it stand for?

                Second, Why does the "TetsuyahishidaTools Module" have to be a "Module"?
                Is it because in Ruby, a class can only inherit from a single other class?
                Or something about nesting rule?

                Third, are there any way to do the same thing using "include"?

                Sorry for my poor English and ruby skill.
                Best regards.

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

                  @tetsuyahishida said:

                  First, does "::"of "TetsuyahishidaTools::Export2csv.new()"
                  stands for scope resolution operator?

                  YES

                  I'm not here much anymore.

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

                    @tetsuyahishida said:

                    Second, Why does the "TetsuyahishidaTools Module" have to be a "Module"?

                    Because an instance of class Module, can only be a singleton instance, meaning only ONE copy of the code it encloses, is needed.
                    Think about it. Within your outermost namespace (module), which should be your unique namespace (your company, etc.) you will define nested objects, both of class Class and class Module, and each of those only needs to be defined ONCE.

                    @tetsuyahishida said:

                    Is it because in Ruby, a class can only inherit from a single other class?

                    No. But for your info... class Class, is actually a direct child subclass of class Module, so objects of class Class, will inherit some methods from their superclass (class Module.)

                    Also.. what most people do not realize, is that when you define a module, like ...

                    module SomeCode
                      # method definitions, etc.
                    end
                    

                    .. that the Ruby parser actually instantiates an instance of class Module like this ...

                    SomeCode = Module.new do |mod|
                      # method definitions, etc.
                    end
                    

                    ... but it's actually done by C-side function calls.

                    I'm not here much anymore.

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

                      @tetsuyahishida said:

                      Third, are there any way to do the same thing using "include"?

                      Only module instances can be mixed-in using the include or extend methods... BUT these 'mixin modules' can be mixed into other modules, classes, or instance objects.

                      I'm not here much anymore.

                      1 Reply Last reply Reply Quote 0
                      • T Offline
                        tetsuyahishida
                        last edited by

                        Dan Rathbun
                        Thank you so much for instruction.
                        I am now studying "Design Patterns in Ruby"
                        And just learned about Singlton Pattern.

                        Does every one use Design Pattern making sketchup plugin?
                        Or maybe use UML?

                        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