Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.
nstevelmans
in reply to: inventor4578

Oké see if we can debug this,

  1. We want to know if the Assy can be found, run this code a Message will appear.
Sub main
	  ' Get the active assembly.
        Dim oAsmDoc As AssemblyDocument = ThisApplication.ActiveDocument
        Dim AssyName As String = "framework:1"  'name of the SubAssy
        Dim TemplateName As String = "white.dwg"  'name of the templae
        Dim Scale As String = "1:1" 'scale
        Dim SpacingBetweenViews As Double = 5
        ' Call the function that does the recursion.
        TraverseAssembly(oAsmDoc.ComponentDefinition.Occurrences, 1, AssyName, TemplateName, Scale, SpacingBetweenViews)
				
  End Sub
  
  
    Private Sub TraverseAssembly(Occurrences As ComponentOccurrences, Level As Integer, Name As String, TemplateName As String, scale As String, SpacingViews As Double)
        ' Iterate through all of the occurrence in this collection.  This
        ' represents the occurrences at the top level of an assembly.
        Dim DesignProject = ThisApplication.DesignProjectManager.ActiveDesignProject
        Dim DrawingTemplate As String = System.IO.Path.Combine(DesignProject.TemplatesPath, TemplateName)
        Dim oOcc As ComponentOccurrence
        For Each oOcc In Occurrences
            ' Check to see if this occurrence represents a subassembly
            ' and recursively call this function to traverse through it.
            If oOcc.DefinitionDocumentType = DocumentTypeEnum.kAssemblyDocumentObject Then
                If oOcc.Name = Name Then
                    Dim AssyDoc As AssemblyDocument = oOcc.Definition.Document
					MsgBox("Assy Found" & " " & AssyDoc.FullFileName )
'                    Dim oDrawDoc As DrawingDocument = CreateDrawing(DrawingTemplate)
'                    CreateViews(oDrawDoc, AssyDoc, scale, SpacingViews)
                End If
                TraverseAssembly(oOcc.SubOccurrences, Level + 1, Name, TemplateName, scale, SpacingViews)
            End If
        Next

    End Sub