Thank you very much. Macro 1 is great for verifying that the part family exists.
I used the code from macro 2 to open the room family. The Excell file opens well, the values indicated are correct but the 3D is not updated. It updates again if I reopen the part family.
In the snippet of code you give you get the table of the object "swModel" but you ask for a reconstruction on the object "Part", try by putting "swModel.ForceRebuild" instead of "Part.ForceRebuild".
For swDesTable.Detach I admit I don't know exactly what it's for but in the help: Detach the design table from the Microsoft Excel sheet.
In the case of the requested use, I don't think it's necessary.
swDesTable.Attach, on the other hand, is used to activate the table.
Debug.assert is a conditional breakpoint if I don't make a mistake if the boolean bret is false, the macro stops on this line (basically if the table doesn't open).
To update the template you must use swDesTable.UpdateTable 2, True
Thank you to both of you for your answers. It works. I still have the excell application (I guess because of the family of parts) which remains open. Would it be possible to close it and come back to the 3D at the end of the macro? Thank you in advance for your feedback
There must be something else in the macro that's blocking Excel from closing. For my part, I have Excel that disappears from the active processes as soon as the macro ends (but I only have a snippet of code that opens the table, updates a value, closes the table and updates the 3D).
It would take the complete code to see if there is another function that is blocking.
'----------------------------------- ' Preconditions: ' 1. Open a part document that contains a design table. ' 2. Verify that the part document contains a design ' table by expanding Tables in the ConfigurationManager. ' 3. Open the Immediate window. ' ' Postconditions: ' 1. Gets whether the design table is updatable before ' running the macro. ' 2. Sets the design table to not updatable if it is ' updatable or vice versa. ' 3. Examine the Immediate window. '----------------------------------- Explicit Option 'Dim swApp As SldWorks.SldWorks Dim swModel As SldWorks.ModelDoc2 Dim swDesignTable As SldWorks.DesignTable Dim boolstatus As Boolean Dim laststate As Variant Dim swDesTable As SldWorks.DesignTable Dim Double Height
Set swApp = Application.SldWorks Set swModel = swApp.ActiveDoc Set swDesignTable = swModel.GetDesignTable() ' Allow changes to the characteristics of the ' design table swDesignTable.EditFeature ' Get whether design table is updatable laststate = swDesignTable.Updatable Debug.Print "Design table updatable: " & CStr(laststate) ' If design table is updatable, then set it ' to not updatable or vice versa swDesignTable.Updatable = Not laststate ' Update this characteristic of the design table boolstatus = swDesignTable.UpdateFeature() ' Get whether design table is updatable laststate = swDesignTable.Updatable Debug.Print "Design table updatable: " & CStr(laststate)
Height = InputBox("Please indicate the Conveyor Height.... ") 'swModel.GetEquationMgr.Value("Height") = Height Set swDesTable = swModel.GetDesignTable bRet = swDesTable.Attach
'Debug.Assert bRet 'breakpoint if the table does not open, if bret is false swDesTable.UpdateTable 2, True swDesTable.Detach swModel.ForceRebuild ' to rebuild a Part.ForceRebuild
Same for me, Excel closes well and disappears from the list of processes at the end of the macro but there is a small period of time before this is done, a time frame that is shorter by deleting the last line "Set swApp = Application.SldWorks" which is useless since this swApp variable is already defined at the beginning of your macro.
I've already noticed that sometimes the Excel process has trouble closing when writing macros and that we often go into debug mode, especially when the macro freezes during execution...
Thank you Roger. Do you have at least one trick to display the active Solidworks window because I have this damn Excel window that takes over.... I'd just like to at least finish my macro by displaying the Sldworks window... Thank you
On the code, I don't see anything in particular, for my part I still have no trace of Excel at the end of the macro.
To put SW back in the foreground, unless I'm mistaken, it's
bret = swapp.visible
After for the problem itself, either it's a crash of Excel or it's a bug in the Solidworks version.
Is the room family open in another window or is it open in SW?
Another slightly barbaric solution is the shell commands to kill the Excel process:
Shell "taskkill /f /im excel.exe", vbHide
Otherwise another idea, it can come from the automatic update of the table when opening, maybe SW is waiting for something in the background (window that would have switched to the background) and suddenly blocks the closure of Excel.
You should test the code with the deactivation of the automatic update of the table, from memory it is in one of the two codes of the help of my first answer.
Hello digging up topic, I will try to be clear. This macro works great except that... 1- I modify a sketch 2- I run the macro (which goes well) but at the end it locks all the dimensions of the sketches so it's no longer possible since SW to modify a value. 3- I run the macro again and there I have access to modify the sketches again from SW. To sum up, if I launch the macro after modifying a sketch, I have to run it a second time to be able to modify a value again. No matter how much I tinker, I don't find why. if someone can enlighten me. May the force be with you.
Hello I am not sure that I have understood the problem properly. I can be in a sketch or edit directly by double-clicking on the function, but I don't have any dimension lock. On the other hand, as there is a strong rebuild, we inevitably find ourselves out of the sketch.
Hello Here is an explanatory video. I explain what is happening. 1-You can see that I can modify a value at will. 2-I run the macro to update the part 3- I want to modify this same value again but the impossible to modify 4-I rerun the macro and there I have edit access again. Why do I have to rerun the macro to have access to edit??? May the Force be with you
Hello I just understood. In fact, you have to remove this part of the code that changes the table's update behavior.
Set swDesignTable = swModel.GetDesignTable()
' Allow changes to the characteristics of the
' design table
swDesignTable.EditFeature
' Get whether design table is updatable
laststate = swDesignTable.Updatable
Debug.Print "Design table updatable: " & CStr(laststate)
' If design table is updatable, then set it
' to not updatable or vice versa
swDesignTable.Updatable = Not laststate
' Update this characteristic of the design table
boolstatus = swDesignTable.UpdateFeature()
' Get whether design table is updatable
laststate = swDesignTable.Updatable
Debug.Print "Design table updatable: " & CStr(laststate)
It toggles from "Allow part family to be updated by model changes" to "Disallow model changes that would update part family." So, first time it switches to the second mode, on the second launch it does the opposite.