Using SW Equations to drive document properties.
Using SW Equations to drive document properties.
(OP)
- Sorry if this has already been asked, could not find specific question -
Hey all, my company uses SW to create various sheet metal parts (different types of material and thickness). We have a sheet metal template that we use to design a new part, but at the end of the project, I find myself spending countless hours filling in the document properties for every part that I make:
Stock Number (this is a raw material number, it tells our system what type of raw sheet metal we need in order to cut the part for example LSPL03060 would be 3/16 ASTM A36 sheet metal). The Stock number in our system is driven by the thickness of the part, and the material.
Material Description (sense its sheet metal, we typically put in "Plate 'thickness'"). Material description is driven directly by material thickness
And then of course Material (which is simply the sheet metal material). This is obviously driven directly by the Material that is selected.
The Material Description and Material properties are very simple to do (using the built in commands in the document property tab).
I have yet to figure out a way to auto fill in the Stock Number depending upon the values of the Material description and the material properties. First, I tried an easy fix, and made a configuration for each specific Stock Number we have (15 or so), that way if you designed a part, and find out it needs to be a different thickness, all you had to do was change the configuration in the upper assembly, and it automatically changed everything for you. The problem with this method is that the part file is huge (because it is carrying around every configuration of every part) and there are a lot of glitches when you change the configuration (features get suppressed, ect).
So now I have been trying several different ways to create variables in SW (too many to list) that could be used in the document properties to assign characters instead of numbers. I have a strong background in Matlab programming, but I have not even scratched the surface as to what goes on behind the scenes in SW.
Here is my logic behind what I want to happen: someone opens a sheetmetal template that I made. They will design the part, and in the tree assign the correct material, and thickness desired. I would like to have a table that lists the stock number, and has the correct combination of material thickness and type that defines the stock number. So lets say someone assigns ASTM A36 steel, and 0.1875 in the tree, the equation would then look into a table (design table maybe) and filter through every combination listed using an and statement. If it finds the correct combination, set a variable equal to LSPL03060. If it does not find the combination, set it to "undefined".
Is this possible in SW? Is there any easier way?
Sorry for the long post, but I like to be as clear as possible, so that we stay on topic..
Hey all, my company uses SW to create various sheet metal parts (different types of material and thickness). We have a sheet metal template that we use to design a new part, but at the end of the project, I find myself spending countless hours filling in the document properties for every part that I make:
Stock Number (this is a raw material number, it tells our system what type of raw sheet metal we need in order to cut the part for example LSPL03060 would be 3/16 ASTM A36 sheet metal). The Stock number in our system is driven by the thickness of the part, and the material.
Material Description (sense its sheet metal, we typically put in "Plate 'thickness'"). Material description is driven directly by material thickness
And then of course Material (which is simply the sheet metal material). This is obviously driven directly by the Material that is selected.
The Material Description and Material properties are very simple to do (using the built in commands in the document property tab).
I have yet to figure out a way to auto fill in the Stock Number depending upon the values of the Material description and the material properties. First, I tried an easy fix, and made a configuration for each specific Stock Number we have (15 or so), that way if you designed a part, and find out it needs to be a different thickness, all you had to do was change the configuration in the upper assembly, and it automatically changed everything for you. The problem with this method is that the part file is huge (because it is carrying around every configuration of every part) and there are a lot of glitches when you change the configuration (features get suppressed, ect).
So now I have been trying several different ways to create variables in SW (too many to list) that could be used in the document properties to assign characters instead of numbers. I have a strong background in Matlab programming, but I have not even scratched the surface as to what goes on behind the scenes in SW.
Here is my logic behind what I want to happen: someone opens a sheetmetal template that I made. They will design the part, and in the tree assign the correct material, and thickness desired. I would like to have a table that lists the stock number, and has the correct combination of material thickness and type that defines the stock number. So lets say someone assigns ASTM A36 steel, and 0.1875 in the tree, the equation would then look into a table (design table maybe) and filter through every combination listed using an and statement. If it finds the correct combination, set a variable equal to LSPL03060. If it does not find the combination, set it to "undefined".
Is this possible in SW? Is there any easier way?
Sorry for the long post, but I like to be as clear as possible, so that we stay on topic..






