VB.Net-AddIn - adding new sheet to drawing and set border and title block to drawing's ressources

VB.Net-AddIn - adding new sheet to drawing and set border and title block to drawing's ressources

weiser
Advocate Advocate
566 Views
2 Replies
Message 1 of 3

VB.Net-AddIn - adding new sheet to drawing and set border and title block to drawing's ressources

weiser
Advocate
Advocate

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
0 Likes
Accepted solutions (1)
567 Views
2 Replies
Replies (2)
Message 2 of 3

petr.meduna
Advocate
Advocate
Accepted solution

Hello,

you are using sPromtStrings(9) which means ten items, because lists are starting with number zero. Try to use  10 cycles (means for i = 0 to 9) so every item in list can be filled.

 

        ' .. Setzen des Schriftfeldes aus der Vorlage
        Dim sPromptStrings(9) As String
        Dim i As Integer = 0
        For i = 0 To 9                ' Anzahl der Strings müssen mit den
            sPromptStrings(i) = "--"  ' angeforderten Eingaben im Schriftfeld
        Next i                        ' übereinstimmen!

 

 

Message 3 of 3

weiser
Advocate
Advocate

Hi @petr.meduna 

thanks for the solution.

To clarify this for some other people who runinto the same issue:

Inventor seems to number the arrays from e.g. 1...10. The array index 0 (e.g. .....BorderDefinitions.Item(0)) seems not to be used. So when sending an array you have to make sure, that the "last index can be accessed", means for my title block there are 10 things prompted, so I have to define an array with 10+1 (for the zero-index) element.

 

So the correct code for me is:

' .. Setzen des Schriftfeldes aus der Vorlage
Dim sPromptStrings(11) As String
Dim i As Integer = 0
For i = 0 To 11 ' Anzahl der Strings müssen mit den
sPromptStrings(i) = "--" ' angeforderten Eingaben im Schriftfeld + 1
Next i ' übereinstimmen!

 

So again, thanks a lot!!!