S or NS state of a function via a macro - VBA

Hi all

I'm currently looking for a way to use a SolidWorks (VBA) macro to put a function of the creation tree in the deleted state or not (I have previously entered all the name of the dimension in my excel file).

If anyone has the solution, it would be very useful to me...

Kind regards

Stone

Hello

Just right-click on the function then properties of the function and you choose delete and choose either in this configuration or all configurations or specify the configuration(s).... The result is the same, as many clicks and less annoying to do...

Hello ac cobra 427,

You 'll notice that I specified "via a macro" so your answer isn't really useful to me, but thank you all the same.

Tampis, it was an alternative solution to your problem in the meantime. Because to do that in VBA it's going to be hot...

 

Hello

The macro recorder doesn't work?

Hello!

Have you thought about taking a look at DriveWorksXpress?

DriveWorksXpress is a free tool that allows you to automate your designs. One of the features is the ability to change the state (deleted or not) of one or more SolidWorks functions.

But if you are comfortable with programming and want to dedicate time to this task.

Your macro should:

  • Retrieve the value of an Excel row. (Loop)
  • retrieve the names of all the SolidWorks features in your model (loop)
  • if it exists, select it.
  • retrieve the state to be controlled from the same Excel line
  • Change the status of the function

etc etc

You definitely want to take a look at the SOLIDWORKS API:

Like what

  • Part.Extension.SelectByID2 (one of several selection methods)
  • Part.EditSuppress2 (a way to change the state of the selected function).

Below is the link to the SolidWorks interfaces for documentation:

http://help.solidworks.com/2016/English/api/SWHelp_List.html?id=e016d4d94ffb4feb9865a83290877513#Pg0&ProductType=&ProductName=

Good luck!

2 Likes

By the way, I just checked quickly, the idea of optiSW is completely valid, everything I just said is contained in a macro quickly recorded.

In fact I think he would like to have a small "drop-down" menu with the deleted and undeleted in the creation tree. But for that you should rather see to develop an addon or if it exists ....

Hello thomas.guillard,

I finally found the solution and it is the same as the one you proposed to me.

I created a small macro that looks for the name of the coast in my excel and then selects it on the 3D part to modify its state.

                    name = Cells(2, i). Value
                    Searchstring = name
                    SearchChar="@"
                    mypos = InStr(1, Searchstring, SearchChar, 1)
                    nom_cote = Right(Searchstring, Len(name) - Mypos) 'counts the number of characters and subtracts the Mypos from it
                        Set Part = swApp.ActiveDoc
                    boolstatus = Part.Extension.SelectByID2(nom_cote, "BODYFEATURE", 0, 0, 0, False, 0, Nothing, 0)
                            Part.EditSuppress2

 

Thank you all for your help,

If thomas.guillard gave you the answer or strongly directed you, he should have been validated as the best answer...

I identified it as the best answer, don't worry.

Even if I had finally found the solution by myself and after finding it I saw his answer which corresponded to the beginning of my solution.

In any case, thank you all,

1 Like