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

    Automatically load a component.

    Scheduled Pinned Locked Moved Developers' Forum
    70 Posts 5 Posters 5.6k Views 5 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.
    • Dan RathbunD Offline
      Dan Rathbun
      last edited by

      @tntdavid said:

      If someone shares one of my dynamic components with a user without my extension, it must be impossible to use these dynamic features!

      There is no way to make it impossible.

      If you must use a DC function try to use a refinement for Ruby 2.0+.
      Code example withdrawn. A refinement will not work, because the DC code files would themselves need to use the refinement.

      • Modifying the DCFunctionsV1 class may not pass inspection by the Trimple Developer extension signing page.

      I'm not here much anymore.

      1 Reply Last reply Reply Quote 0
      • TNTDAVIDT Offline
        TNTDAVID
        last edited by

        @tig said:

        You could also make it so tiny that if was hard to find !

        Very good idea. 👍

        We can also hide the edges of a model?

        @tig said:

        My example test code, checks if the definition is loaded and if not it loads it.
        If it id loaded and there is an instance there is nothing more to do, otherwise it adds the instance...

        You talk about this example?

        @tig said:

        if definition.valid?
          if instance.valid? ###[or perhaps || definition.instances[0] ???]
            ### You are already set to do the DC load...
          else
            ### You need to add an instance - perhaps it's been deleted by the user ???
            ### NOW you are set to do the DC load...
          end
        else ### definition is NOT valid - it's been deleted - so the instance has too.
          ### You load the definition AND add the instance again - seems like the user has deleted both !
          ### NOW you are set to do the DC load...
        end


        @tig said:

        I agree with Dan...
        All of the messing on so far could be achieved by more subtle and less complex means.
        It probably needs a separate thread...

        I do not doubt for a moment of your words.

        As my specialty are dynamic components, create a protection directly into the models is much easier for me.

        Although my protection is not foolproof, it will be very difficult to circumvent.


        @dan rathbun said:

        There is no way to make it impossible.

        If you must use a DC function try to use a refinement for Ruby 2.0+.
        Code example withdrawn. A refinement will not work, because the DC code files would themselves need to use the refinement.

        Thanks for these informations ❗

        [b:8wt9py2i]* Nouveau !!![/b:8wt9py2i] Découvrez notre nouveau Plugin [url=http://www.composant-dynamique.com/:8wt9py2i][color=#40FF00:8wt9py2i]C[/color:8wt9py2i][color=#77FF00:8wt9py2i]l[/color:8wt9py2i][color=#ADFF00:8wt9py2i]i[/color:8wt9py2i][color=#E4FF00:8wt9py2i]c[/color:8wt9py2i][color=#FFDB09:8wt9py2i]k[/color:8wt9py2i][color=#FF921B:8wt9py2i]-[/color:8wt9py2i][color=#FF492E:8wt9py2i]C[/color:8wt9py2i][color=#FF0040:8wt9py2i]u[/color:8wt9py2i][color=#ED2577:8wt9py2i]i[/color:8wt9py2i][color=#DA49AD:8wt9py2i]s[/color:8wt9py2i][color=#C86EE4:8wt9py2i]i[/color:8wt9py2i][color=#AD77FF:8wt9py2i]n[/color:8wt9py2i][color=#8965FF:8wt9py2i]e[/color:8wt9py2i] [color=#4040FF:8wt9py2i]2[/color:8wt9py2i][/url:8wt9py2i], pour créer vos cuisines 3D !

        1 Reply Last reply Reply Quote 0
        • TNTDAVIDT Offline
          TNTDAVID
          last edited by

          Hello,

          I still can not limit the number of cube to 1. 😕

          If someone can give me more information on writing code, I would be very recognize him.

          Thank you

          David

          [b:8wt9py2i]* Nouveau !!![/b:8wt9py2i] Découvrez notre nouveau Plugin [url=http://www.composant-dynamique.com/:8wt9py2i][color=#40FF00:8wt9py2i]C[/color:8wt9py2i][color=#77FF00:8wt9py2i]l[/color:8wt9py2i][color=#ADFF00:8wt9py2i]i[/color:8wt9py2i][color=#E4FF00:8wt9py2i]c[/color:8wt9py2i][color=#FFDB09:8wt9py2i]k[/color:8wt9py2i][color=#FF921B:8wt9py2i]-[/color:8wt9py2i][color=#FF492E:8wt9py2i]C[/color:8wt9py2i][color=#FF0040:8wt9py2i]u[/color:8wt9py2i][color=#ED2577:8wt9py2i]i[/color:8wt9py2i][color=#DA49AD:8wt9py2i]s[/color:8wt9py2i][color=#C86EE4:8wt9py2i]i[/color:8wt9py2i][color=#AD77FF:8wt9py2i]n[/color:8wt9py2i][color=#8965FF:8wt9py2i]e[/color:8wt9py2i] [color=#4040FF:8wt9py2i]2[/color:8wt9py2i][/url:8wt9py2i], pour créer vos cuisines 3D !

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

            Think through the logic...

            Here set out in words - not code...

            If there is no loaded definition, either it's a fresh start or the user has managed to delete it from the model: therefore you load it - otherwise you have got it already and you go to the next step.
            Next.
            If there is no instance of that definition, either because it's a fresh start or the user has managed to delete it from the model: therefore you need to add it - otherwise you already have it and do nothing.
            If there are multiple instances delete all but the first one.

            S'il n'y a pas de la definition chargée, soit il est un nouveau départ, ou l'utilisateur a réussi à le supprimer du modèle: donc vous le chargez [load] - sinon vous l'avez, déjà vous allez à l'étape suivante.
            Prochain.
            S'il n'y a pas d'instance de cette definition, soit parce qu'il est un nouveau départ, ou l'utilisateur a réussi à le supprimer du modèle: par conséquent, vous devez l'ajouter - sinon, vous l'avez déjà et ne rien faire ...
            S'il y a plusieurs instances supprimer tout sauf la première.

            ###
            model = Sketchup.active_model
            definitions = model.definitions
            if definition = definitions['cube'] ### or whatever it's named
              ### do nothing as we already have it
            else
              ### we load it because it's missing
              definition = definitions.load(path_to_cube.skp) ### you need to work that out
            end #if
            ### now check instance exists
            if definition.instances.length == 1
              ### we have it
              instance = definition.instances[0]
            elsif definition.instances.length > 1
              ### somehow we have duplicates, erase all but the first one [0]
              definition.instances[1..-1].each{|i| i.erase! }
              instance = definition.instances[0]
            else
              ### there is NO instance so we add it
              instance = model.entities.add_instance(definition, ORIGIN)
            end #if
            ###
            ### Now change instance to have an OFF layer, hide it, lock it etc etc
            ### ALWAYS do this in case the user has messed with it...
            ### 
            

            [mod=:1961t99s]Fixed my stupid typo ' definition.instances[1..-1]**.each**{|i| i.erase! }'[/mod:1961t99s]

            TIG

            1 Reply Last reply Reply Quote 0
            • TNTDAVIDT Offline
              TNTDAVID
              last edited by

              Thanks TIG,

              I followed your method, which is very clear and detailed:

              def self.methode1
                    path = Sketchup.find_support_file("cube.skp", 
                    "Plugins/TesteCube/Components/")
                    model = Sketchup.active_model
                    definitions = model.definitions
                    component_definition = definitions.load(path)
                    point = Geom;;Point3d.new(0, 0, 0)
                    transformation = Geom;;Transformation.new(point) 
              	  
                    if definition = definitions['cube']
              	  
                    else
                    definition = definitions.load(path_to_cube.skp)
                    end
              	  
                    if definition.instances.length == 1
                    instance = definition.instances[0]
              
                    elsif definition.instances.length > 1
                    definition.instances[1..-1]{|i| i.erase! }
                    instance = definition.instances[0]
              	  
                    else
                    instance = model.entities.add_instance(component_definition, transformation)
              	  
                    status = instance.locked = true
                    layers = model.layers
                    new_layer = layers.add "cube"
                    new_layer.visible = false
                    instance.layer = new_layer
                    instance.locked = true
                    instance.hidden = true
                    Sketchup.active_model.import(@@path_to_00)
                    end
              

              I get this error message at the launch of SketchUp:

              @unknownuser said:

              Error Loading File C:/Users/DAVID/AppData/Roaming/SketchUp/SketchUp 2015/SketchUp/Plugins/TesteCube/logic.rb
              Error: #<SyntaxError: C:/Users/DAVID/AppData/Roaming/SketchUp/SketchUp 2015/SketchUp/Plugins/TesteCube/logic.rb:30: syntax error, unexpected { arg, expecting keyword_end
              definition.instances[1..-1]{|i| i.erase! }

                                          ^
              

              C:/Users/DAVID/AppData/Roaming/SketchUp/SketchUp 2015/SketchUp/Plugins/TesteCube/logic.rb:30: syntax error, unexpected '}', expecting keyword_end
              definition.instances[1..-1]{|i| i.erase! }

                                                        ^
              

              C:/Users/DAVID/AppData/Roaming/SketchUp/SketchUp 2015/SketchUp/Plugins/TesteCube/logic.rb:102: syntax error, unexpected end-of-input, expecting keyword_end>
              C:/Program Files/SketchUp/SketchUp 2015/Tools/extensions.rb:197:in require' C:/Program Files/SketchUp/SketchUp 2015/Tools/extensions.rb:197:in load'
              C:/Users/DAVID/AppData/Roaming/SketchUp/SketchUp 2015/SketchUp/Plugins/TesteCube.rb:28:in register_extension' C:/Users/DAVID/AppData/Roaming/SketchUp/SketchUp 2015/SketchUp/Plugins/TesteCube.rb:28:in module:TesteCube'
              C:/Users/DAVID/AppData/Roaming/SketchUp/SketchUp 2015/SketchUp/Plugins/TesteCube.rb:18:in `<top (required)>'

              I made a mistake somewhere?

              Thank you

              [b:8wt9py2i]* Nouveau !!![/b:8wt9py2i] Découvrez notre nouveau Plugin [url=http://www.composant-dynamique.com/:8wt9py2i][color=#40FF00:8wt9py2i]C[/color:8wt9py2i][color=#77FF00:8wt9py2i]l[/color:8wt9py2i][color=#ADFF00:8wt9py2i]i[/color:8wt9py2i][color=#E4FF00:8wt9py2i]c[/color:8wt9py2i][color=#FFDB09:8wt9py2i]k[/color:8wt9py2i][color=#FF921B:8wt9py2i]-[/color:8wt9py2i][color=#FF492E:8wt9py2i]C[/color:8wt9py2i][color=#FF0040:8wt9py2i]u[/color:8wt9py2i][color=#ED2577:8wt9py2i]i[/color:8wt9py2i][color=#DA49AD:8wt9py2i]s[/color:8wt9py2i][color=#C86EE4:8wt9py2i]i[/color:8wt9py2i][color=#AD77FF:8wt9py2i]n[/color:8wt9py2i][color=#8965FF:8wt9py2i]e[/color:8wt9py2i] [color=#4040FF:8wt9py2i]2[/color:8wt9py2i][/url:8wt9py2i], pour créer vos cuisines 3D !

              1 Reply Last reply Reply Quote 0
              • TNTDAVIDT Offline
                TNTDAVID
                last edited by

                Wonderful 😍 😍 😍

                If I delete this line of code:

                elsif definition.instances.length > 1
                      definition.instances[1..-1]{|i| i.erase! }
                      instance = definition.instances[0]
                
                

                Your method works great TIG! 👍

                Do you know why the line of code that is intended to deleted "cube", does not?

                Many thanks for your help.

                David

                [b:8wt9py2i]* Nouveau !!![/b:8wt9py2i] Découvrez notre nouveau Plugin [url=http://www.composant-dynamique.com/:8wt9py2i][color=#40FF00:8wt9py2i]C[/color:8wt9py2i][color=#77FF00:8wt9py2i]l[/color:8wt9py2i][color=#ADFF00:8wt9py2i]i[/color:8wt9py2i][color=#E4FF00:8wt9py2i]c[/color:8wt9py2i][color=#FFDB09:8wt9py2i]k[/color:8wt9py2i][color=#FF921B:8wt9py2i]-[/color:8wt9py2i][color=#FF492E:8wt9py2i]C[/color:8wt9py2i][color=#FF0040:8wt9py2i]u[/color:8wt9py2i][color=#ED2577:8wt9py2i]i[/color:8wt9py2i][color=#DA49AD:8wt9py2i]s[/color:8wt9py2i][color=#C86EE4:8wt9py2i]i[/color:8wt9py2i][color=#AD77FF:8wt9py2i]n[/color:8wt9py2i][color=#8965FF:8wt9py2i]e[/color:8wt9py2i] [color=#4040FF:8wt9py2i]2[/color:8wt9py2i][/url:8wt9py2i], pour créer vos cuisines 3D !

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

                  Use:
                  definition.instances[1..-1].each {|i| i.erase! }

                  I'm not here much anymore.

                  1 Reply Last reply Reply Quote 0
                  • K Offline
                    kaas
                    last edited by

                    Also have a look at this section in the picture.

                    My suggestion is: add more puts statements into your code to quickly find the problems (yourself).

                    Edit: where are you declaring definitionanyway??


                    code.jpg

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

                      Sorry about the typo - substitute Dan's .each{ correction.
                      I have edited the original post to suit !

                      Also I used the reference ' definition' BUT you then used ' component_definition'
                      Please try to match such references when you are given 'generic' code...

                      Why did you not follow my example more closely [except for the stupid typo!] ???

                      PS: @Kaas is actually wrong it IS = NOT == because
                      if definition = definitions[...
                      With the = test you are trying to set the reference ' definition' to be pointing to something 'by name' in definitions - if that fails then you get nil returned, so then the else part of the test runs...
                      A == test is for 'equality' of two items, and not for testing if setting a reference works...

                      TIG

                      1 Reply Last reply Reply Quote 0
                      • TNTDAVIDT Offline
                        TNTDAVID
                        last edited by

                        I took note of all your comments. 😉

                        This is not very important but the code, do not remove the "cube", if there is more than one.

                        elsif component_definition.instances.length> 1
                                 component_definition.instances [1 .. -1] .each {| i | i.erase! }
                                 component_definition.instances instance = [0]
                        

                        You know why?

                        Thank you

                        David

                        [b:8wt9py2i]* Nouveau !!![/b:8wt9py2i] Découvrez notre nouveau Plugin [url=http://www.composant-dynamique.com/:8wt9py2i][color=#40FF00:8wt9py2i]C[/color:8wt9py2i][color=#77FF00:8wt9py2i]l[/color:8wt9py2i][color=#ADFF00:8wt9py2i]i[/color:8wt9py2i][color=#E4FF00:8wt9py2i]c[/color:8wt9py2i][color=#FFDB09:8wt9py2i]k[/color:8wt9py2i][color=#FF921B:8wt9py2i]-[/color:8wt9py2i][color=#FF492E:8wt9py2i]C[/color:8wt9py2i][color=#FF0040:8wt9py2i]u[/color:8wt9py2i][color=#ED2577:8wt9py2i]i[/color:8wt9py2i][color=#DA49AD:8wt9py2i]s[/color:8wt9py2i][color=#C86EE4:8wt9py2i]i[/color:8wt9py2i][color=#AD77FF:8wt9py2i]n[/color:8wt9py2i][color=#8965FF:8wt9py2i]e[/color:8wt9py2i] [color=#4040FF:8wt9py2i]2[/color:8wt9py2i][/url:8wt9py2i], pour créer vos cuisines 3D !

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

                          It's wrongly formed, reread what you have typed it does not make sense.
                          Try this...

                          elsif component_definition.instances.length > 1
                            component_definition.instances[1..-1].each{|i| i.erase! }
                            instance = component_definition.instances[0]
                          
                          

                          I am assuming that all of your references to the cube's definition now use 'component_definition' rather than 'definition' ?
                          You cannot copy / paste snippets of code in a different sequence and hope that it will somehow work.
                          The first part of your code is also carried over from your earlier version and does NOT do what I asked you to do.
                          It always loads the path, but you ought to check if the definition exists and then load it if not.
                          Try following my code more closely, and remove your earlier steps which pre-load the cube before checking if it's loaded !

                          TIG

                          1 Reply Last reply Reply Quote 0
                          • K Offline
                            kaas
                            last edited by

                            @tig said:

                            ...PS: @Kaas is actually wrong it IS = NOT == because
                            if definition = definitions[...
                            With the = test you are trying to set the reference ' definition' to be pointing to something 'by name' in definitions - if that fails then you get nil returned, so then the else part of the test runs...
                            A == test is for 'equality' of two items, and not for testing if setting a reference works...

                            Thanks TIG. Learned something here.

                            1 Reply Last reply Reply Quote 0
                            • TNTDAVIDT Offline
                              TNTDAVID
                              last edited by

                              @tig said:

                              I am assuming that all of your references to the cube's definition now use 'component_definition' rather than 'definition' ?

                              I think yes :

                               
                              def self.methode00
                                  path = Sketchup.find_support_file("cube.skp", 
                                  "Plugins/TesteCube/Components/")
                                   model = Sketchup.active_model
                                   definitions = model.definitions
                                   component_definition = definitions.load(path)
                                   point = Geom;;Point3d.new(0, 0, 0)
                                   transformation = Geom;;Transformation.new(point) 
                              	  
                                   if component_definition = definitions['cube']
                              	  
                                   else
                                   component_definition = definitions.load(path_to_cube.skp)
                                   end
                              	  
                                   if component_definition.instances.length == 1
                                   instance = component_definition.instances[0]
                              	  
                                   elsif component_definition.instances.length > 1
                                   component_definition.instances [1..-1] .each {| i | i.erase! }
                                   instance = component_definition.instances[0]
                              	  
                                   else
                                   instance = model.entities.add_instance(component_definition, transformation)
                              	  
                                   status = instance.locked = true
                                   layers = model.layers
                                   new_layer = layers.add "cube"
                                   new_layer.visible = false
                                   instance.layer = new_layer
                                   instance.locked = true
                                   instance.hidden = true
                                   end
                                   end
                              

                              @tig said:

                              You cannot copy / paste snippets of code in a different sequence and hope that it will somehow work.

                              Sorry for silly mistakes, but i am just beginning to understand the logic of the ruby.

                              I'm a simple Carpenter by training, then learn the ruby is not easy for me.

                              I Thank You for your understanding and your indulgence.

                              David

                              [b:8wt9py2i]* Nouveau !!![/b:8wt9py2i] Découvrez notre nouveau Plugin [url=http://www.composant-dynamique.com/:8wt9py2i][color=#40FF00:8wt9py2i]C[/color:8wt9py2i][color=#77FF00:8wt9py2i]l[/color:8wt9py2i][color=#ADFF00:8wt9py2i]i[/color:8wt9py2i][color=#E4FF00:8wt9py2i]c[/color:8wt9py2i][color=#FFDB09:8wt9py2i]k[/color:8wt9py2i][color=#FF921B:8wt9py2i]-[/color:8wt9py2i][color=#FF492E:8wt9py2i]C[/color:8wt9py2i][color=#FF0040:8wt9py2i]u[/color:8wt9py2i][color=#ED2577:8wt9py2i]i[/color:8wt9py2i][color=#DA49AD:8wt9py2i]s[/color:8wt9py2i][color=#C86EE4:8wt9py2i]i[/color:8wt9py2i][color=#AD77FF:8wt9py2i]n[/color:8wt9py2i][color=#8965FF:8wt9py2i]e[/color:8wt9py2i] [color=#4040FF:8wt9py2i]2[/color:8wt9py2i][/url:8wt9py2i], pour créer vos cuisines 3D !

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

                                The initial
                                component_definition = definitions.load(path)
                                is NOT needed.
                                remove it, and retry.

                                TIG

                                1 Reply Last reply Reply Quote 0
                                • TNTDAVIDT Offline
                                  TNTDAVID
                                  last edited by

                                  @tig said:

                                  The initial
                                  component_definition = definitions.load(path)
                                  is NOT needed.
                                  remove it, and retry.

                                  If I delete this line, the cube is no longer imported. 😲

                                  Another area of research:

                                  Is it possible to activate a tool SketchUp, with an icon from my toolbar?

                                  I would like to activate the tool, "Interact with Dynamic Components" and the window of "Components Options".

                                  How to change the value of an attribute of a dynamic component, by clicking on an icon?

                                  Thank you in advance for your lights.

                                  David

                                  [b:8wt9py2i]* Nouveau !!![/b:8wt9py2i] Découvrez notre nouveau Plugin [url=http://www.composant-dynamique.com/:8wt9py2i][color=#40FF00:8wt9py2i]C[/color:8wt9py2i][color=#77FF00:8wt9py2i]l[/color:8wt9py2i][color=#ADFF00:8wt9py2i]i[/color:8wt9py2i][color=#E4FF00:8wt9py2i]c[/color:8wt9py2i][color=#FFDB09:8wt9py2i]k[/color:8wt9py2i][color=#FF921B:8wt9py2i]-[/color:8wt9py2i][color=#FF492E:8wt9py2i]C[/color:8wt9py2i][color=#FF0040:8wt9py2i]u[/color:8wt9py2i][color=#ED2577:8wt9py2i]i[/color:8wt9py2i][color=#DA49AD:8wt9py2i]s[/color:8wt9py2i][color=#C86EE4:8wt9py2i]i[/color:8wt9py2i][color=#AD77FF:8wt9py2i]n[/color:8wt9py2i][color=#8965FF:8wt9py2i]e[/color:8wt9py2i] [color=#4040FF:8wt9py2i]2[/color:8wt9py2i][/url:8wt9py2i], pour créer vos cuisines 3D !

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

                                    The reason it's not loading is that the if...else...end test fails because you have not edited it properly:
                                    The line
                                    component_definition = definitions.load(path_to_cube.skp)
                                    should actually be
                                    component_definition = definitions.load(path)

                                    Of course you can do all of what you outline by setting up appropriate code.

                                    e.g. if you have a selected DC instance then a button click could change an attribute and then refresh the DC, but all of this is complex - we already have enough issues getting the cube.skp loaded !

                                    TIG

                                    1 Reply Last reply Reply Quote 0
                                    • TNTDAVIDT Offline
                                      TNTDAVID
                                      last edited by

                                      Do not be so pessimistic TIG, because thanks to you I made very big progress in Ruby. 💚

                                      Here is an example of evolution, thanks to the ruby script:

                                      http://i.imgur.com/tgXhofT.gif

                                      Notice that the "Control Panel", is the "Click-Window 3D" layer are imported along with the "Hung Windows".

                                      Other advanced thanks to ruby, the "Control Panel" always positions façe the camera when you call.

                                      I want to believe you that my requests are complicated, but I will not give up before trying.

                                      You can at least guide me by giving me the methods to use?

                                      And if you are generous as usual, a small sample code?

                                      Thank you in advance.

                                      David

                                      [b:8wt9py2i]* Nouveau !!![/b:8wt9py2i] Découvrez notre nouveau Plugin [url=http://www.composant-dynamique.com/:8wt9py2i][color=#40FF00:8wt9py2i]C[/color:8wt9py2i][color=#77FF00:8wt9py2i]l[/color:8wt9py2i][color=#ADFF00:8wt9py2i]i[/color:8wt9py2i][color=#E4FF00:8wt9py2i]c[/color:8wt9py2i][color=#FFDB09:8wt9py2i]k[/color:8wt9py2i][color=#FF921B:8wt9py2i]-[/color:8wt9py2i][color=#FF492E:8wt9py2i]C[/color:8wt9py2i][color=#FF0040:8wt9py2i]u[/color:8wt9py2i][color=#ED2577:8wt9py2i]i[/color:8wt9py2i][color=#DA49AD:8wt9py2i]s[/color:8wt9py2i][color=#C86EE4:8wt9py2i]i[/color:8wt9py2i][color=#AD77FF:8wt9py2i]n[/color:8wt9py2i][color=#8965FF:8wt9py2i]e[/color:8wt9py2i] [color=#4040FF:8wt9py2i]2[/color:8wt9py2i][/url:8wt9py2i], pour créer vos cuisines 3D !

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

                                        Try this to open the Options dialog for the currently selected DC.
                                        $dc_observers.get_latest_class.show_configure_dialog

                                        Here are some other clues to update a DC after you change its attributes in Ruby...

                                        With dins set to an array of DC instances...
                                        dins.each{|di| $dc_observers.get_latest_class.redraw(din, false, false) if din && din.valid?}

                                        Alternatively
                                        dins.each{|sel| $dc_observers.get_latest_class.redraw_with_undo(din) if din && din.valid? }

                                        DC attributes are normally attached to the DC instance's definition,although some are on the instance itself.
                                        Assuming that din is the DC instance...
                                        dda = din.definition.attribute_dictionary("dynamic_attributes") ida = din.attribute_dictionary("dynamic_attributes")

                                        To see these, when testing etc, use
                                        dda.each_pair{|k, v| puts "#{k} = #{v}" }
                                        and so on...

                                        To get a particular 'key' value use this format.
                                        Note how 'built-in' attributes start with an _
                                        puts dda["_name"]

                                        To set a particular 'key' to a new value use this format.
                                        First see original name...
                                        puts dda["_name"] **dda["_name"]="Banane"** puts dda["_name"]
                                        which should show the new name...

                                        BUT remember that you need to do a ' redraw' - as explained above to see the changes and update the DC's Options etc.

                                        Also consider how attribute values are stored - as strings, with dimensions in inches etc...

                                        TIG

                                        1 Reply Last reply Reply Quote 0
                                        • TNTDAVIDT Offline
                                          TNTDAVID
                                          last edited by

                                          @tig said:

                                          $dc_observers.get_latest_class.show_configure_dialog

                                          TIG big thank you, this code works perfectly.

                                          I read on another forum, some character like "$" are refused by the bank of extensions and can lead to a rejection of the Plugin.

                                          Is it true?

                                          How close the window component options, with another icon?

                                          I'm sorry to ask twisted questions, but your experience is a great help to me. 👍

                                          I can not activate the icon "Interact with Dynamic Component".

                                          Yet I am the logical steps:

                                          1. I select the tool "Interact with Dynamic Components".

                                          2. I open the Ruby console and write this code:

                                           = tools Sketchup.active_model.tools
                                           if tools.active_tool_id.equal? 0
                                            puts "Tools collection is empty"
                                           else
                                           name = tools.active_tool_name
                                           end
                                          

                                          The result is: "RubyTool" the name of the tool.

                                          As a result I write the following code:

                                          result = Sketchup.send_action "selectRubyTool:"

                                          The result is: False!
                                          If that means that "RubyTool" is not the right name.

                                          I so understand, that the solution is too hard to find for me!

                                          Do you have the solution?


                                          Thank you for explanations on changing the Dynamic Component with the ruby ​​script.

                                          I'll take my time to study in detail all the information you give me.

                                          Thank you for your patience.

                                          David

                                          [b:8wt9py2i]* Nouveau !!![/b:8wt9py2i] Découvrez notre nouveau Plugin [url=http://www.composant-dynamique.com/:8wt9py2i][color=#40FF00:8wt9py2i]C[/color:8wt9py2i][color=#77FF00:8wt9py2i]l[/color:8wt9py2i][color=#ADFF00:8wt9py2i]i[/color:8wt9py2i][color=#E4FF00:8wt9py2i]c[/color:8wt9py2i][color=#FFDB09:8wt9py2i]k[/color:8wt9py2i][color=#FF921B:8wt9py2i]-[/color:8wt9py2i][color=#FF492E:8wt9py2i]C[/color:8wt9py2i][color=#FF0040:8wt9py2i]u[/color:8wt9py2i][color=#ED2577:8wt9py2i]i[/color:8wt9py2i][color=#DA49AD:8wt9py2i]s[/color:8wt9py2i][color=#C86EE4:8wt9py2i]i[/color:8wt9py2i][color=#AD77FF:8wt9py2i]n[/color:8wt9py2i][color=#8965FF:8wt9py2i]e[/color:8wt9py2i] [color=#4040FF:8wt9py2i]2[/color:8wt9py2i][/url:8wt9py2i], pour créer vos cuisines 3D !

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

                                            You can always write code that does not need to use 'global' variable reference - i.e. avoid the form $myCompo
                                            These globals are seen by and affect all Ruby code running, so it's not a good idea, as one day your code and someone else's code will clash - e.g. imagine if you used $x, and changed its value in your script, then someone else's code that also ill-advisedly uses that same reference is messed up afterwards - so just don't go there !
                                            There are several useful built-in Ruby globals like $: etc that are useful.
                                            SketchUp itself chose to break the rule with how it handles DC references.
                                            If your code only uses the SketchUp and Ruby globals it should at least pass those EW tests...
                                            However, it's not a certainty - if that is a reason appeal - I once wrote a method containing a Constant named TEMP pointing at a temporary folder location.
                                            It was rejected by EW because it was reassigning a system Constant - of course it was not as it was within it's own module - so after an appeal they relented and allowed it - they had simply misread the code...

                                            A variable is only available in the method it is made - e.g. x or myCompo
                                            An instance variable is available in all methods within a module or those within one instance of a class - e.g. @x or @myCompo; so it's remembered across Module use, during that session.
                                            A class variable is initialized outside of any methods within a class and is available in all methods in any use of that class, during that session - e.g. @@x or @@myCompo
                                            Another form of reference is a Constant, these must start with a Capital letter, often they are in all capitals, but it's not compulsory. You can reset the value of a Constant in code but it produces a Ruby Console warning message, there are ways of changing a Constant in code to avoid the message, but since a constant is set up to remain the same it seems perverse to do so. There are built-in Constants like ORIGIN, X_AXIS and so on, you can set up your own unchanging ones to be remembered across a module that session - e.g. IMAGES_FOLDER, TEMP_FOLDER etc.
                                            To keep values per key across sessions you can write custom attributes to almost anything - from the model itself through collections like Layers and Materials, to elements like a definition, or individual instances etc.
                                            This way you can remember the last user inputs for each model.
                                            To remember the last user inputs for your tool globally across models consider using Sketchup.write_default() and [ruby:3rngofgq]read_default()[/ruby:3rngofgq]
                                            You can of course write data to a file and read it back later [like an ini file]...

                                            I gave you the code to open the DC Options dialog...
                                            [ruby:3rngofgq]$dc_observers.get_latest_class.show_configure_dialog[/ruby:3rngofgq]
                                            Using
                                            [ruby:3rngofgq]$dc_observers.get_latest_class.methods.sort[/ruby:3rngofgq]
                                            prints a long list of ALL methods accessed by that DC class's function...

                                            The obvious candidate for closing it is...
                                            [ruby:3rngofgq]$dc_observers.get_latest_class.close_configure_dialog[/ruby:3rngofgq]

                                            Which does indeed work !

                                            TIG

                                            1 Reply Last reply Reply Quote 0
                                            • 1
                                            • 2
                                            • 3
                                            • 4
                                            • 3 / 4
                                            • First post
                                              Last post
                                            Buy SketchPlus
                                            Buy SUbD
                                            Buy WrapR
                                            Buy eBook
                                            Buy Modelur
                                            Buy Vertex Tools
                                            Buy SketchCuisine
                                            Buy FormFonts

                                            Advertisement