sketchucation logo sketchucation
    • 登入
    Oops, your profile's looking a bit empty! To help us tailor your experience, please fill in key details like your SketchUp version, skill level, operating system, and more. Update and save your info on your profile page today!
    ⚠️ Important | Libfredo 15.6b introduces important bugfixes for Fredo's Extensions Update

    Help Understanding Classes and Class objects

    已排程 已置頂 已鎖定 已移動 Developers' Forum
    30 貼文 4 Posters 743 瀏覽 4 Watching
    正在載入更多貼文
    • 從舊到新
    • 從新到舊
    • 最多點贊
    回覆
    • 在新貼文中回覆
    登入後回覆
    此主題已被刪除。只有擁有主題管理權限的使用者可以查看。
    • Dan RathbunD 離線
      Dan Rathbun
      最後由 編輯

      Sorry ... I got busy and did not get back to this thread,

      I was going to continue the discussion on why wrapper classes are extremely problematic for Sketchup::Drawingelement subclasses. (One issue is on Mac multiple models could be open, but the API does not yet have a good way to track them, and we know of some bugs on the PC, that causes issues.)


      Anyway... the alternative you REALLY should be using is to create a Sketchup::ComponentDefinition for your pully and conveyor, and then place instances of these (rather than Groups.)

      The definition's instances collection will keep track of them for you.

      The model's DefintionList collection will keep track of your definition(s) for each model that they are inserted into.

      When a model is opened, your plugin can search through it's DefintionList to find those definitions that are "known" to the plugin. And then grab an array of their instances, and iterate it to get references.

      I'm not here much anymore.

      1 條回覆 最後回覆 回覆 引用 0
      • P 離線
        pmagans
        最後由 編輯

        Dan you are correct. Adding the .group gave me access to the "group" objects that were created.

        As for my thought process I am not sure that it is valid so let me describe my thoughts.

        I don't want to code "like" things so I assumed that using classes would allow me to inherit class attributes things without having to copy a bunch of code it multiple places. For example classes would be:

        1. FUNCTIONAL AREAS
          [list:11tc2ay1]1. CONVEYOR
        • CONVEYOR_COMPONENTS

        • END_PULLEY

        • DRIVE

        • INTERMEDIATE_BED

        • PAN_GUARD

        • BEARINGS

        • ETC.

        • BUILDING_MODSETC.[/*Ⓜ11tc2ay1][/list⭕11tc2ay1]Later I could write Customer specific code for each of the classes and inherit all of the functionality that I wrote in the "General" Classes

        One customer's end_pulley may contain different bearings, pulleys, profiles etc. Also there are many types of end pulleys. That being said they do have some similarities especially attribute definitions, layer structure, basic functionality.

        Am I on the right track or am I way off the rails?

        1 條回覆 最後回覆 回覆 引用 0
        • Dan RathbunD 離線
          Dan Rathbun
          最後由 編輯

          @TIG 🎉

          Simply put:

          A class constructor returns an instance of IT's class.

          CONVEYOR::EndPully.new() returns an instance of CONVEYOR::EndPully not an instance Sketchup::Group

          This is one of the MAJOR drawbacks of a wrapper class, you have to write wrapper methods for all the methods of the wrapped object that you wish to access "as if" the wrapper "were" the object itself.

          There are some ruby tricks to get a list of only the API methods, and define wrapper methods via an eval loop. But .. it's still can get complicated in other nitty-gritty ways.

          I just do not recommend it.

          I'm not here much anymore.

          1 條回覆 最後回覆 回覆 引用 0
          • Dan RathbunD 離線
            Dan Rathbun
            最後由 編輯

            Dynamic Component definitions can give you a lot of flexibility. A style of pully, were the diameter and width are settable via the Component Options dialog.

            Your code classes and modules... are geometry creators, but not the actual model objects themselves.

            You can also inherit (share) code functionality via mixin module libraries.

            Given a mixin module named BasicPully ...

            module FancyPully
            
              include BasicPully
            
              # now overrride inherited methods if desired
            
              # now add additional methods if desired
            
            end
            

            .. and later ...

            module NiftyPully
            
              include FancyPully
            
              # now overrride inherited methods if desired
            
              # now add additional methods if desired
            
            end
            

            I'm not here much anymore.

            1 條回覆 最後回覆 回覆 引用 0
            • TIGT 線上
              TIG Moderator
              最後由 編輯

              ☀ 😒 doh!

              TIG

              1 條回覆 最後回覆 回覆 引用 0
              • P 離線
                pmagans
                最後由 編輯

                I will check into the mixin module approach also the dynamic components. Are dynamic components "create-able" through Ruby code or only through the Sketchup interface?

                The only info/tutorial I could find was:
                http://sketchucation.com/forums/viewtopic.php?f=180&t=17888&p=145120&hilit=dynamic+component+tutorial#p145120

                1 條回覆 最後回覆 回覆 引用 0
                • Dan RathbunD 離線
                  Dan Rathbun
                  最後由 編輯

                  Both.

                  But of course the coding means is not documented because the Free license users are not supposed to do it. (... or at least use a wizard interface.)

                  A lot has been written about them.

                  I'm not here much anymore.

                  1 條回覆 最後回覆 回覆 引用 0
                  • P 離線
                    pmagans
                    最後由 編輯

                    @dan rathbun said:

                    But of course the coding means is not documented because the Free license users are not supposed to do it. (... or at least use a wizard interface.)

                    That's a bummer. I like the concept of dynamic tools for locking up variables and documenting the components, but I hate the user interface! It would just take me too long through traditional means to create a workable library. And of course if I wanted to change something I would have to do it in multiple places. I will do a more active search for creating/modifying dynamic components through Ruby. So far what I have found has not been that helpful besides holding/setting attributes. Any tips on where to start?
                    Thanks!

                    1 條回覆 最後回覆 回覆 引用 0
                    • Dan RathbunD 離線
                      Dan Rathbun
                      最後由 編輯

                      In SU Pro.. open the "Component Attributes" wizard.

                      Switch to the "Functions" pane.

                      Click on the "more >>" link, ... a bowser window will open to the DC online reference.

                      Bookmark that page.

                      Notice also the links in the left navigation column.

                      Happy Reading.

                      Basically scripting them is first understanding how to create and access Attribute Dictionary objects.

                      I'm not here much anymore.

                      1 條回覆 最後回覆 回覆 引用 0
                      • P 離線
                        pmagans
                        最後由 編輯

                        @dan rathbun said:

                        Bookmark that page.

                        Done, thanks for the link.

                        I remember doing the tutorials when DC's first came out but have forgotton the majority of what I learned so I guess I will be spending some time there first.

                        1 條回覆 最後回覆 回覆 引用 0
                        • 1
                        • 2
                        • 2 / 2
                        • 第一個貼文
                          最後的貼文
                        Buy SketchPlus
                        Buy SUbD
                        Buy WrapR
                        Buy eBook
                        Buy Modelur
                        Buy Vertex Tools
                        Buy SketchCuisine
                        Buy FormFonts

                        Advertisement