Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Change Title Block using Visual Basic

2 REPLIES 2
SOLVED
Reply
Message 1 of 3
bretrick30
3157 Views, 2 Replies

Change Title Block using Visual Basic

I am trying to change the title block of the active sheet using visual basic.  I realize this can be done using a snippet in iLogic, but I am creating an external .dll file using Visual Studio.

 

I have tried...

 

ThisDoc.Document.ActiveSheet.TitleBlock.Definition = "Title Block Name"

 

ThisDoc.Document.ActiveSheet.TitleBlock.Definition.Name = "Title Block Name" (This changes the name of the title block in the browser but doesnt swap it out.)

 

Call ThisDoc.Document.ActiveSheet.TitleBlock.Definition("Title Block Name")

 

Thanks,

2 REPLIES 2
Message 2 of 3
nickv02
in reply to: bretrick30

This is from the Programming Help file in Inventor.  I'm sure you can modify it to suit your needs.  It's VBA, but there's just a few tweaks to make it VB.

 

Public Sub InsertTitleBlockOnSheet()
    ' Set a reference to the drawing document.
    ' This assumes a drawing document is active.
    Dim oDrawDoc As DrawingDocument
    Set oDrawDoc = ThisApplication.ActiveDocument

    ' Obtain a reference to the desired border defintion.
    Dim oTitleBlockDef As TitleBlockDefinition
    Set oTitleBlockDef = oDrawDoc.TitleBlockDefinitions.Item("Sample Title Block")

    Dim oSheet As Sheet
    Set oSheet = oDrawDoc.ActiveSheet

    ' Check to see if the sheet already has a title block and delete it if it does.
    If Not oSheet.TitleBlock Is Nothing Then
        oSheet.TitleBlock.Delete
    End If

    ' This title block definition contains one prompted string input.  An array
    ' must be input that contains the strings for the prompted strings.
    Dim sPromptStrings(1 To 2) As String
    sPromptStrings(1) = "String 1"
    sPromptStrings(2) = "String 2"

    ' Add an instance of the title block definition to the sheet.
    Dim oTitleBlock As TitleBlock
    Set oTitleBlock = oSheet.AddTitleBlock(oTitleBlockDef, , sPromptStrings)
End Sub

 

Message 3 of 3

Private Sub OButtonDefA1_OnExecute(ByVal Context As Inventor.NameValueMap) Handles OButtonDefA1.OnExecute
            On Error Resume Next

            Dim oDoc As Inventor.DrawingDocument
            oDoc = m_inventorApplication.ActiveDocument
            Dim sName As String
            If oDoc.Sheets.Count = 1 Then
                If Not Left(oDoc.ActiveSheet.Name, 5) = "00_00" Then
                    sName = "00_00"
                    Call oDoc.Sheets.Add(Inventor.DrawingSheetSizeEnum.kCustomDrawingSheetSize, Inventor.PageOrientationTypeEnum.kLandscapePageOrientation, sName, 80.5, 58.2)
                    oDoc.Sheets.Item(1).Delete(False)
                Else
                    sName = "01_00"
                    Call oDoc.Sheets.Add(Inventor.DrawingSheetSizeEnum.kCustomDrawingSheetSize, Inventor.PageOrientationTypeEnum.kLandscapePageOrientation, sName, 80.5, 58.2)
                End If
            ElseIf oDoc.Sheets.Count > 1 Then
                sName = Format(oDoc.Sheets.Count, "0#") & "_00"
                Call oDoc.Sheets.Add(Inventor.DrawingSheetSizeEnum.kCustomDrawingSheetSize, Inventor.PageOrientationTypeEnum.kLandscapePageOrientation, sName, 80.5, 58.2)
            End If

            Dim oBorder As Inventor.BorderDefinition
            oBorder = oDoc.BorderDefinitions.Item("IP-A1")

            Call oDoc.ActiveSheet.AddBorder(oBorder)

            Dim oTitle As Inventor.TitleBlockDefinition
            oTitle = oDoc.TitleBlockDefinitions.Item("IP-TITLE-B")

            Dim sPromptStrings(1) As String
            sPromptStrings(0) = "N.T.S"
            sPromptStrings(1) = "01"

            Dim oSheet As Inventor.Sheet
            oSheet = oDoc.ActiveSheet

            If Not oSheet.TitleBlock Is Nothing Then
                oSheet.TitleBlock.Delete()
            End If


            Dim oTitleBlock As Inventor.TitleBlock
            oTitleBlock = oSheet.AddTitleBlock(oTitle, , sPromptStrings)
        End Sub

 Hope this will help you

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report