Code:
Sub ZeichnungenAusBG()Dim oApp As Application
Set oApp = ThisApplication
Dim oDoc As Document
Dim oAsmDoc As AssemblyDocument
Dim oPrtDoc As PartDocument
Dim oDrwDoc As DrawingDocument
Dim sDrwNamePath As String
Dim oSheet As Sheet
Dim Punkt As Point2d
Dim oDocType As DocumentTypeEnum
Set oDoc = oApp.ActiveDocument
oDocType = oDoc.DocumentType
Dim oRefDoc As Document
Dim oAllRefDocs As DocumentsEnumerator
Dim sTemplate As String
sTemplate = oApp.DesignProjectManager.ActiveDesignProject.TemplatesPath & "Norm.idw" 'Norm.idw muss im Vorlagenordner liegen!!
oApp.SilentOperation = True
If oDocType = kAssemblyDocumentObject Then
Set oAllRefDocs = oDoc.AllReferencedDocuments
For Each oRefDoc In oAllRefDocs
If oRefDoc.DocumentType = kPartDocumentObject Then
oApp.Documents.Open oRefDoc.FullDocumentName
Set oDoc = oApp.ActiveDocument
Set oDrwDoc = oApp.Documents.Add(DocumentTypeEnum.kDrawingDocumentObject, sTemplate)
Set oSheet = oDrwDoc.ActiveSheet
Set Punkt = oApp.TransientGeometry.CreatePoint2d(10, 10)
Call oSheet.DrawingViews.AddBaseView(oDoc, Punkt, 1, kFrontViewOrientation, kHiddenLineRemovedDrawingViewStyle)
sDrwNamePath = Left(oRefDoc.FullFileName, Len(oRefDoc.FullFileName) - 4) & ".idw"
Call oDrwDoc.SaveAs(sDrwNamePath, False)
Call oRefDoc.Close
End If
Next
End If
oApp.SilentOperation = False
End Sub