×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Error 91 when Part.GetCustomInfoValue - I screwed something up

Error 91 when Part.GetCustomInfoValue - I screwed something up

Error 91 when Part.GetCustomInfoValue - I screwed something up

(OP)
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?

RE: Error 91 when Part.GetCustomInfoValue - I screwed something up

shawn76o,
As a side note, nothing to do with your program. I too, make a lot of changes to my VB programs, sometimes they work and sometimes they do not. What I have started doing is keeping a history folder of working programs.
E.g.
CopyProperties_12-04-06
CopyProperties_12-05-06
CopyProperties_12-05-06a    for same days changes
CopyProperties_12-06-06

Bradley
SolidWorks 2007 SP2.0

RE: Error 91 when Part.GetCustomInfoValue - I screwed something up

shawn76o,

Maybe I missed this in your code but I do not see any checks that any 2nd Child components exist?

SA

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources