• Login
sketchucation logo sketchucation
  • Login
🤑 SketchPlus 1.3 | 44 Tools for $15 until June 20th Buy Now

Plugin(export attributes to csv)

Scheduled Pinned Locked Moved Developers' Forum
16 Posts 4 Posters 819 Views
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.
  • T Offline
    tetsuyahishida
    last edited by 9 Jun 2011, 12:04

    Hi!All. I'm a newbie and I'm sorry if I'm in the wrong place.

    Now making a plugin based on TIG's
    "exportvertices2csv"
    "VolumeCalculator2"

    The script it self is uploaded in GITHUB
    https://github.com/tetsuyahishida/export2csv

    <What the Plugin can do>
    the script can output
    1.volume
    2.are of the faces
    3.normal vector of the faces
    to csv

    <The Problem>
    But the problem is that it doesn't work on in some PCs!
    The window with the message
    "uninitialized constant Export2csv::Volume”
    can some body help me?


    snapshot

    1 Reply Last reply Reply Quote 0
    • T Offline
      TIG Moderator
      last edited by 9 Jun 2011, 12:44

      The class method
      def Volume::calculate(fcs)
      should be renamed as
      def volume(fcs)
      and then called in the 'initialize()' code where
      volume=Volume.calculate(fcs)#calculate volume
      becomes
      volume=self.volume(fcs)

      you are making it all too convoluted...

      PS: whilst I don't mind an acknowledgment in the scripts header, please don't make me the (c) author... that's you ! I accept NO blame 😉

      TIG

      1 Reply Last reply Reply Quote 0
      • D Offline
        Dan Rathbun
        last edited by 9 Jun 2011, 20:37

        Why do you distro a copy of sketchup.rb ?

        It does not appear to be different from the Google version, and should not be changed anyhow.

        I'm not here much anymore.

        1 Reply Last reply Reply Quote 0
        • T Offline
          tetsuyahishida
          last edited by 9 Jun 2011, 21:27

          TIG
          Thank you so much for your reply!
          I'm a fan of you. So excited to be able to get in touch with you.

          The Plugin worked flawlessly after the modification.

          Dan Rathbun
          Thank you for your advice.
          It is the same as the Google version.

          I'll push the changes.
          Since using "git" and push it to GITHUB seems to be a very usefull method I think other sketchup user might like using it.

          1 Reply Last reply Reply Quote 0
          • T Offline
            TIG Moderator
            last edited by 10 Jun 2011, 07:41

            You shouldn't distribute sketchup.rb - all users will already have it in their Tools folder, so giving it to a user who might then put a duplicate [or worse, 'out of date'] version into their Plugins folder could cause all sorts of unexpected complications that can be avoided by NOT supplying it in the zip-file.

            TIG

            1 Reply Last reply Reply Quote 0
            • T Offline
              tetsuyahishida
              last edited by 11 Jun 2011, 02:55

              TIG

              Thank you for your advise.
              I've removed sketchup.rb from GITHUB.

              Unfortunately, some other people still can't use the plugin.

              <Error message>
              #<NameError: undefined loca variable or method 'export2csv' for main:Object>

              do you have any idea what's wrong?

              Link Preview Image
              export2csv/export2csv.rb at version0.8 · tetsuyahishida/export2csv

              sketchup plugin. Contribute to tetsuyahishida/export2csv development by creating an account on GitHub.

              favicon

              GitHub (github.com)


              screenshot

              1 Reply Last reply Reply Quote 0
              • J Offline
                Jim
                last edited by 11 Jun 2011, 08:52

                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 11 Jun 2011, 09:05

                  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
                  • T Offline
                    TIG Moderator
                    last edited by 11 Jun 2011, 11:38

                    @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 11 Jun 2011, 12:11

                      @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
                      • T Offline
                        TIG Moderator
                        last edited by 11 Jun 2011, 12:35

                        @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 11 Jun 2011, 15:12

                          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
                          • D Offline
                            Dan Rathbun
                            last edited by 13 Jun 2011, 01:52

                            @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
                            • D Offline
                              Dan Rathbun
                              last edited by 13 Jun 2011, 02:08

                              @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
                              • D Offline
                                Dan Rathbun
                                last edited by 13 Jun 2011, 02:11

                                @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 15 Jun 2011, 10:22

                                  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
                                  1 / 1
                                  • First post
                                    1/16
                                    Last post
                                  Buy SketchPlus
                                  Buy SUbD
                                  Buy WrapR
                                  Buy eBook
                                  Buy Modelur
                                  Buy Vertex Tools
                                  Buy SketchCuisine
                                  Buy FormFonts

                                  Advertisement