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

    Can it be to achieve?

    Scheduled Pinned Locked Moved Developers' Forum
    8 Posts 5 Posters 278 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.
    • W Offline
      winzard
      last edited by

      Everyboby,I want to have a replacement on components
      in model by the ruby script at the same time.Can it be to achieve?
      Thanks

      1 Reply Last reply Reply Quote 0
      • M Offline
        Matt666
        last edited by

        Do you really need for a script to do what you want?
        Look at the image here...
        😉

        Frenglish at its best !
        My scripts

        1 Reply Last reply Reply Quote 0
        • thomthomT Offline
          thomthom
          last edited by

          I think you can get the transformation of the component you want to replace,
          then erase it
          add the new component and apply the transformation

          Thomas Thomassen — SketchUp Monkey & Coding addict
          List of my plugins and link to the CookieWare fund

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

            Here are some clues...

            ### first let's assume you know the component-definition you want 'to go' and you also know the component-definition you want 'to add' in its place...
              component_to_go.instances.each{|e|e.definition=component_to_add}
            ### this swaps ALL instances of one for the other, leaving them in place with the same, rotation, scaling, materials etc
            ### now let's assume that you only have details of one instance of the type that's 'to go' - perhaps you initially got it by selecting it (instance_to_go=SketchUp.active_model.selection[0])...
              instance_to_go.definition.instances.each{|e|e.definition=component_to_add}
            ### now let's assume you only want to swap those in a selection and leave any others unchanged...
              SketchUp.active_model.selection.each{|e|e.definition=component_to_add if e.typename=="ComponentInstance" and e.definition=component_to_go}
            ###
            
            

            How might you be getting the info on the 'to go' and the 'to add' component definitions ?

            TIG

            1 Reply Last reply Reply Quote 0
            • W Offline
              winzard
              last edited by

              Is the idea very difficult? My boss ask me to do that. 😒

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

                You can also do it without Ruby...
                Try this way...
                In the model select the component instances you want to be replaced - either by manually picking them (in which case they can even be a mixture of several types) OR by using the Component Browser (model-tab) and then right-clicking over the definition's icon that you want to have selected and pick 'Select Instances' - that way all of its active instances are selected.
                Now use the Component Browser - either in the model-tab to use components that are already within the model, or from any other 'external' location for components that are currently not yet loaded into the project - again you right-click over the definition's icon that you want 'to add' and pick 'Replace Selected'.
                Now the components you selected have been replaced by the component you wanted...

                It's possible to script it BUT it might be as easy to do it this way... There are already several component swapping scripts too...

                TIG

                1 Reply Last reply Reply Quote 0
                • W Offline
                  winzard
                  last edited by

                  Thanks !I fell a warm in the community forums!

                  1 Reply Last reply Reply Quote 0
                  • R Offline
                    RickW
                    last edited by

                    @tig said:

                    You can also do it without Ruby...
                    Try this way...
                    In the model select the component instances you want to be replaced - either by manually picking them (in which case they can even be a mixture of several types) OR by using the Component Browser (model-tab) and then right-clicking over the definition's icon that you want to have selected and pick 'Select Instances' - that way all of its active instances are selected.
                    Now use the Component Browser - either in the model-tab to use components that are already within the model, or from any other 'external' location for components that are currently not yet loaded into the project - again you right-click over the definition's icon that you want 'to add' and pick 'Replace Selected'.
                    Now the components you selected have been replaced by the component you wanted...

                    It's possible to script it BUT it might be as easy to do it this way... There are already several component swapping scripts too...

                    It can be done using the Component Browser, but when you have lots of components, it can be easier to select a desired component on-screen rather than hunting through the browser. Though I wrote ApplyTo before the Component Browser offered that functionality, it retains its relevance for this reason.

                    RickW
                    [www.smustard.com](http://www.smustard.com)

                    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