Announcement

Collapse
No announcement yet.

Apply Script to many objects at once

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Apply Script to many objects at once

    Hi all,

    I searched TFM for a way to apply a certain script to many objects at once but didn't find a way to do it.
    Like if i need to apply a script to many objects on Enter or on click or ....

    I'm building an app that contains 10s of buttons and its taking too long to do it , and its painful when i change the code and want to replace it for the all objects.

    Any Hint ??

  • #2
    sameer valva
    It's hard to see what you are after as it's painful for us to guess without some sort of code sample
    but see if this helps - use enumerate objects etc


    https://forums.indigorose.com/forum/...in-programming

    https://forums.indigorose.com/forum/...ouping-objects

    Comment


    • #3
      Thanks colc for help, but my question is not related to any specific script, im asking in general if there is a way to apply any code to many objects at the same time.

      ex: if i want to add a code to (on enter) to many objects at once, is there any way to do it without going to each object and apply it? is there any automation ? or batch or something ?

      I will check the links you added if there is a solution.

      Thank you So much

      Comment


      • #4
        Here is an example I've done for you , uses properties and also xml file
        DynamicPages.apz

        Comment


        • #5
          Thank you so much colc Maybe i didn't explain it wright , excuse my English level
          I'm did something close to what you shared but what i need is different

          I have an app contains a grid of buttons all buttons will have the same function on (On click) and other function on (On Right-Click) and other on (On Enter) and one for (On Leave)
          I made functions so any change will apply to all button having the same function, but if i need to add another function or script, i have to go to each button and add the script for each on all four panels.

          One Example of what i need to do: I want to put a script on (On Enter) on all buttons ( more than 500 buttons) so when the mouse enters any of them the same script will be executed

          I know two options: 1- Do it manually and go to each button and add the same function.
          2- add the function to the mouse movement but i don't know how to do it.

          Note: each box is a button.

          Thank you again Click image for larger version

Name:	Screenshot 2021-06-30 110753.jpg
Views:	203
Size:	8.4 KB
ID:	307296 Click image for larger version

Name:	Screenshot 2021-06-30 110758.jpg
Views:	130
Size:	37.7 KB
ID:	307297


          Comment


          • #6
            Make one button with the scripts you need, then duplicate the button (select object, then press Ctrl+D) and reposition the new object where you need it. Repeat until the objective is reached.

            Ulrich

            Comment


            • #7
              Hi Ulrish

              I already did that, I designed everything and arranged all buttons after i put all needed codes, but suppose you need to add a new script to all buttons after you prepared and arranged all, is it only manual way to do it ? going to each button and add the new script, or AMS has another way?

              can i select 4 or more objects together and put a script to (On click or On enter or ...) at the same time rather than going to each button?

              Thanks

              Comment


              • #8
                Unless your buttons load and run from an external script otherwise use a global
                try this for fun
                sameer_code.zip

                Comment


                • #9
                  Thank you colc , already did exactly what you have have done with the example, It seems that the way i did it is the only way. Thank you soooo much and Ulrish also.

                  Comment


                  • #10
                    According to you post

                    is it only manual way to do it ? going to each button and add the new script, or AMS has another way?

                    can i select 4 or more objects together and put a script to (On click or On enter or ...) at the same time rather than going to each button?
                    you didn't , otherwise what was the point of this thread.
                    From Globals you can control each object or group of objects with if,eleseif statements

                    Comment


                    • #11
                      I meant by ("the way i did it is the only way") is that what I've done before posting the question, is the same as you did and the same as UIlrish.

                      My question is really simple, its not about functions and how to use it to control objects, its about AMS itself, if there is a ways that we can put a a script (On Enter) for all the buttons with one click, not going to each button and add the script to (On Enter).

                      Like if you select many objects at once, AMS allows to change their properties together at the same time, like opacity or Visibility ,but what if i want to add a script to (On Enter) to many objects at the same time .

                      Im So sorry this post took too much from your time than it deserves because of my bad way to explain it (bad English Skills )

                      Click image for larger version

