Assign a Value to an Existing Configuration via a Macro (SolidWorks 2020)

Hello

I hope that people will be able to help me and that the subject is not already open elsewhere.

To explain my request, I modeled a part (a spring) that is managed by a macro. When I open my file and activate my macro, my UserForm appears and allows me to fill in a number of elements. Once the different elements have been filled in, I validate and my document is updated.

My problem comes at this point, this file has several configurations that correspond to several states of my spring (free state, compressed and X working positions). To date in my userform I have only managed the Free length. I would like to be able to create other boxes that would correspond to the different states of my jurisdiction and therefore to link the appropriate value to them. Ideally, it would be to have 3 basic states (Free Length, Block Length and Working Length 1). And so that the value I enter in each field can be assigned to the right configuration.  To date, I can't link the values entered to a specific configuration. 

If experts from the VBA solidworks have already worked on this subject or equivalent, I am strongly interested in their help.

Thanks in advance

 


macro_ressort.jpg

Hello Benoît,

Taking your example of a spring declined in 3 pre-existing configurations, I propose a macro that assigns to each config a different length, each entered in a TextBox of the UserForm.

Kind regards


dimensionconfig.zip
1 Like

Hello m.blt,

Thank you for your help, it meets my need exactly.

So I tried to take your example and insert it into my existing macro. I think I have implanted the elements in the right places, however when I run my macro it gives me an error message telling me that a variable is not defined. And I can't figure out which one it is.

Also, your macro looks much simpler than mine, so I wonder if I don't have super-flow elements in it, or if I wrote my lines in the right places.

 I put my working file with my macro. Maybe it will be easier for our exchanges.

PS: I'm starting out in macro, I arrived at the one after a lot of research and trials. Configuration management is for me the next level ^^.


ressort_parametrable.zip

Hello

Marrying macro codes from different origins is not always easy...
A functional and commented version is attached to this message.

Good luck.


ressortparametrablev2.zip
2 Likes

A big thank you m.blt, this solves the subject.

I still have to figure out how to manage my grinding function for each configuration and the macro will be fully operational.

I take note of the comments you left me for my future projects in which I would like to manage with a macro.

Thanks again for the time spent and the advice^^