iLogic-Code
Imports Inventor.ViewOrientationTypeEnum Imports Inventor.DrawingViewStyleEnum Sub Main() Dim Zeich As DrawingDocument Zeich = ThisApplication.ActiveDocument Dim oSheet As Sheet oSheet = Zeich.ActiveSheet 'Modell er esten Ansicht ermitteln Dim Modell As Document Modell = oSheet.DrawingViews.Item(1).ReferencedDocumentDescriptor.ReferencedDocument 'Prüfen ob Modell Blechteil ist Dim sDocumentSubType As String sDocumentSubType = Modell.SubType If sDocumentSubType = "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}" Then 'Abwicklungsansicht erstellen AddFlatPatternDrawingView (Modell.FullFileName) 'Symbol ergänzen Dim SymName As String SymName = "CAD-CAM" Dim oSketchedSymbolDef As SketchedSymbolDefinition oSketchedSymbolDef = Zeich.SketchedSymbolDefinitions.Item(SymName) Dim oTG As TransientGeometry oTG = ThisApplication.TransientGeometry Dim oSketchedSymbol As SketchedSymbol oSketchedSymbol = Zeich.ActiveSheet.SketchedSymbols.Add(oSketchedSymbolDef, oTG.CreatePoint2d(15, 5), 0, 1) Else Exit Sub End If End Sub Public Sub AddFlatPatternDrawingView(Modellpfad As String) ' a reference to the drawing document. ' This assumes a drawing document is active. Dim oDrawDoc As DrawingDocument oDrawDoc = ThisApplication.ActiveDocument ' a reference to the active sheet. Dim oSheet As Sheet oSheet = oDrawDoc.ActiveSheet ' Create a new NameValueMap object Dim oBaseViewOptions As NameValueMap oBaseViewOptions = ThisApplication.TransientObjects.CreateNameValueMap ' the options to use when creating the base view. Call oBaseViewOptions.Add("SheetMetalFoldedModel", False) ' Open the sheet metal document invisibly Dim oModel As Document oModel = ThisApplication.Documents.Open(Modellpfad, False) ' Create the placement point object. Dim oPoint As Point2d oPoint = ThisApplication.TransientGeometry.CreatePoint2d(25, 20) ' Create a base view. Dim oBaseView As DrawingView oBaseView = oSheet.DrawingViews.AddBaseView(oModel, oPoint, 0.3, _ kDefaultViewOrientation, kHiddenLineRemovedDrawingViewStyle, _ , , oBaseViewOptions) End Sub
VBA-Code
Private Sub WennBlechDannAbwicklung() Dim Zeich As DrawingDocument Set Zeich = ThisApplication.ActiveDocument Dim oSheet As Sheet Set oSheet = Zeich.ActiveSheet 'Modell er esten Ansicht ermitteln Dim Modell As Document Set Modell = oSheet.DrawingViews.Item(1).ReferencedDocumentDescriptor.ReferencedDocument 'Prüfen ob Modell Blechteil ist Dim sDocumentSubType As String sDocumentSubType = Modell.SubType If sDocumentSubType = "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}" Then 'Abwicklungsansicht erstellen AddFlatPatternDrawingView (Modell.FullFileName) 'Symbol ergänzen Dim SymName As String SymName = "CAD-CAM" Dim oSketchedSymbolDef As SketchedSymbolDefinition Set oSketchedSymbolDef = Zeich.SketchedSymbolDefinitions.Item(SymName) Dim oTG As TransientGeometry Set oTG = ThisApplication.TransientGeometry Dim oSketchedSymbol As SketchedSymbol Set oSketchedSymbol = Zeich.ActiveSheet.SketchedSymbols.Add(oSketchedSymbolDef, oTG.CreatePoint2d(0, 0), 0, 1) Else Exit Sub End If End Sub Public Sub AddFlatPatternDrawingView(Modellpfad As String) ' Set a reference to the drawing document. ' This assumes a drawing document is active. Dim oDrawDoc As DrawingDocument Set oDrawDoc = ThisApplication.ActiveDocument 'Set a reference to the active sheet. Dim oSheet As Sheet Set oSheet = oDrawDoc.ActiveSheet ' Create a new NameValueMap object Dim oBaseViewOptions As NameValueMap Set oBaseViewOptions = ThisApplication.TransientObjects.CreateNameValueMap ' Set the options to use when creating the base view. Call oBaseViewOptions.Add("SheetMetalFoldedModel", False) ' Open the sheet metal document invisibly Dim oModel As Document Set oModel = ThisApplication.Documents.Open(Modellpfad, False) ' Create the placement point object. Dim oPoint As Point2d Set oPoint = ThisApplication.TransientGeometry.CreatePoint2d(25, 20) ' Create a base view. Dim oBaseView As DrawingView Set oBaseView = oSheet.DrawingViews.AddBaseView(oModel, oPoint, 1, _ kDefaultViewOrientation, kHiddenLineRemovedDrawingViewStyle, _ , , oBaseViewOptions) End Sub
Bemerkungen
Das ist natürlich nur ein grobes Codegerüst:
- Hat das Blech noch keine Abwicklung scheitert der Code. Da müsste man ggf. prüfen, ob eine Abwicklung vorhanden ist und wenn nicht dann eine erstellen
- Der Ansichtsmaßstab der Abwicklung und deren Position auf dem Blatt müsste abhängig von der Blechgröße und Blattgröße noch ermittelt werden
- ggf. muss die Position des Symbols angepasst werden
Links zum Thema
VBA Code in iLogic Code "umwandeln"
[Quelle]
Hallo,
AntwortenLöschenBin hier auf diesen tollen Code gestoßen.
Habe ihn gleich ausprobiert, und läuft alles perfekt! Danke
Aber wie kann ich den Maßstab automatisch von der Erstansicht übernehmen? Dass sozusagen Erstansicht und Abwicklungsansicht , den selben Maßstab aufweisen!?
Grüße
Lukas