iLogic Error

iLogic Error

Anonymous
Not applicable
879 Views
12 Replies
Message 1 of 13

iLogic Error

Anonymous
Not applicable

Can anyone run this code? Do you get an error? If an error occurs, how is said error corrected?

 

SyntaxEditor Code Snippet

Public Sub Main()

    ' Get the active assembly. 
    Dim oAsmDoc As AssemblyDocument 
    oAsmDoc = ThisApplication.ActiveDocument 
    
    
    Call TraverseAssembly(oAsmDoc.ComponentDefinition.Occurrences, 1)

End Sub 

Private Sub TraverseAssembly(Occurrences As ComponentOccurrences, _ 
                             Level As Integer) 
    
    Dim oOcc As ComponentOccurrence 
    For Each oOcc In Occurrences 
    
    If oOcc.Definition.BOMStructure = BOMStructureEnum.kPurchasedBOMStructure
         oOcc.Definition.Document.PropertySets.Item("Inventor User Defined Properties").Item("WO#").Value = "S"
    End If
    
        ' Check to see if this occurrence represents a subassembly 
        ' and recursively call this function to traverse through it. 
        If oOcc.DefinitionDocumentType = kAssemblyDocumentObject Then
            Call TraverseAssembly(oOcc.SubOccurrences, Level + 1) 
        End If 
    Next
End Sub
0 Likes
880 Views
12 Replies
Replies (12)
Message 2 of 13

MechMachineMan
Advisor
Advisor
Did you get an error running this code, or why are you asking?

--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.

Justin K
Inventor 2018.2.3, Build 227 | Excel 2013+ VBA
ERP/CAD Communication | Custom Scripting
Machine Design | Process Optimization


iLogic/Inventor API: Autodesk Online Help | API Shortcut In Google Chrome | iLogic API Documentation
Vb.Net/VBA Programming: MSDN | Stackoverflow | Excel Object Model
Inventor API/VBA/Vb.Net Learning Resources: Forum Thread

Sample Solutions:Debugging in iLogic ( and Batch PDF Export Sample ) | API HasSaveCopyAs Issues |
BOM Export & Column Reorder | Reorient Skewed Part | Add Internal Profile Dogbones |
Run iLogic From VBA | Batch File Renaming| Continuous Pick/Rename Objects

Local Help: %PUBLIC%\Documents\Autodesk\Inventor 2018\Local Help

Ideas: Dockable/Customizable Property Browser | Section Line API/Thread Feature in Assembly/PartsList API Static Cells | Fourth BOM Type
0 Likes
Message 3 of 13

Anonymous
Not applicable

yes

 

error message.jpg

0 Likes
Message 4 of 13

Anonymous
Not applicable

and

 

error message.jpg

0 Likes
Message 5 of 13

MechMachineMan
Advisor
Advisor
Try running it from your master LOD and see if that makes any difference

--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.

Justin K
Inventor 2018.2.3, Build 227 | Excel 2013+ VBA
ERP/CAD Communication | Custom Scripting
Machine Design | Process Optimization


iLogic/Inventor API: Autodesk Online Help | API Shortcut In Google Chrome | iLogic API Documentation
Vb.Net/VBA Programming: MSDN | Stackoverflow | Excel Object Model
Inventor API/VBA/Vb.Net Learning Resources: Forum Thread

Sample Solutions:Debugging in iLogic ( and Batch PDF Export Sample ) | API HasSaveCopyAs Issues |
BOM Export & Column Reorder | Reorient Skewed Part | Add Internal Profile Dogbones |
Run iLogic From VBA | Batch File Renaming| Continuous Pick/Rename Objects

Local Help: %PUBLIC%\Documents\Autodesk\Inventor 2018\Local Help

Ideas: Dockable/Customizable Property Browser | Section Line API/Thread Feature in Assembly/PartsList API Static Cells | Fourth BOM Type
0 Likes
Message 6 of 13

Anonymous
Not applicable

same result

0 Likes
Message 7 of 13

Anonymous
Not applicable

By the way, I am grateful for the help.

0 Likes
Message 8 of 13

MechMachineMan
Advisor
Advisor

Try this:

 

Public Sub Main()

    ' Get the active assembly. 
    Dim oAsmDoc As AssemblyDocument 
    oAsmDoc = ThisApplication.ActiveDocument 
    
    
    Call TraverseAssembly(oAsmDoc.ComponentDefinition.Occurrences, 1)

End Sub 

