Sorry for keeping this one longer. There was some other work going on which kept me away from putting this one up but I’m happy to have this one now..

To start you will the spring file you created in the last chapter i.e. HOW TO ANIMATE A SPRING -1.

1. Open the spring part file.

2. Click on the Record button on the macro tool bar. If you haven’t have the macro toolbar one, you can go to Tools > Macros > Record to start recording. To show the macro toolbar go to View > Toolbar > Macro.

3. Double click on the spring body to show the dimensions and then click on the length, 100 mm in this case if you used the same old spring part file.

4. In the pop up window change the value to anything > I have changed it to 110 mm.

5. Click on Rebuild in the same dimension box or from the toolbar.

6. Finally click Stop on the macro toolbar or Tools > Macros > Stop.

7. Give a name your macro and hit save. I have used Spring Animate.

8. Now click on Edit button on macro toolbar or Tools > Macros > Edit

9. Browse to the macro you saved in the step 7 and open it.

10. VB editor will get open up and your screen will look like this.

11. Remove the extra line and make your window look like this.

12. Copy these 3 highlighted lines and paste them.

13. The editor window will look like this. Change the system value to .1. The system takes all in puts in meter. So if you want any other value convert it to meter and put here. .1 denotes .1 m i.e. 100mm

14. Add these 4 lines as shown and save you macro. You can keep any value for “i”. In this case I have used 10 which means the macro will run for 10 times. You can give any value or can create an input box where user can put the number of steps he needs. I will put up a macro or tutorial on how to do that.

15. Close the VB editor and back to SolidWorks window. Click on Play button on macro toolbar or Tools > Macros > Play

16. Browse to the macro you edited and saved in step 14.

17. Now sit back and enjoy the animation.

Apart from using macro, I have been trying to use Phil Sluder’s trick (SW Tips/Tricks – July Issue Adding Logic to Equations) but getting some error. I have requested Phil to check the same. As soon as he fixes as where I’m going wrong, we can have animation of spring using equations too. I’m also going to put another one using a combination of equations and Animator.

Link for the macro used in this tutorial: Spring Animate.swp


25 thoughts on “HOW TO ANIMATE A SPRING -2

  1. Mark

    The graphical part is fine with me but going down the article to the code part that’s where I am having a problem. Can’t understand if it’s the font or the photo… It’s not smooth when I zoom it…

  2. Calleo

    Wow! This can be one particular of the most beneficial blogs We have ever arrive across on this subject. Basically Magnificent

  3. Scott

    I want to use the SaveAsPDF macro but have it add the current Revision to the end of the file name, got any thoughts on this.

  4. Cooki

    Hi Deepak,

    I’m a newbie at solidworks so don’t really know much, would appreciate if you could help with a description.I don’t know if you mean using something from the context toolbar or using something else. I have used your first tutorial to draw the spring, and tried using the macro file you have provided, but cannot seem to be able to animate the spring. I am currently using SW2009. Any help would be much appreciated.


      1. Cooki

        Hi Deepak,

        Thanks for your reply. I have tried using the same dimensions and parameters, but this is what is shown when I try to edit the macro (below). I don’t know, but I think maybe the dimension are in inches or something but unfortunately don’t know how to change it to mm. I have also tried using different dimensions and parameters, as I wanted a longer spring, which starts as a closed spring with differeng sized spheres inside it. I also want to have the spheres falling out as the spring is extended. Is that possible you think? I appreciate your help.

        im swApp As Object

        Dim Part As Object
        Dim boolstatus As Boolean
        Dim longstatus As Long, longwarnings As Long

        Sub main()

        Set swApp = Application.SldWorks

        Set Part = swApp.ActiveDoc
        Dim myModelView As Object
        Set myModelView = Part.ActiveView
        myModelView.FrameState = swWindowState_e.swWindowMaximized
        boolstatus = Part.Extension.SelectByID2(“”, “FACE”, -0.02326244404162, 0.02662097323329, -0.03696098821953, False, 0, Nothing, 0)
        boolstatus = Part.Extension.SelectByID2(“”, “FACE”, -0.02409785880718, 0.02672903695176, -0.03650702421299, False, 0, Nothing, 0)
        boolstatus = Part.Extension.SelectByID2(“D3@Helix/Spiral1@Spring.SLDPRT”, “DIMENSION”, -0.02515551656815, 0.05238200955658, 0.09430238401681, True, 0, Nothing, 0)
        boolstatus = Part.EditRebuild3()
        boolstatus = Part.EditRebuild3()
        Part.ClearSelection2 True
        End Sub

      2. Cooki


        Kept trying, and used your macro, and it worked using the same dimensions, sorry for the trouble. However, I’m not sure what to do if the dimensions are different and if I want to continuously stretch the spring rather than opening and closing it.


          1. Cooki

            I have finally been able to animate the spring extending. For the spheres do you mean using a different way to animate them?

  5. Cooki

    I would like to make an animation of a spring with different sized balls coming out of it as it is extended. I’d appreciate it if you could help me out please.

  6. Phil Sluder

    If you guys are interested; here is a CORRECTED example of spring animation out of the July 2004 edition of SW Tips/Tricks “Adding Logic to Equations”

    Replace the three equations in the newsletter with these two equations, and you should be set:


    "D1@Sketch1"=IIF("D2@Sketch1" LIKE 1,"D1@Sketch1"+.1,"D1@Sketch1"-.1)

    Thanks for the heads up, Deepak.

  7. prudhvi

    sir, i need to know how to save a solid works model in IGES format ,so that i can import it to ansys……can u pls help me out


I'll be happy to know your views and opinions as this will help me to improve. You can share them as comments below.

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s