Name:	The Objects.jpg
Views:	151
Size:	22.0 KB
ID:	307307 Click image for larger version

Name:	Properties.jpg
Views:	112
Size:	31.6 KB
ID:	307308 Click image for larger version

Name:	Script Explorer.jpg
Views:	107
Size:	71.2 KB
ID:	307309


                      Hope its clear now.

                      And I Really Really Thank you all , im learning so much from your answers for me and for others.

                      Comment


                      • #12
                        did you find the magic button in the demo?
                        it will show you the code

                        Comment


                        • #13
                          Yes i found the Magic Button 54 and as i told you, this is the same way i built the project but i was asking if there is a way to escape going to each button and apply the scripts on each Event:

                          Code:
                          ------------------------------[[ SCRIPT: Page: Page1, Object: Button1, Event: On Click Script ]]------------------------------
                          btn = this
                          doit()
                          
                          ------------------------------[[ SCRIPT: Page: Page1, Object: Button1, Event: On Enter Script ]]------------------------------
                          btn = this
                          showit()
                          
                          ------------------------------[[ SCRIPT: Page: Page1, Object: Button1, Event: On Leave Script ]]------------------------------
                          btn = this
                          hideit()
                          
                          ------------------------------[[ SCRIPT: Page: Page1, Object: Button2, Event: On Click Script ]]------------------------------
                          btn = this
                          doit()
                          
                          ------------------------------[[ SCRIPT: Page: Page1, Object: Button2, Event: On Enter Script ]]------------------------------
                          btn = this
                          showit()
                          
                          ------------------------------[[ SCRIPT: Page: Page1, Object: Button2, Event: On Leave Script ]]------------------------------
                          btn = this
                          hideit()
                          
                          ------------------------------[[ SCRIPT: Page: Page1, Object: Button3, Event: On Click Script ]]------------------------------
                          btn = this
                          doit()
                          
                          ------------------------------[[ SCRIPT: Page: Page1, Object: Button3, Event: On Enter Script ]]------------------------------
                          btn = this
                          showit()
                          
                          ------------------------------[[ SCRIPT: Page: Page1, Object: Button3, Event: On Leave Script ]]------------------------------
                          btn = this
                          hideit()
                          Your Demo contain 100 Buttons and my Projects contains 600 Button so clicking on each button and add the functions to each Event is taking time, i was wondering if there is a way that automates this process like batch thing or something. I don't mind if its the only way to do it manually, but just asking to learn how gain time and work smart in projects like this.

                          BTW Can we make this is in a different way ? like Putting a function to Page Events (On Mouse Move) and when the mouse enters an image area or button then an image appears or something.
                          so rather than putting a function to each button we put one function to the mouse move ( just throwing an idea without any knowledge or experience)

                          Comment


                          • #14
                            If you do not know this information, add it to your knowledge dictionary:
                            The name of any object that can be replaced by the word " this " .

                            Comment


                            • #15
                              this is an example Put this code in " On Show " in your Project and Preview what is happend by Pressed on any Button :

                              Code:
                              -- Get the names of all of the objects on the page.
                              object_names = Page.EnumerateObjects();
                              
                              -- Get the error code of the last action.
                              error = Application.GetLastError();
                              
                              -- If an error occurred, display the error code message.
                              if (error ~= 0) then
                              Dialog.Message("Error", _tblErrorMessages[error], MB_OK, MB_ICONEXCLAMATION);
                              else
                              -- If there are no objects on the current page, display a dialog.
                              if (object_names == nil) then
                              Dialog.Message("Notice", "There are no objects on the current page.", MB_OK, MB_ICONEXCLAMATION);
                              else
                              -- Display the names of all of the label objects on the page.
                              output_string = "";
                              for index, object in pairs(object_names) do
                              -- Get the type of the object
                              type = Page.GetObjectType(object);
                              if (type == OBJECT_BUTTON) then
                              Page.SetObjectScript(object, "On Click", "Dialog.Message('welcome', 'this is '..this)");
                              end
                              end
                              end
                              end

                              Comment

                              Working...
                              X