iLogic to insert an image into Drawing Sketch by Sketched Symbols

by Chandra shekar Gopal,

Question:
How can I insert an image into the drawing sketch of the active sheet within a drawing document using iLogic code?

Answer:
In Autodesk Inventor, after creating a drawing sketch—whether via the user interface or API—the option to insert an image directly into the sketch is disabled (grayed out), as shown below. This means that inserting an image directly into a drawing sketch is not supported.

Grayed out image command

To work around this limitation, you can insert images into drawings by leveraging Sketched Symbols. Sketched Symbols allow you to embed images within a symbol that can then be placed on a drawing sheet.
For more details on creating Sketched Symbols, please refer to the comprehensive blog post here:

https://blog.autodesk.io/2012/08/13/creating-sketched-symbols

Sample iLogic Code to Insert an Image Using Sketched Symbols

The following iLogic code demonstrates how to insert an image into the drawing sketch of the active sheet by creating and using a Sketched Symbol:


Sub InsertSketchedSymbolWithImage()

    ' Get the active drawing document
    Dim oDwg As DrawingDocument
    Set oDwg = ThisApplication.ActiveDocument

    ' Access Transient Geometry for point creation
    Dim oTG As TransientGeometry
    Set oTG = ThisApplication.TransientGeometry

    ' Create a new Sketched Symbol definition
    Dim oSSD As SketchedSymbolDefinition
    Set oSSD = oDwg.SketchedSymbolDefinitions.Add("mySymbol")

    ' Open the sketch in edit mode
    Dim oRes As DrawingSketch
    Call oSSD.Edit(oRes)

    ' Add the image to the sketch at point (0, 4)
    Call oRes.SketchImages.Add("C:\Temp\sample.png", oTG.CreatePoint2d(0, 4))

    ' Exit edit mode and save changes
    oSSD.ExitEdit True

    ' Insert the sketched symbol onto the active sheet at point (10, 10)
    Call oDwg.ActiveSheet.SketchedSymbols.Add("mySymbol", oTG.CreatePoint2d(10, 10))

End Sub

By following this approach, you can effectively embed images into your drawing documents using iLogic, overcoming the limitation of direct image insertion into drawing sketches.

If you have any questions or need further assistance, feel free to leave a comment or reach out.


Comments

Leave a Reply

Discover more from Autodesk Developer Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading