- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi there,
again I stuck while switching from VBA (which works fine) to VB.NET
As written in the title I like to add a new sheet to the active drawing document and set its border an title block to ressources wihtin the drawing-file.
So I thought I just take the VBA-code and be happy .... but in both cases I get an error when trying to apply the given ressources. Because I'm using Inventor's default border I found a workaround for that. The original VBA-code which is not working with VB.NET can be found in the comments below the MsgBox #2.
... But I really get stucked in applying the title block. Maybe there is something wrong with values / references....
The error is in the line: oSheet.AddTitleBlock(oTitleBlockDef, , sPromptStrings)
The code is stopping even without giving the sPromptStrings.
When reading the API-Reference it's said that:
TitleBlockDefinition / Variant/ Input Variant that specifies which TitleBlockDefinition to use. The input for the argument can be either a TitleBlockDefinition object or string containing the name of an existing TitleBlockDefinition object.
So it should be possible to use the command above like: oSheet.AddTitleBlock("DIN 7200 (iLogic)", , sPromptStrings)
But this also didn't work.
It might be just a little step for you, but a big one for my nerves .... So I would be glad if you could give me some advise 😉
Regards
'--------------------------------------------------------------
' Fügt ein neues Zeichenblatt in der aktuellen Zeichnung ein
'--------------------------------------------------------------
Public Sub CommandFunctionZeichnungNeuBlatt()
' Abfrage, ob es sich um ein Zeichnungsdokument handelt
If Not g_inventorApplication.ActiveDocument.DocumentType = Inventor.DocumentTypeEnum.kDrawingDocumentObject _
Then
MsgBox("Funktion kann nur in einer Zeichnung verwendet werden.")
Exit Sub
End If
' Setzen des aktuellen Dokumentes
Dim oDrawDoc As Inventor.DrawingDocument
oDrawDoc = g_inventorApplication.ActiveDocument
' Hinzufügen eines neuen Blattes
oDrawDoc.Sheets.Add
Dim oSheetNumber As Integer = oDrawDoc.Sheets.Count
' Setzen des aktuellen Blatts (das zuletzt hinzugefügte)
Dim oSheet As Inventor.Sheet
oSheet = oDrawDoc.ActiveSheet
MsgBox("#1 / Sheet:" & oSheet.Name)
' Setzen der Standard-Blattgröße und -Ausrichtung
oSheet.Size = Inventor.DrawingSheetSizeEnum.kA4DrawingSheetSize ' A4-Größe
'oSheet.Orientation = Inventor.PageOrientationTypeEnum.kPortraitPageOrientation ' Hochformat
oSheet.Orientation = Inventor.PageOrientationTypeEnum.kLandscapePageOrientation ' Querformat
' Setzen des Standard-Zeichnungsrahmens
' .. Löschen eines ggf. vorhandenen Rahmens
If oSheet.Border IsNot Nothing Then
oSheet.Border.Delete()
End If
oSheet.AddDefaultBorder()
MsgBox("#2 / DefaultBorder")
' .. Setzen des Standardrahmens aus der Vorlage
'Dim oBorder As Inventor.DefaultBorder
'oBorder = oSheet.AddDefaultBorder()
'Dim oBorder As Inventor.Border
'Dim oBorderDef As Inventor.BorderDefinition
'oBorderDef = oDrawDoc.BorderDefinitions.Item("Standardrahmen")
'oBorder = oSheet.AddBorder(oBorderDef)
'Dim borderName As String = "Standardrahmen"
'oBorder = oSheet.AddBorder(borderName)
' Setzen des Schriftfeldes
' .. Löschen eines ggf. vorhandenen Schriftfeldes
If oSheet.TitleBlock IsNot Nothing Then
oSheet.TitleBlock.Delete()
Else
MsgBox("kein Schriftfeld vorhanden!")
End If
' .. Setzen des Schriftfeldes aus der Vorlage
Dim sPromptStrings(9) As String
Dim i As Integer = 0
For i = 0 To 8 ' Anzahl der Strings müssen mit den
sPromptStrings(i) = "--" ' angeforderten Eingaben im Schriftfeld
Next i ' übereinstimmen!
Dim oTitleBlockDef As Inventor.TitleBlockDefinition
oTitleBlockDef = oDrawDoc.TitleBlockDefinitions.Item("DIN 7200 (iLogic)")
MsgBox("Test: " & oTitleBlockDef.Name & " / max: " & oDrawDoc.TitleBlockDefinitions.Count)
Dim oTitleBlock As Inventor.TitleBlock
oTitleBlock = oSheet.AddTitleBlock(oTitleBlockDef, , sPromptStrings)
' Anpassen der Ansicht
g_inventorApplication.ActiveView.Fit()
' Aufrufen des Ausfüll-Dialogs
Dim Run As New RunRule
Run.iLogic("Schriftfeld.Eingabe")
Run = Nothing
End Sub
Solved! Go to Solution.