• Login
sketchucation logo sketchucation
  • Login
🤑 SketchPlus 1.3 | 44 Tools for $15 until June 20th Buy Now

How To Interpret a Text as a DC Formula

Scheduled Pinned Locked Moved Dynamic Components
sketchup
15 Posts 3 Posters 9.5k Views
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.
  • S Offline
    SketchUcationKid
    last edited by 6 Feb 2017, 00:15

    hi everybody!

    the X axis value of my DC normally comes from a function because of the auto resize. the problem happens when I change the X axis value through the ANIMATE function on the INTERACT mode. it toggles between 0.3cm and 0.85cm values. when I click on the DC, SketchUp overwrites the value passed by the ANIMATE function on the function previously saved on the X axis field.

    from that time on, the DC doesn't resize properly because there's no more formula in the field but a value instead.

    in order to avoid this, I created a custom variable called pos_X in order to receive the formula that should be saved in the X axis field. pos_X is in a text format but X axis field only accepts number format.

    I need to know how to interpret this formula in text format and send the value in number format to the X axis field.

    many thanks.

    1 Reply Last reply Reply Quote 0
    • J Offline
      Jim
      last edited by 6 Feb 2017, 09:10

      Hard to say without seeing the model, or the formulas. Here's a suggestion:

      Use onClick to animate some attribute, in this case "movement":

      onCLick: animate("movement", 0, 5)

      The quotes are important.
      It prevents a bug if your animation values are negative,
      so just get in the habit of using them with the animate function.

      Then base the X formula on the attribute:

      X: =movement

      The equals sign is important. It gets you the value of the attribute.

      Hi

      1 Reply Last reply Reply Quote 0
      • S Offline
        SketchUcationKid
        last edited by 6 Feb 2017, 14:43

        @Jim. first of all, thanks for the reply.
        I will try to be straight in my explanation:

        When opening SketchUp:

        • DC parent name: Cabinet
        • DC child name: Door
        • custom variable name: door_gap
        • door_gap value: =0.3
        • custom variable name: door_thickness
        • door_thickness value: =1.5
        • X axis value: =Cabinet!X+Door!door_gap
        • RotZ value: 0

        OnClick Event:

        • ANIMATE("RotZ",0,-90);
        • ANIMATE("X",Cabinet!X+Door!door_gap,Cabinet!X+Door!door_gap+door_thickness)
          PS: the first animation works fine, as the second one. the problem happens when the second animation runs and change the X axis value, which was previously set to "=Cabinet!X+Door!door_gap". now it toggles between two numeric values (as result the two formulas).

        when I finish the INTERACT mode and resize the cabinet, now, it doesn't resize properly because X axis value is not a formula anymore but a numeric value.

        as a try to overcome this situation, I created another custom variable called "pos_X" (text type) and changed OnClick code, as follows:

        • ANIMATE("RotZ",0,-90);
        • SET("pos_X",IF("RotZ=0","=Cabinet!X+Door!door_gap","=Cabinet!X+Door!door_gap+door_thickness"))
          PS: pos_X receives the right formula in text format. now, I need to know how to interpret this formula and send the value to X axis, in numeric format.

        any idea?

        1 Reply Last reply Reply Quote 0
        • T Offline
          TIG Moderator
          last edited by 6 Feb 2017, 15:32

          You are trying to set the built-in RotZ directly.
          In Jim's example he set a variable, which was then used to set one of the built-in variables...
          So try:
          ANIMATE("myRotZ", 0, -90)
          Then use that layer, with:
          RotZ =myRotZ
          etc...

          TIG

          1 Reply Last reply Reply Quote 0
          • S Offline
            SketchUcationKid
            last edited by 6 Feb 2017, 15:59

            @TIG. the problem doesn't have to do with RotZ setting but with X axis setting. when I change its value (through ANIMATE function), it loses the formula previously saved.

            thanks.

            1 Reply Last reply Reply Quote 0
            • J Offline
              Jim
              last edited by 6 Feb 2017, 21:26

              It sounds as if you could simplify the functions by using a better placed axis of rotation. Can you share the model?

              Hi

              1 Reply Last reply Reply Quote 0
              • S Offline
                SketchUcationKid
                last edited by 6 Feb 2017, 22:36

                yes @Jim. for sure.
                activate the INTERACT mode, open and close the cabinet door and see what happens to the door.


                SketchUcation Sample.skp

                1 Reply Last reply Reply Quote 0
                • J Offline
                  Jim
                  last edited by 6 Feb 2017, 23:02

                  Are you really using SketchUp 7 as it says on yout profile?

                  Hi

                  1 Reply Last reply Reply Quote 0
                  • J Offline
                    Jim
                    last edited by 6 Feb 2017, 23:07

                    Anyhow, the point I and TIG are trying to make is that you can have a single animation attribute, but can use that attribute in any of the position and rotation attributes to obtain simultaneous animations.

                    Quick example: This would animate 90 degress around the Z axis, while at the same time moving along the X axis from 1 to 3. Does that help?

                    00068.png

                    Hi

                    1 Reply Last reply Reply Quote 0
                    • S Offline
                      SketchUcationKid
                      last edited by 7 Feb 2017, 00:00

                      I'm using SketchUp 8.011752

                      1 Reply Last reply Reply Quote 0
                      • S Offline
                        SketchUcationKid
                        last edited by 7 Feb 2017, 00:54

                        @Jim and @TIG. I understood the changes you did but I'll come back to the same problem: X axis will lose the formula =Cabinet!X+Door!door_gap, useful for the dynamic resize. I want to kill 2 birds with one stone: I want to have a dynamic resize along with open/close door animation.

                        you might have noticed that when I rotate the door right after I have to move back the door in the X coordinate, otherwise, the door will be touching the other door of the beside cabinet, when both are open.

                        when opening/closing the door, X axis receives numeric values, losing the formula. when resizing the cabinet, X axis should have the formula back, in order to do the resize properly.

                        thanks.

                        1 Reply Last reply Reply Quote 0
                        • S Offline
                          SketchUcationKid
                          last edited by 7 Feb 2017, 01:30

                          but you both gave me a very good idea that might be the solution and I'll try it right after the coffee. I will write the formula Cabinet!X + anim in the X axis field. the custom variable anim will receive the numeric value coming from one of the two formulas written in the ANIMATE function.

                          ANIMATE function in turn will have the two formulas: Door!door_gap and Door!door_gap+MDF_thickness, for instance.

                          what do you think?

                          1 Reply Last reply Reply Quote 0
                          • S Offline
                            SketchUcationKid
                            last edited by 7 Feb 2017, 03:16

                            hi guys,

                            the problem with the resize and cabinet door opening/closing was solved thanks to you guys, specially to @Jim and @TIG who gave me a brilliant idea.

                            I'll let available the project for whoever wants to make use of it.

                            THANKS!!!


                            Dynamic Resize With Open-Close Door.skp

                            1 Reply Last reply Reply Quote 0
                            • J Offline
                              Jim
                              last edited by 7 Feb 2017, 08:30

                              Here is what I mean.

                              The "anim" attribute moves smoothly between 0 and 1. We use the basic math properties that

                              
                              
                              0 × N == 0
                              1 × N == N
                              
                              
                              

                              where N is any number.

                              So then for any translation or rotation or scale the formula is:

                              
                              start_position + anim * travel_distance
                              
                              

                              or for a rotation:

                              start_angle + anim * travel_angle
                              
                              

                              Think in terms of start position and travel amount. When "anim" is 0 you get the start position. When "anim" reaches 1 you get the start_position + travel_amount.

                              The main advantage of all this is that you can use the "anim" attribute in any of the position, rotation, or size attributes to get multiple, simultaneous animations. Plus it actually simplifies the formulas once you get your head around it. You can also use the "anim" attribute to drive animations in other components in your DC.

                              Perhaps the 2nd image will help clarify.

                              00071.png

                              00073.png

                              Hi

                              1 Reply Last reply Reply Quote 0
                              • S Offline
                                SketchUcationKid
                                last edited by 8 Feb 2017, 23:06

                                that's right @Jim. you are an expert! now I'm uploading the final version of the cabinet project, with 2 doors working, as it really should be.

                                thanks.


                                SketchUcation - Cabinet 2 Doors - Dynamic Resize & Open-Close Doors.skp

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

                                Advertisement