Good Morning to you all!
So my eventual goal is to take a sheet metal part with all manually entered values and change it so they use a gauge table and bend table. I have an idea of how i need to go about doing this but am getting caught up in some code that is from the solidworks help.
Right now I am trying to set the gauge table path but it keeps throwing up an error(telling me that the object or with variable are not defined) and I am unsure as to why. I would be willing to bet that I am misisng some slice of code but everything looks correct. Keep in mind that I'm just beginning to work on this so it is a bit sloppy because I havent added everything in yet.
Thanks in advance for any help you can give me!
-Trevor
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swFeat As SldWorks.Feature
Public swSubFeat As SldWorks.Feature
Public swSelMgr As SldWorks.SelectionMgr
Public Const STOCK_XREF As String = "J:\CP LIBRARY\CP-KRAUSE MATERIAL REFERENCE.xlsx"
Public Const CP_STEEL As String = "J:\Toolbox\Templates\Ga. Tables\CP-STEEL.xls"
Public Const CP_BEND As String = "J:\Toolbox\Templates\Ga. Tables\CP-BEND DEDUCTIONS.xls"
Public kStock As String
Public cpStock As String
Public customPropertyMgr As SldWorks.CustomPropertyManager
Public boolStatus As Boolean
Public gaugeTable As String
Option Explicit
Function Stock_Convert()
Dim myExcelApp As Object
Dim xlSheet As Variant
'Open excel workbook
Set myExcelApp = CreateObject("Excel.Application")
myExcelApp.Visible = False
myExcelApp.Workbooks.Open FileName:=STOCK_XREF
'get cpStock from .xls file
Set xlSheet = myExcelApp.ActiveSheet
Dim y As Double
y = 1
Do While y < 10000
If xlSheet.Cells(y, 3) = kStock Then
cpStock = xlSheet.Cells(y, 1)
Exit Do
Else
y = y + 1
End If
Loop
End Function
Sub Process_SMBaseFlange _
( _
swApp As SldWorks.SldWorks, _
swModel As SldWorks.ModelDoc2, _
swFeat As SldWorks.Feature _
)
Debug.Print " +" & swFeat.Name & " [" & swFeat.GetTypeName & "]"
Dim swBaseFlange As SldWorks.BaseFlangeFeatureData
Set swBaseFlange = swFeat.GetDefinition
swBaseFlange.UseGaugeTable = True
swBaseFlange.GaugeTablePath = CP_STEEL
'Debug.Print " Gauge Table = " & swBaseFlange.GaugeTablePath
'swBaseFlange.GaugeTablePath = CP_STEEL
End Sub
Sub Main()
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
Set customPropertyMgr = swModel.Extension.CustomPropertyManager("")
Set swFeat = swModel.FirstFeature
swFeat.Select2 True, 1
'get kstocknumber
kStock = swModel.GetCustomInfoValue("", "kstockNumber")
'figure out what stock number/material needs to be used
If swModel.GetType = 1 Then
Stock_Convert
Process_SMBaseFlange swApp, swModel, swFeat
Else
MsgBox "Can only be used on parts, not assemblies"
End
End If
End Sub