I’m trying to create a dynamic component with instances of other dynamic components. Could someone help me understand the error?
- The code you provided is nothing to do with Dynamic Components.
There is no proper way to interact with Dynamic Components from another extension. Dynamic Components does not have a public API and all interactions with it is basically just a hacks and risky…
However your methods can be called as a way to create you component dynamically.
- We do not know what error you got?
- We do not know with which parameters and how the
- If the last parameter
"nome"passed as String, then the
verificaParametrosNumericosmethod will return
- There is no
add_to_modelmethod exist in the SketchUp Ruby API for the
entitiesand I did not see if you delfineden it somewhere… (it is line 20 in CaixaMDF2.rb)
(1) Do not define custom classes at the top level
ObjectSpace. Only Ruby and the API should do this.
All of you code should be within your unique top-level namespace module. Each of your extenstions should be within a separate submodule of your namespace module.
(2) The last statement of
return instancia) is worthless. A class’
#initialize method ALWAYS returns the new instance of it’s class. (In this case the new instance of a
- Your code cannot return something else, so this
returnstatement would be ignored.
- What you might not understand, is that by the time a class’
#initializemethod gets called, it’s instance object is already created and the
#initializemethod is being evaluated within this new instance object.
(3) It is not normal procedure to do all the “work” within an
initialize method. Usually this is done in other methods of a class and called from the
initialize method. Generally, the
initialize method defines internal instance variables that will hold state throughout the life if the class’ instance objects.
That said, …
(4) What you show in “Cubo.rb” should not be a class as it does not have any state (properties) to hold. Really what you’ve shown is simply a module method, so
Cubo should really be module as there is nothing to instantiate. It just contains one “factory method” that producs a SketchUp API object and adds it to the model’s active entities collection.
The main error is the misuse of classes. Ie, neither
CaixaMDF should be a class.
CaixaMDF, the calls to
Cubo.new does not return what the coder thinks it does. The
Cubo objects are basically “empty” Ruby
Object subclasses that have no state or functionality (beyond what is inherited from
So, they cannot be later added to any entities collection using
The solution is for both files to be combined into a single module with module methods.
Your answer was helpful and clarified things for me. Do you have any sample code that instantiates an object with other objects, splitting their functions? It’s quite hard to find examples like this on the web.