Insert symbol, if it is not there

Insert symbol, if it is not there

Anonymous
Not applicable
353 Views
1 Reply
Message 1 of 2

Insert symbol, if it is not there

Anonymous
Not applicable

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 )

0 Likes
Accepted solutions (1)
354 Views
1 Reply
Reply (1)
Message 2 of 2

bradeneuropeArthur
Mentor
Mentor
Accepted solution

With this...

 

' 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 sk As SketchedSymbol
For Each sk In oSheet.SketchedSymbols


If sk.Name = "MATERIAL" Then
Exit Sub
End If

Next

    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 )

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background


Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:
Drawing List!|
Toggle Drawing Sheet!|
Workplane Resize!|
Drawing View Locker!|
Multi Sheet to Mono Sheet!|
Drawing Weld Symbols!|
Drawing View Label Align!|
Open From Balloon!|
Model State Lock!
Posts and Ideas:
My Ideas|
Dimension Component!|
Partlist Export!|
Derive I-properties!|
Vault Prompts Via API!|
Vault Handbook/Manual!|
Drawing Toggle Sheets!|
Vault Defer Update!

! For administrative reasons, please mark a "Solution as solved" when the issue is solved !


 


EESignature

0 Likes