RE: Using SW Equations to drive document properties.
The down side is that users would have to run it. If they did not run it after changing the thickness or material, then the stock number would be incorrect. I do not know of a way that would automatically update.
It would also be possible write a slightly more complex macro that iterated over all of the files in a directory or all of the components in an assembly and set the stock number based on the material and the thickness.
Eric
RE: Using SW Equations to drive document properties.
I have played around with macros a little, would definitely be something to look into. I am sure there is a way to make it so that the macro runs every time the part or assembly is rebuilt right? Also, could I simply save the macro onto our server so that anyone who opens the template will get the macro as well?
I guess its time to do some research about macros!
I had another idea that might work that I may try tomorrow.
What if i were to set up a variable for each stock number we have and set it equal to the thickness of material for the stock number. Where by entering the stock number into the base flange for thickness will assign it the appropriate thickness for that stock number. Then the only thing is to be able to call out the variable used inside the document properties. The down sides I see with this is that every time you want to change the thickness of the material, you would have to enter a ridiculous number in order to keep the properties consistent, and the other down side is figuring out how to get it to work lol.
I am just throwing ideas out there, and I welcome any other alternatives, cause messing around with little things like this is how I learn best..
RE: Using SW Equations to drive document properties.
h
The example files can be downloaded from
https://forum.solidworks.com/thread/42011
-handleman, CSWP (The new, easy test)
RE: Using SW Equations to drive document properties.
I looked over what you gave me, but I don't think I have enough VBA experience to do this with a marco.. I have not lost interest in VBA, I am learning a lot about it, but attempting something that I want to do seems like a 10 mile marathon, where I need to start out with the 1/4 mile marathon and work my way up.
however, maybe there is a simpler way after all, but I will definitely need some help.
So I made an excel sheet that will do exactly what I want SW to do.
The file is attached so you can see what I did.
So when someone makes a sheet metal part in SW, they will need to set the material thickness, and fortunately every stock number has a different thickness.
So in the excel sheet, the green box is the thickness of the material, the red box is just for reference to the matrix in cells A1:C9, and the blue boxes are the properties extracted from the thickness input.
At the bottom of the file is a list of all the stock numbers we use, so by entering any one of those decimals into the thickness cell will call out the correct stock number, material and material description.
- - Here is where I need assistance - -
How can I get SW to automatically enter the thickness of the material into the correct cell, then set the values in the blue cells to the corresponding document properties?
This seems like an easier task to accomplish because I understand excel programming better than VBA (for the time being), and it seems like SW could use this almost as a design table? (if it can, I would love to hear how!)
Let me know if this sparked any ideas!
RE: Using SW Equations to drive document properties.
RE: Using SW Equations to drive document properties.
Is there any good websites that explain the SW VBA or API commands (whichever ones are specific to SW)? I have been using the API Help through SW, but I am having trouble understanding specific things and what they do. For example:
Set swApp = CreateObject("sldWorks.Application")
Using logic I believe that it is "Setting" a variable "swApp" equal to the "sldWorks.Applicaion". (please correct me if I am wrong)
I also understand that CreateObject, creates and object, but I am having understanding what that is doing for the program. Why did the "sldWorks.Application" need to be created?
I apologize for the elementary questions, I am trying to figure out how the simple things work so that I know why I need to use them.
The overall goal that I am trying to accomplish with my program is to set various properties under the custom tab in the document properties. Through the API Help in SW, I have found example programs that explain how to get and set File Summary Information (which is the summary tab of the document properties).
There are a couple websites I found that may assist others that are new to this VBA/API thing:
This one is a downloadable power point presentation:
http://w
This one is very helpful in showing beginners how to use excel to drive various SW parameters:
http://s
RE: Using SW Equations to drive document properties.
Can someone explain how to get the thickness of a sheet metal part in VBA?
The API Help in SW is very hard for me to understand (and I can'f for the life of me get it to work)
The Help File Says:
Dim instance As ISheetMetalFeatureData
Dim value As Double
instance.Thickness = value
value = instance.Thickness
That makes sense to me, but how do you actually do this in a program?
RE: Using SW Equations to drive document properties.
Here's an example that I use for custom BOM length quantities. So they show up in a SW BOM table automatically. It doesn't give you everything, but that code will search every feature & dimension for the given dimension name. Just be careful not to make multiple dimensions with the same name as it only takes the first instance. If you can't figure out how to get the filename as a string, and configname I can provide an example of those seperately as well.
--------------------
Public swFeat As SldWorks.Feature
Public swSubFeat As SldWorks.Feature
Public swDim As SldWorks.Dimension
Public swDispDim As SldWorks.DisplayDimension
Public swAnnotation As SldWorks.Annotation
Public boolstatus As Boolean
Public ToggleBOMQtyDim As Integer
Public ToggleBOMQtyExists As Integer
Public DimName As String
Public FeatName As String
Public SubFeatName As String
Sub SetPropBOMQty()
ToggleBOMQtyDim = 0
Set swFeat = swModelDoc.FirstFeature
Do While Not swFeat Is Nothing
Set swSubFeat = swFeat.GetFirstSubFeature
Do While Not swSubFeat Is Nothing
Set swDispDim = swSubFeat.GetFirstDisplayDimension
Do While Not swDispDim Is Nothing
Set swAnnotation = swDispDim.GetAnnotation
DimName = swAnnotation.GetName
If DimName = "BOMQty" And ToggleBOMQtyDim = 0 Then
SubFeatName = swSubFeat.GetNameForSelection(swSelSKETCHES)
CheckBOMQty = """" & DimName & "@" & FeatName & "@@" & ConfigName & "@" & sFileName & """"
Set swDim = swDispDim.GetDimension
ToggleBOMQtyDim = 1
ElseIf DimName = "BOMQty" And ToggleBOMQtyDim = 1 Then
Else
End If
Set swDispDim = swSubFeat.GetNextDisplayDimension(swDispDim)
Loop
Set swSubFeat = swSubFeat.GetNextSubFeature
Loop
Set swDispDim = swFeat.GetFirstDisplayDimension
Do While Not swDispDim Is Nothing
Set swAnnotation = swDispDim.GetAnnotation
DimName = swAnnotation.GetName
If DimName = "BOMQty" And ToggleBOMQtyDim = 0 Then
FeatName = swFeat.GetNameForSelection(swSelSKETCHES)
CheckBOMQty = """" & DimName & "@" & FeatName & "@@" & ConfigName & "@" & sFileName & """"
Set swDim = swDispDim.GetDimension
ToggleBOMQtyDim = 1
ElseIf DimName = "BOMQty" And ToggleBOMQtyDim = 1 Then
Else
End If
Set swDispDim = swFeat.GetNextDisplayDimension(swDispDim)
Loop
Set swFeat = swFeat.GetNextFeature
Loop
End Sub
-------------------------------
Hope that helps.
James Spisich
Design Engineer, CSWP
RE: Using SW Equations to drive document properties.
Any suggestions as to why this is? Here is my Excel macro code:
SUB
Set swApp = CreateObject("SldWorks.Application")
Set swModel = swApp.ActiveDoc
Set swEqnMgr = swModel.GetEquationMgr
Dim Thick As Double
Thick = swEqnMgr.Value(Thickness)
Excel.Range("A14") = Thick
END SUB
I have tried setting Thick as an integer, but it did not work either. Any suggestions?
RE: Using SW Equations to drive document properties.