Title Block Definition Create and Insert API Sample doesn't work as iLogic

Title Block Definition Create and Insert API Sample doesn't work as iLogic

AlexFielder
Advisor Advisor
1,545 Views
1 Reply
Message 1 of 2

Title Block Definition Create and Insert API Sample doesn't work as iLogic

AlexFielder
Advisor
Advisor

Hi Folks,

 

I've found and solved a problem with the above API sample in the Inventor 2013 API Help and thought it worth sharing:

 

Sub Main()
	CreateTitleBlockDefinition()
	InsertTitleBlockOnSheet()
End Sub

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

    ' Create the new title block defintion.
    Dim oTitleBlockDef As TitleBlockDefinition
    oTitleBlockDef = oDrawDoc.TitleBlockDefinitions.Add("Sample Title Block")

    ' Open the title block definition's sketch for edit.  This is done by calling the Edit
    ' method of the TitleBlockDefinition to obtain a DrawingSketch.  This actually creates
    ' a copy of the title block definition's and opens it for edit.
    Dim oSketch As DrawingSketch
    Call oTitleBlockDef.Edit(oSketch)

    Dim oTG As TransientGeometry
    oTG = ThisApplication.TransientGeometry

    ' Use the functionality of the sketch to add title block graphics.
    Call oSketch.SketchLines.AddAsTwoPointRectangle(oTG.CreatePoint2d(0, 0), oTG.CreatePoint2d(9, 3))
    Call oSketch.SketchLines.AddByTwoPoints(oTG.CreatePoint2d(0, 1.5), oTG.CreatePoint2d(9, 1.5))
    Call oSketch.SketchLines.AddByTwoPoints(oTG.CreatePoint2d(0, 2.25), oTG.CreatePoint2d(9, 2.25))
    Call oSketch.SketchLines.AddByTwoPoints(oTG.CreatePoint2d(4.5, 1.5), oTG.CreatePoint2d(4.5, 2.25))
    Call oSketch.SketchLines.AddByTwoPoints(oTG.CreatePoint2d(3, 2.25), oTG.CreatePoint2d(3, 3))
    Call oSketch.SketchLines.AddByTwoPoints(oTG.CreatePoint2d(6, 2.25), oTG.CreatePoint2d(6, 3))

    ' Add some static text to the title block.
    Dim sText As String
    sText = "TITLE BLOCK"
    Dim oTextBox As Inventor.TextBox
    oTextBox = oSketch.TextBoxes.AddFitted(oTG.CreatePoint2d(4.5, 0.75), sText)
    oTextBox.VerticalJustification = VerticalTextAlignmentEnum.kAlignTextMiddle
     oTextBox.HorizontalJustification = HorizontalTextAlignmentEnum.kAlignTextCenter

    sText = "Static Text"
    oTextBox = oSketch.TextBoxes.AddByRectangle(oTG.CreatePoint2d(0, 1.5), oTG.CreatePoint2d(4.5, 2.25), sText)
    oTextBox.VerticalJustification = VerticalTextAlignmentEnum.kAlignTextMiddle
     oTextBox.HorizontalJustification = HorizontalTextAlignmentEnum.kAlignTextCenter
	
	MessageBox.Show("Before PE", "Title")

    ' Add some prompted text fields.
    sText = "<Prompt>Enter text 1</Prompt>"
    oTextBox = oSketch.TextBoxes.AddByRectangle(oTG.CreatePoint2d(4.5, 1.5), oTG.CreatePoint2d(9, 2.25), sText)
    oTextBox.VerticalJustification = VerticalTextAlignmentEnum.kAlignTextMiddle
     oTextBox.HorizontalJustification = HorizontalTextAlignmentEnum.kAlignTextCenter

	MessageBox.Show("After PE 1", "Title")

    sText = "<Prompt>Enter text 2</Prompt>"
    oTextBox = oSketch.TextBoxes.AddByRectangle(oTG.CreatePoint2d(0, 2.25), oTG.CreatePoint2d(3, 3), sText)
    oTextBox.VerticalJustification = VerticalTextAlignmentEnum.kAlignTextMiddle
     oTextBox.HorizontalJustification = HorizontalTextAlignmentEnum.kAlignTextCenter

	MessageBox.Show("After PE 2", "Title")
	
    ' Add some property text.
    ' Add the property value of Author from the drawing
    sText = "<Property Document='drawing' FormatID='{F29F85E0-4FF9-1068-AB91-08002B27B3D9}' PropertyID='4' />"
    oTextBox = oSketch.TextBoxes.AddByRectangle(oTG.CreatePoint2d(3, 2.25), oTG.CreatePoint2d(6, 3), sText)
    oTextBox.VerticalJustification = VerticalTextAlignmentEnum.kAlignTextMiddle
    oTextBox.HorizontalJustification = HorizontalTextAlignmentEnum.kAlignTextCenter

    ' Add the property value of Subject from the drawing
    sText = "<Property Document='drawing' FormatID='{F29F85E0-4FF9-1068-AB91-08002B27B3D9}' PropertyID='3' />"
    oTextBox = oSketch.TextBoxes.AddByRectangle(oTG.CreatePoint2d(6, 2.25), oTG.CreatePoint2d(9, 3), sText)
    oTextBox.VerticalJustification = VerticalTextAlignmentEnum.kAlignTextMiddle
     oTextBox.HorizontalJustification = HorizontalTextAlignmentEnum.kAlignTextCenter

    Call oTitleBlockDef.ExitEdit(True)
End Sub

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

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

    Dim oSheet As Sheet
    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(0 To 1) As String
    sPromptStrings(0) = "String 1"
     sPromptStrings(1) = "String 2"

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

 The code works fine as VBA- but when you copy it to iLogic as I have above, the lines in bold failed because the API sample misses off the VerticalTextAlignmentEnum and HorizontalTextAlignmentEnum required by iLogic to make this work. I also had to modify the array sPromptStrings to be Dim sPromptStrings(0 To 1) As String instead of the supplied Dim sPromptStrings(1 To 2) As String - that and removing all the "Set" entries. 🙂

 

I do have a question though:

 

What does the FormatID of the Property text do? and with my post from yesterday in mind is there a way to capture that information from an existing titleblock using iLogic?

0 Likes
1,546 Views
1 Reply
Reply (1)
Message 2 of 2

augusto.goncalves
Alumni
Alumni

Hi,

 

From the Inventor API help file: The FormatID attribute specifies which property set the property is within. This is specified as a GUID in string form. The "Document Properties" topic in the API Overview discusses how to obtain the format ID’s for specific property sets.

 

So you may also want to look at the list GUIDs at the documentation.

 

Regards,



Augusto Goncalves
Twitter @augustomaia
Autodesk Developer Network
0 Likes