06-25-2024
07:55 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
06-25-2024
07:55 PM
Hi @Shag_Bore
I quickly reviewed the code and couldn't really see the issue, so I can only offer a little advice having done this process before.
- If you have narrowed your problem area set up some logger statements and check the occurrence name is being logically reached based on needing to be visible or not.
- I would suggest to use Try Catch Statements over On Error Resume Next. You really have no indication of what is happening with the On Error methods.
- I see two leaf occurrences loops are they both needed or could you put it in a function or to store the occurrences as a list of occurrences?
- i see you create weekly typed Collections rather than to explicitly declare the type. Example for string. this can help narrow down issues if the wrong object type gets added into the collection.
Dim list as New List (Of String)
Dim occList as New List (Of ComponentOccurrence)
- If this section of code is designed to get the filename without extension then I would suggest to change it to System IO method as it has less lines. The method here looks more like old VBA methods.
' Locate the last backslash position in the full file name
Dim FNamePos As Long
FNamePos = InStrRev(docFile.FullFileName, "\", -1)
' Remove path from part file name
Dim docFName As String
docFName = Right(docFile.FullFileName, Len(docFile.FullFileName) - FNamePos)
' Remove extension from part file name
Dim ShortName As String
ShortName = Left(docFName, Len(docFName) - 4)
You actually use it further down the code.
ShortName = System.IO.Path.GetFileNameWithoutExtension(oCompOcc.ReferencedDocumentDescriptor.ReferencedFileDescriptor.FullFileName)
- In this section there is a good lot of code duplication with the same definition variables used in different places all the way through the code. It will work but it could lead to issues identifying what is going on especially when trying to target sub assemblies etc.
' Define current document
Dim openDoc As Document
openDoc = ThisDoc.Document
Dim oTrans As Transaction
oTrans = ThisApplication.TransactionManager.StartTransaction(openDoc, "Create View Rep's")
On Error Goto ErrorHandler
' Set a reference to the assembly component definition.
' This assumes an assembly document is open.
Dim oAsmCompDef As AssemblyComponentDefinition
oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition
' Look at all of the components in the assembly
Dim oCompDef As Inventor.ComponentDefinition
oCompDef = openDoc.ComponentDefinition
If this solved a problem, please click (accept) as solution.
Or if this helped you, please, click (like)
Regards
Alan
Or if this helped you, please, click (like)
Regards
Alan