Auto Family Coin Update

Hi all!

 

In my eternal search for complexity and in order to facilitate the use of a tool for others, I try to make a small "module" in VBA so that in a single data file, the coin odds on SW change.

 

To do this, I obviously started by doing tests on a single part.

 

I created a room family table and therefore set the desired dimensions by creating two lines: "origin" and "modifiable"

 

So I created my data file, with the original dimensions of the parts (In case they are forgotten by dint of changing them!)

 

On this one, I also created a button, with the following VBA command in it:

 

[code] Sub Changement_cote()

Workbooks.Open ("Test-Workbook.xlsm")
'Modification
Workbooks("Test-Workbook.xlsm"). Worksheets("Sheet1"). Range("B4"). Value = "='[Database.xlsm]Sheet1'!$B$4"

Workbooks("Test-Workbook.xlsm"). Worksheets("Sheet1"). Range("C4"). Value = "='[Database.xlsm]Sheet1'!$C$4"

Workbooks("Test-Workbook.xlsm"). Close 'Closing Test File

 

 

Workbooks.Open ("00-XXXXX-0-Came.xlsx") 'Family Room

'Modification
Workbooks("00-XXXXX-0-Came.xlsx"). Worksheets("Sheet1"). Range("B4"). Value = "='[Database.xlsm]Sheet1'!$B$4"

Workbooks("00-XXXXX-0-Came.xlsx"). Worksheets("Sheet1"). Range("C4"). Value = "='[Database.xlsm]Sheet1'!$C$4"

Workbooks("00-XXXXX-0-Came.xlsx"). Close 'Closing Test File

 

End Sub[/code]

 

For the moment I haven't added the auto' backup of the files, but they ask me to, and I also see the change on the files that didn't use the "updatescreen=false" =)

 

So my problem comes later. I reopen solidworks after making my modification, and the part family unfortunately does not update, despite the fact that its file is up to date. I have to go through "edit part family" for it to update

 

(during this operation I only do "edit family" and I quit, solidworks seems to go and get the file)

 

Would there be a VBA command allowing this update to do so automatically?

Because this is only a room, it's not a problem. But for a complex assembly containing only 20 parts, it may become a long ^^'

 

Sorry for the pavement and the inconvenience,

Hoping to find a solution ^^"

 

Friendly

 

Yoann

 


base_donnee.jpg

Hello

 

Here is a macro found on the SolidWorks forum:

 

https://forum.solidworks.com/thread/9335

 

Or see the SolidWorks Help instruction:

http://help.solidworks.com/2012/English/api/sldworksapi/Get_or_Set_Whether_Edits_Update_Design_Table_Example_VB.htm

Hello@Lucas

 

mmmh... functions such as "Dim swApp As SldWorks.SldWorks" don't fit in the vba module of excel?

 

It gives me an error when I try to run the macro:

"Compilation   Error User-Defined Type Not Defined"

 

Apart from the fact that I understand that he is telling me that what I have defined... is not defined.... (she gives you a headache this sentence *shocked*)

 

I don't really understand =/

 

friendly

Oh but you create the part family from Excel?

 

How do you then implement it so that it appears in SolidWorks?

It created itself as a file .xlsx actually ^^'  when I saved it

 

So I thought I'd do all the manipulations from my database file, in order to simplify future use by other people.

When I create a part family, I don't have access to the Excel file! Where do you find it?

I only had access to it by having the family "registered" ^^

 

To tell the truth, I don't open it via Excel, the latter. I only needed it to access its address "C:\...\came.xlsx" in order to put the link in my VBA code

OK, anyway, you won't be able to update the part family in SolidWorks from Excel: it's a SolidWorks macro that I was offering you!

And it's sure that it's much less interesting: to update it, instead of opening the coin family, you have to launch a macro it's pretty much the same thing.

 

Otherwise, launching the macro automatically every time a part is started will be really tedious and will slow down SW when opening a file...

http://www.leguide3d.com/profiles/blogs/piloter-un-modele-3d-au-travers-d-excel

 

I found this, I'll test, but it seems to me to be a solution =). I'll keep you posted!

1 Like

Sorry a little tired, yes you can actually create a SolidWorks macro from Excel as it is written in your link.

 

If the part is open in SolidWorks, using the instructions in the image:

 

http://api.ning.com/files/s2sZbafeBpX-mX9KHHPZMOqmYpSGIu93UHOfWU*M6CnBzflIcn0D5aoMp7YX937HiJ5u00KItfo8KQVFyrpA0TVLVgq-rvlW/Code1.PNG

 

You should be able to launch the macro I proposed above.

No worries Lucas^^ weekend, I think everyone is a little tired^^

 

I have indeed tried this, and it doesn't detect any problem =)

 

Except later, when I try to integrate the solidworks macro you gave me above^^'

 

Dim swDoc As SldWorks.ModelDoc2

 

is not recognized =/

 

 

Not being able to use solidworks macros in excel, I started looking for how I could launch the solidworks macro from excel.

 

So I proceeded as follows

 

Set swApp = CreateObject("SldWorks.Application")
Set Part = swApp.ActiveDoc
Dim boolstatus As Boolean

Dim filename As String
filename = swApp.GetCurrentMacroPathName
filename = Left(filename, InStrRev(filename, "\")) + "Macro1.swp"
boolstatus = swApp.RunMacro(filename, "Macro11", "alternate")
boolstatus = swApp.RunMacro(filename, "Macro11", "main")

 

And now my "update" button on the side also updates the families of parts on solidworks by launching the macro @Lucas gave me =)

 

(https://forum.solidworks.com/thread/9335)

 

All that's missing is to find out how to remove the view of the pages with a command like "screenupdate.false" solidworks version.

 

But it's not really annoying =)

 

Thank you for your help Lucas once again^^