Looking for a macro to insert a general table template. Has anyone seen one or have one? Thanks
Welcome to SolidWorks forums Grant.
Check this example: Insert General Table (VBA) OR use modified codes below.
Option ExplicitDim swApp As SldWorks.SldWorksDim swModel As SldWorks.ModelDoc2Dim swDrawing As SldWorks.DrawingDocDim swTable As SldWorks.TableAnnotationSub main()Set swApp = Application.SldWorksSet swModel = swApp.ActiveDocSet swDrawing = swModel Set swTable = swDrawing.InsertTableAnnotation2(True, 0, 0, swBOMConfigurationAnchor_TopLeft, "Enter complete path to your general table template here", 4, 2)End Sub
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swDrawing As SldWorks.DrawingDoc
Dim swTable As SldWorks.TableAnnotation
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
Set swDrawing = swModel
Set swTable = swDrawing.InsertTableAnnotation2(True, 0, 0, swBOMConfigurationAnchor_TopLeft, "Enter complete path to your general table template here", 4, 2)
Replace 0,0 with the x and y coordinates you need (macro can be modified to use the user selected point)
You might also find this post helpful for your future reference.
We have a general table template that we insert manually can that be done with this code?
Yes. And before I suggest you something, I would like to know as how you insert that i.e. at a fixed location in drawing or at a place/location selected by user.
Yes it is a fixed location, the template has an anchor point.
OK macro can do that. The macro doesn't read the numbers of rows from the table template so you can fix them in the macro ( say 5, 6, etc.) or can have a pop up window asking for the rows. How would you like the macro?
2 Rows is all we would need. Sometimes we need 2 but we can just add a row. Fixing it to 2 rows in the code would be great. We always use the same template and it is located on our server. Will there be a line in the code to specify the location of the template?
OK try this macro.
You need to edit the macro and change the path to your general table template. Make sure the path is between "".
Change the path in this line:
Const sTablePath As String = "D:\SolidWorks\Tables\GT.sldtbt"
To edit the macro, go to Tools > Edit and browse to the Insert General Table.swp file.
Macro has been built and tested on SW2013 x64
Thanks! Thats great. Couple questions, can it use the documents settings for the borders? When I manually insert the gen template the "use document settings" check box is checked. When I run the macro the check box is missing. Alternately if you can set the size in the code our doc setting is .0138in for both borders.
Also, we do use 2 templates but it depends on sheet size (A & B one template then C and up for the other template). I was just going to create 2 icons to run macros for the 2 different general templates. Is it possible to have a pop up window so the user can specify which template they need? Again, I can create 2 icons to run the macros but thought a pop up to define which template would be nice.
Appreciate your help with this Deepak. Also, I'm not new to SW forums, just with a new company so I have a different serial/new SW forums profile.
Grant, sorry on the welcome message but saw your joining date as today so thought you're a new guy on the board.
For setting up the border yes, we can set them in the macro itself.
And for different templates, the macro can be made to read the sheet size/template and insert the appropriate general table. So this will save you additional macro button or mouse clicks. What you think??
No worries. Been here 6 Months finally needed some help, tired of clicking and inserting the template.
Great, please add the border size in the code.
That sounds like a great idea.
OK give this one a try. Make sure you specify the paths for the general table template as stated in the macro.
It is inserting the A & B size sheet template in all sheet sizes. Basically the only difference between the 2 templates is the size. Not sure if this is effecting it but we have one sheet template and at the drawing level change the sheet properties to select the appropriate sheet format/size.
It should be inserting C size template on all drawing because code has a slight mistake.
Can you please try this one, sorry for the trouble with the earlier one.
I saw the sTablePath2 typo and fixed it on the other one, forgot to say that in the other post. Still seems to just insert the A & B template.
Can you send the drawings, all the three types and both the templates to check.
I just replied to your PM.
Your first file works perfectly for me! Thank you!!
Two part question..
I want to insert this not attached to an anchor point.
I cannot find details about the "switches" for this function.
Hard coding a coordinate will work typically for me.
Set swTable = swDrawing.InsertTableAnnotation2(True, 0, 0, swBOMConfigurationAnchor_TopLeft, sTablePath, 2, 1)
You mentioned being able to ask for an insertion point.
How is that done?
Here is the original code you posted in the zip file: (header removed)
If (swModel Is Nothing) Or (swModel.GetType <> swDocDRAWING) Then
swApp.SendMsgToUser ("To be used for drawings only, Open a drawing first and then TRY!")
Set swDrawing = swModel
' Insert general table
If Not swTable Is Nothing Then
swTable.BorderLineWeight = 1
swTable.GridLineWeight = 0
Setting False in this line would give you the desired results. The next two 0,0 are X and Y coordinates.
Set swTable = swDrawing.InsertTableAnnotation2(FALSE, 0, 0, swBOMConfigurationAnchor_TopLeft, sTablePath, 2, 1)
OR you can use pickpt to get the mouse click/point on the drawing. And then use them to define the X and Y in above line.
I was really excited to find this post. I tried your original code, but it did not work. Maybe something changed between 2013 and 2015 which we are on now.
I also tried all the macros in this thread. None of them work for me. I'm trying to pull in a general table template (with merged cells and links to variables). The only time I get it even close to working is if I record it myself, but it unmerges the cells and strips all the content out of my format.
Download the macros and edit them go to Tools/References and make sure the the boxes checked are 2016 and un-check older versions, save and try it again, if the macro still doesn't work copy the code and record a new macro, drop in the copied code and save..
I tried the above with no luck. I've tried copying the code into a macro of my own. Unfortunately the macro I record and the macro I downloaded from this thread are pretty different, and I can't figure out why/how.
Edit the macro and select the code and copy, close the macro and record a new one and paste the code in that one, see it'll work then.. Deepak Gupta said sometimes you need to shake them up a bit...
I have always found the information you give to be very helpful. I know that this is an old post but I wanted to know why will this macro not work following the instruction you gave?
I am running SW-2015 SP 4
Set swTable = swDrawing.InsertTableAnnotation2(True, 0, 0, swBOMConfigurationAnchor_TopLeft, "Y:\SWLib\SolidWorks_Set-Up\SolidWorks_Custom_Properties\Paint Specification", 4, 2)
Jonathan, your table path is not correct. It should have the table name with extension. For e.g.
This what I have still does not work
Set swTable = swDrawing.InsertTableAnnotation2(True, 0, 0, swBOMConfigurationAnchor_TopLeft, "Y:\SWLib\SolidWorks_Set-Up\SolidWorks_Custom_Properties\Paint Specification\Table.sldtbt", 4, 2)
Option ExplicitDim swApp As SldWorks.SldWorksDim swModel As SldWorks.ModelDoc2Dim swDrawing As SldWorks.DrawingDocDim swTable As SldWorks.TableAnnotationSub main()Set swApp = Application.SldWorksSet swModel = swApp.ActiveDocSet swDrawing = swModelSet swTable = swDrawing.InsertTableAnnotation2(True, 0, 0, swBOMConfigurationAnchor_TopLeft, "Y:\SWLib\SolidWorks_Set-Up\SolidWorks_Custom_Properties\Paint Specification\Table.sldtbt", 4, 2)End Sub
The path I gave was just an example. For you case, the path would be
Retrieving data ...