Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.
Anonymous
324 Views, 1 Reply

Insert symbol, if it is not there

I need a way to check if a symbol is already in a drawing before running this following code that inserts a symbol

SyntaxEditor Code Snippet

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

    ' Obtain a reference to the desired sketched symbol definition.
    Dim oSketchedSymbolDef As SketchedSymbolDefinition = oDrawDoc.SketchedSymbolDefinitions.Item("MATERIAL")

    Dim oSheet As Sheet = oDrawDoc.ActiveSheet

    ' This sketched symbol definition contains one prompted string input. An array
    ' must be input that contains the strings for the prompted strings.
    Dim oPromptStrings As String() = {iProperties.Value("Project", "STOCK NUMBER"),""}
    


    Dim oBorder As Border
    oBorder = oSheet.Border
    Dim oPlacePoint As Point2d
    oyOffset = 7 'user defined offset
    oxOffset = 9
    oX = oBorder.RangeBox.MaxPoint.X - oxOffset
    oY = oBorder.RangeBox.MinPoint.Y + oyOffset
    oPlacePoint = ThisApplication.TransientGeometry.CreatePoint2d(oX,oY)
    ' Add an instance of the sketched symbol definition to the sheet.
    ' Rotate the instance by 45 degrees and scale by .75 when adding.
    ' The symbol will be inserted at (0,0) on the sheet. Since the
    ' start point of the line was marked as the insertion point, the
    ' start point should end up at (0,0).
    Dim oSketchedSymbol As SketchedSymbol = oSheet.SketchedSymbols.Add(oSketchedSymbolDef, oPlacePoint, (0), 1,oPromptStrings )