shawn76o
Nuclear
- Nov 14, 2006
- 31
My code seemed to be working fine earlier, and I was actually getting the custom properties for the parts, but somewhere I screwed something up in my haste.
Here is the extent of my code:
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Const swDocAssembly = 2
Option Explicit
Public docType As Integer
Public swApp As SldWorks.SldWorks
Public swModel As SldWorks.ModelDoc2
Dim returnOK As Boolean
Public Part As Object
Sub cmdPreScan_Click()
Dim swRootComp As SldWorks.Component2
Dim swConf As SldWorks.Configuration
Set swApp = CreateObject("SldWorks.Application")
swApp.visible = True
Set swModel = swApp.ActiveDoc
If swModel Is Nothing Then
Call MsgBox("A SolidWorks document needs to be loaded!", vbExclamation, "Custom Properties") ' Display error message
returnOK = False
swApp.visible = True
End ' If no model currently loaded, then exit
Else
docType = swModel.GetType
If (docType = swDocAssembly) Then
Set swConf = swModel.GetActiveConfiguration
Set swRootComp = swConf.GetRootComponent
'Traverse assembly
TraverseComponent swRootComp
Else
MsgBox ("File is not assembly")
End 'Exit if file is not assembly
'Code for parts and drawings to be added later
End If
End If
End Sub
Sub TraverseComponent(swComp As SldWorks.Component2)
'this recursively traverses all of the components in an assembly
Dim vChildComp As Variant
Dim swChildComp As SldWorks.Component2
Dim ModName As String
Dim i As Integer
Dim vChildComp2 As Variant
Dim i2 As Integer
Dim swChildComp2 As SldWorks.Component2
Dim vChildComp3 As Variant
Dim i3 As Integer
Dim swChildComp3 As SldWorks.Component2
Dim Pass As Boolean
Dim Matl As String
Dim itmX As ListItem
Dim MatCase As String
Dim ThkCase As String
Dim VolCase As String
Dim strTemp As String
'Set up the Parts list box
With PartsList
' Create the column headers.
.ListItems.Clear
.ColumnHeaders.Clear
.ColumnHeaders.Add , , "PART NUMBER"
.ColumnHeaders.Add , , "MATERIAL"
.ColumnHeaders.Add , , "VOLUME"
.ColumnHeaders.Add , , "THICKNESS"
.View = lvwReport
.Sorted = False
End With
'Get the childrent of this component
vChildComp = swComp.GetChildren
'Get children on 1st level
For i = 0 To UBound(vChildComp)
ProgressBar.Value = (i / UBound(vChildComp) * 100)
Set swChildComp = vChildComp(i)
ModName = swChildComp.Name
'Set the Part object
Set Part = swChildComp.GetModelDoc()
strTemp = Part.GetCustomInfoValue("", "Description")
If (False = swChildComp.IsSuppressed) And (False = swChildComp.ExcludeFromBOM) Then
Pass = False
Matl = Part.GetCustomInfoValue("", MatCase)
'Check for Material property
Call CheckMatl(Matl, Pass)
If Pass = True Then
If False = (Part.GetCustomInfoValue("", VolCase) <> "") Or False = (Part.GetCustomInfoValue("", ThkCase) <> "") Then
Set itmX = PartsList.ListItems.Add(1, , swChildComp.Name)
itmX.SubItems(1) = Part.GetCustomInfoValue("", MatCase)
itmX.SubItems(2) = Part.GetCustomInfoValue("", VolCase)
itmX.SubItems(3) = Part.GetCustomInfoValue("", ThkCase)
End If
End If
'Set the Child variant
vChildComp2 = swChildComp.GetChildren
'Get children on 2nd level
For i2 = 0 To UBound(vChildComp2)
Set swChildComp2 = vChildComp2(i2)
Set Part = swChildComp2.GetModelDoc()
'Check case for "Material" custom prop
'HERE IS WHERE I'M GETTING ERROR 91
strTemp = Part.GetCustomInfoValue("", "Description")
If strTemp <> "" Then
MatCase = "Material"
End If
If (False = swChildComp2.IsSuppressed) And (False = swChildComp2.ExcludeFromBOM) Then
Pass = False
Matl = Part.GetCustomInfoValue("", MatCase)
'Check for Material property
Call CheckMatl(Matl, Pass)
If Pass = True Then
If False = (Part.GetCustomInfoValue("", VolCase) <> "") Or False = (Part.GetCustomInfoValue("", ThkCase) <> "") Then
Set itmX = PartsList.ListItems.Add(1, , swChildComp2.Name)
itmX.SubItems(1) = Part.GetCustomInfoValue("", MatCase)
itmX.SubItems(2) = Part.GetCustomInfoValue("", VolCase)
itmX.SubItems(3) = Part.GetCustomInfoValue("", ThkCase)
End If
End If
'Set the Child variant
vChildComp3 = swChildComp2.GetChildren
'Get childrent on 3rd level
For i3 = 0 To UBound(vChildComp3)
Set swChildComp3 = vChildComp3(i3)
Set Part = swChildComp3.GetModelDoc()
If (False = swChildComp3.IsSuppressed) And (False = swChildComp3.ExcludeFromBOM) Then
Pass = False
Matl = Part.GetCustomInfoValue("", MatCase)
'Check for Material property
Call CheckMatl(Matl, Pass)
If Pass = True Then
If False = (Part.GetCustomInfoValue("", VolCase) <> "") Or False = (Part.GetCustomInfoValue("", ThkCase) <> "") Then
Set itmX = PartsList.ListItems.Add(1, , swChildComp3.Name)
itmX.SubItems(1) = Part.GetCustomInfoValue("", MatCase)
itmX.SubItems(2) = Part.GetCustomInfoValue("", VolCase)
itmX.SubItems(3) = Part.GetCustomInfoValue("", ThkCase)
End If
End If
End If
Next i3
End If
Next i2
End If
Next i
StatusLabel.Caption = "Finished!"
End Sub
Public Sub CheckMatl(Matl As String, Pass As Boolean)
Select Case Matl
Case "20102", "20105", "20112", "20114", "30009", "30098", "30099", _
"31060", "31102", "31103", "31104", "31105", "31113", "31117", "31237", _
"31266", "31275", "31355", "31357"
'Material is valid and properties will be evaluated
Pass = True
End Select
End Sub
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
When it gets to
strTemp = Part.GetCustomInfoValue("", "Description")
I get Error 91 - Object variable or With Block variable not set
I've checked everything I can think of...
What could have gone wrong?
Here is the extent of my code:
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Const swDocAssembly = 2
Option Explicit
Public docType As Integer
Public swApp As SldWorks.SldWorks
Public swModel As SldWorks.ModelDoc2
Dim returnOK As Boolean
Public Part As Object
Sub cmdPreScan_Click()
Dim swRootComp As SldWorks.Component2
Dim swConf As SldWorks.Configuration
Set swApp = CreateObject("SldWorks.Application")
swApp.visible = True
Set swModel = swApp.ActiveDoc
If swModel Is Nothing Then
Call MsgBox("A SolidWorks document needs to be loaded!", vbExclamation, "Custom Properties") ' Display error message
returnOK = False
swApp.visible = True
End ' If no model currently loaded, then exit
Else
docType = swModel.GetType
If (docType = swDocAssembly) Then
Set swConf = swModel.GetActiveConfiguration
Set swRootComp = swConf.GetRootComponent
'Traverse assembly
TraverseComponent swRootComp
Else
MsgBox ("File is not assembly")
End 'Exit if file is not assembly
'Code for parts and drawings to be added later
End If
End If
End Sub
Sub TraverseComponent(swComp As SldWorks.Component2)
'this recursively traverses all of the components in an assembly
Dim vChildComp As Variant
Dim swChildComp As SldWorks.Component2
Dim ModName As String
Dim i As Integer
Dim vChildComp2 As Variant
Dim i2 As Integer
Dim swChildComp2 As SldWorks.Component2
Dim vChildComp3 As Variant
Dim i3 As Integer
Dim swChildComp3 As SldWorks.Component2
Dim Pass As Boolean
Dim Matl As String
Dim itmX As ListItem
Dim MatCase As String
Dim ThkCase As String
Dim VolCase As String
Dim strTemp As String
'Set up the Parts list box
With PartsList
' Create the column headers.
.ListItems.Clear
.ColumnHeaders.Clear
.ColumnHeaders.Add , , "PART NUMBER"
.ColumnHeaders.Add , , "MATERIAL"
.ColumnHeaders.Add , , "VOLUME"
.ColumnHeaders.Add , , "THICKNESS"
.View = lvwReport
.Sorted = False
End With
'Get the childrent of this component
vChildComp = swComp.GetChildren
'Get children on 1st level
For i = 0 To UBound(vChildComp)
ProgressBar.Value = (i / UBound(vChildComp) * 100)
Set swChildComp = vChildComp(i)
ModName = swChildComp.Name
'Set the Part object
Set Part = swChildComp.GetModelDoc()
strTemp = Part.GetCustomInfoValue("", "Description")
If (False = swChildComp.IsSuppressed) And (False = swChildComp.ExcludeFromBOM) Then
Pass = False
Matl = Part.GetCustomInfoValue("", MatCase)
'Check for Material property
Call CheckMatl(Matl, Pass)
If Pass = True Then
If False = (Part.GetCustomInfoValue("", VolCase) <> "") Or False = (Part.GetCustomInfoValue("", ThkCase) <> "") Then
Set itmX = PartsList.ListItems.Add(1, , swChildComp.Name)
itmX.SubItems(1) = Part.GetCustomInfoValue("", MatCase)
itmX.SubItems(2) = Part.GetCustomInfoValue("", VolCase)
itmX.SubItems(3) = Part.GetCustomInfoValue("", ThkCase)
End If
End If
'Set the Child variant
vChildComp2 = swChildComp.GetChildren
'Get children on 2nd level
For i2 = 0 To UBound(vChildComp2)
Set swChildComp2 = vChildComp2(i2)
Set Part = swChildComp2.GetModelDoc()
'Check case for "Material" custom prop
'HERE IS WHERE I'M GETTING ERROR 91
strTemp = Part.GetCustomInfoValue("", "Description")
If strTemp <> "" Then
MatCase = "Material"
End If
If (False = swChildComp2.IsSuppressed) And (False = swChildComp2.ExcludeFromBOM) Then
Pass = False
Matl = Part.GetCustomInfoValue("", MatCase)
'Check for Material property
Call CheckMatl(Matl, Pass)
If Pass = True Then
If False = (Part.GetCustomInfoValue("", VolCase) <> "") Or False = (Part.GetCustomInfoValue("", ThkCase) <> "") Then
Set itmX = PartsList.ListItems.Add(1, , swChildComp2.Name)
itmX.SubItems(1) = Part.GetCustomInfoValue("", MatCase)
itmX.SubItems(2) = Part.GetCustomInfoValue("", VolCase)
itmX.SubItems(3) = Part.GetCustomInfoValue("", ThkCase)
End If
End If
'Set the Child variant
vChildComp3 = swChildComp2.GetChildren
'Get childrent on 3rd level
For i3 = 0 To UBound(vChildComp3)
Set swChildComp3 = vChildComp3(i3)
Set Part = swChildComp3.GetModelDoc()
If (False = swChildComp3.IsSuppressed) And (False = swChildComp3.ExcludeFromBOM) Then
Pass = False
Matl = Part.GetCustomInfoValue("", MatCase)
'Check for Material property
Call CheckMatl(Matl, Pass)
If Pass = True Then
If False = (Part.GetCustomInfoValue("", VolCase) <> "") Or False = (Part.GetCustomInfoValue("", ThkCase) <> "") Then
Set itmX = PartsList.ListItems.Add(1, , swChildComp3.Name)
itmX.SubItems(1) = Part.GetCustomInfoValue("", MatCase)
itmX.SubItems(2) = Part.GetCustomInfoValue("", VolCase)
itmX.SubItems(3) = Part.GetCustomInfoValue("", ThkCase)
End If
End If
End If
Next i3
End If
Next i2
End If
Next i
StatusLabel.Caption = "Finished!"
End Sub
Public Sub CheckMatl(Matl As String, Pass As Boolean)
Select Case Matl
Case "20102", "20105", "20112", "20114", "30009", "30098", "30099", _
"31060", "31102", "31103", "31104", "31105", "31113", "31117", "31237", _
"31266", "31275", "31355", "31357"
'Material is valid and properties will be evaluated
Pass = True
End Select
End Sub
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
When it gets to
strTemp = Part.GetCustomInfoValue("", "Description")
I get Error 91 - Object variable or With Block variable not set
I've checked everything I can think of...
What could have gone wrong?