Private Sub TraverseAssembly(Occurrences As ComponentOccurrences, _ 
                             Level As Integer) 
    
    Dim oOcc As ComponentOccurrence 
    For Each oOcc In Occurrences 
    
    If oOcc.Definition.BOMStructure = BOMStructureEnum.kPurchasedBOMStructure
         Try
             oOcc.Definition.Document.PropertySets.Item("Inventor User Defined Properties").Item("WO#").Value = "S"
         Catch
             If MsgBox("iProp WO# does not exist. Create?",MsgBoxStyle.YesNo,"Rules") = MsgBoxResult.Yes
		oOcc.Definition.Document.PropertySets.Item("Inventor User Defined Properties").Add("S", "WO#")
             End if
         End Try
    End if

 ' Check to see if this occurrence represents a subassembly 
        ' and recursively call this function to traverse through it. 
        If oOcc.DefinitionDocumentType = DocumentTypeEnum.kAssemblyDocumentObject Then
            Call TraverseAssembly(oOcc.SubOccurrences, Level + 1) 
        End If 
    Next
End Sub

--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.

Justin K
Inventor 2018.2.3, Build 227 | Excel 2013+ VBA
ERP/CAD Communication | Custom Scripting
Machine Design | Process Optimization


iLogic/Inventor API: Autodesk Online Help | API Shortcut In Google Chrome | iLogic API Documentation
Vb.Net/VBA Programming: MSDN | Stackoverflow | Excel Object Model
Inventor API/VBA/Vb.Net Learning Resources: Forum Thread

Sample Solutions:Debugging in iLogic ( and Batch PDF Export Sample ) | API HasSaveCopyAs Issues |
BOM Export & Column Reorder | Reorient Skewed Part | Add Internal Profile Dogbones |
Run iLogic From VBA | Batch File Renaming| Continuous Pick/Rename Objects

Local Help: %PUBLIC%\Documents\Autodesk\Inventor 2018\Local Help

Ideas: Dockable/Customizable Property Browser | Section Line API/Thread Feature in Assembly/PartsList API Static Cells | Fourth BOM Type
0 Likes
Message 9 of 13

Anonymous
Not applicable

Threw up errors again. Here is a screen shot of that information.

 

error 8-25-15.jpg

 

more info 8-25-15.jpg

0 Likes
Message 10 of 13

MechMachineMan
Advisor
Advisor

I have a really good idea what's wrong. But I'm going to let you figure it out.

 

Look at your error windows and read.

 

One of the lines sticks out as familiar - "get.BomStructure"

 

This tells us it's either that function or something invoked by/related to that function.

 

Run a basic name check of the occurrences and let me know how that goes.

 

Let me know if you see anything weird.

 

 

Public Sub Main()

    ' Get the active assembly. 
    Dim oAsmDoc As AssemblyDocument 
    oAsmDoc = ThisApplication.ActiveDocument 
    
    
    Call TraverseAssembly(oAsmDoc.ComponentDefinition.Occurrences, 1)

End Sub 

Private Sub TraverseAssembly(Occurrences As ComponentOccurrences, _ 
                             Level As Integer) 
    
    Dim oOcc As ComponentOccurrence 
    For Each oOcc In Occurrences 
              MsgBox(oOcc.Name
 
 ' Check to see if this occurrence represents a subassembly 
        ' and recursively call this function to traverse through it. 
        If oOcc.DefinitionDocumentType = DocumentTypeEnum.kAssemblyDocumentObject Then
            Call TraverseAssembly(oOcc.SubOccurrences, Level + 1) 
        End If 
    Next
End Sub

--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.

Justin K
Inventor 2018.2.3, Build 227 | Excel 2013+ VBA
ERP/CAD Communication | Custom Scripting
Machine Design | Process Optimization


iLogic/Inventor API: Autodesk Online Help | API Shortcut In Google Chrome | iLogic API Documentation
Vb.Net/VBA Programming: MSDN | Stackoverflow | Excel Object Model
Inventor API/VBA/Vb.Net Learning Resources: Forum Thread

Sample Solutions:Debugging in iLogic ( and Batch PDF Export Sample ) | API HasSaveCopyAs Issues |
BOM Export & Column Reorder | Reorient Skewed Part | Add Internal Profile Dogbones |
Run iLogic From VBA | Batch File Renaming| Continuous Pick/Rename Objects

Local Help: %PUBLIC%\Documents\Autodesk\Inventor 2018\Local Help

Ideas: Dockable/Customizable Property Browser | Section Line API/Thread Feature in Assembly/PartsList API Static Cells | Fourth BOM Type
0 Likes
Message 11 of 13

Anonymous
Not applicable

it did partially work & I think I noticed it wanted the part to be checked out by the user running the code.

0 Likes
Message 12 of 13

Anonymous
Not applicable

This is all greek to me. I have no idea where to start. However, when I tried the rule on a single subassembly with just parts, it worked well. SO maybe the problem is the subassemblies within an assembly?

0 Likes
Message 13 of 13

Anonymous
Not applicable

I noticed I had less problem when I had everything checked out. Other than that. I have no idea. I'm such a novice with code that I don't know where to start to look.

0 Likes