Insert OLE in titleblock

Insert OLE in titleblock

Anonymous
Not applicable
368 Views
1 Reply
Message 1 of 2

Insert OLE in titleblock

Anonymous
Not applicable

I would like to insert ole object (image) in titleblock

0 Likes
369 Views
1 Reply
Reply (1)
Message 2 of 2

ekinsb
Alumni
Alumni

I've taken the sample from the API help that demonstrates creating a new title block and added a line at the bottom that inserts and image.  You have a choice of linking or embedding the image (the third argument in the Add method) .  If you link it, you'll need to make sure the image is somewhere in the project so Inventor can find it.

 

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

    ' Create the new title block defintion.
    Dim oTitleBlockDef As TitleBlockDefinition
    Set 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
    Set 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 TextBox
    Set oTextBox = oSketch.TextBoxes.AddFitted(oTG.CreatePoint2d(4.5, 0.75), sText)
    oTextBox.VerticalJustification = kAlignTextMiddle
    oTextBox.HorizontalJustification = kAlignTextCenter

    sText = "Static Text"
    Set oTextBox = oSketch.TextBoxes.AddByRectangle(oTG.CreatePoint2d(0, 1.5), oTG.CreatePoint2d(4.5, 2.25), sText)
    oTextBox.VerticalJustification = kAlignTextMiddle
    oTextBox.HorizontalJustification = kAlignTextCenter

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

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

    ' 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' />"
    Set oTextBox = oSketch.TextBoxes.AddByRectangle(oTG.CreatePoint2d(3, 2.25), oTG.CreatePoint2d(6, 3), sText)
    oTextBox.VerticalJustification = kAlignTextMiddle
    oTextBox.HorizontalJustification = kAlignTextCenter

    ' Add the property value of Subject from the drawing
    sText = "<Property Document='drawing' FormatID='{F29F85E0-4FF9-1068-AB91-08002B27B3D9}' PropertyID='3' />"
    Set oTextBox = oSketch.TextBoxes.AddByRectangle(oTG.CreatePoint2d(6, 2.25), oTG.CreatePoint2d(9, 3), sText)
    oTextBox.VerticalJustification = kAlignTextMiddle
    oTextBox.HorizontalJustification = kAlignTextCenter
    
    ' Add an image.
    Call oSketch.SketchImages.Add("C:\Temp\Img.png", oTG.CreatePoint2d(0.25, 1), False)

    Call oTitleBlockDef.ExitEdit(True)
End Sub

 


Brian Ekins
Inventor and Fusion 360 API Expert
Mod the Machine blog
0 Likes