Sketch Symbol Insertion

Sketch Symbol Insertion

zikmund
Contributor Contributor
506 Views
3 Replies
Message 1 of 4

Sketch Symbol Insertion

zikmund
Contributor
Contributor

Can someone please help me?

 

I'm trying to put simple sketch symbol from drawing resources into the drawing on exact coordinates by iLogic. I've tried a lot of codes I've found on these forums, but nothing worked and I hade the same mistake on the line with insertion of the symbol.

What am I doing wrong?

Dim oDrawDoc As DrawingDocument = ThisApplication.ActiveDocument
Dim oSheet As Sheet = oDrawDoc.ActiveSheet

'create insertion point
Dim oPosition As Point2d = ThisApplication.TransientGeometry.CreatePoint2d(10, 15)

'define symbol Definition to use
Dim oSymDef As SketchedSymbolDefinition
oSymDef = oDrawDoc.SketchedSymbolDefinitions.Item("SYMBOL")
    
'insert the new symbol
Dim oSymbol As SketchedSymbol
oSymbol = oDrawDoc.ActiveSheet.SketchedSymbols.Add(oSymDef, oPosition, 0, 1, )

Thanks a lot for you help.

Milan

0 Likes
507 Views
3 Replies
Replies (3)
Message 2 of 4

bradeneuropeArthur
Mentor
Mentor

For me the code works perfect.

Did you notice the following;

the coordinates are in cm (10,15)

You need to define also in the Sketched Symbol the Insertion point correctly.

 

 

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
Message 3 of 4

FINET_Laurent
Advisor
Advisor

Hi @zikmund ,

 

I also tried those lines and they work as intended. The only issue I can see is regarding the name of the sketch symbol.

Does the symbol exists localy on the sheet, in this directory ? : 

laurentfinetAF8M9_0-1686664203528.png

 

What about the name ? The symbol name has to match exactly with the line of code : 

oSymDef = oDrawDoc.SketchedSymbolDefinitions.Item("Pin")

 Make sure there is no tabulation or space in the symbol name (localy on the drawing)

 

Regards,

 

FINET L. 

If this post solved your question, please kindly mark it as "Solution"

If this post helped out in any way to solve your question, please drop a "Like"

@LinkedIn     @JohnCockerill

0 Likes
Message 4 of 4

rhasell
Advisor
Advisor

Hi

Your code works as is, however, if the symbol does not exist, the code will fail

Below is a copy of my code, a little more long winded than yours, but you may be able to pull some data from it and use it in yours. (I built mine from Help and snippets)

 

1: Get the symbol from your library

2: Do a duplicate check

3: Make the symbol static

'Author Reg Hasell
'05.07.19
'
'Get the Note refence Symbol from the library
'Insert it into the drawing
'A duplicate check done, for both Resources and Drawing

'------
Dim oDrawDoc As Inventor.DrawingDocument = ThisDoc.Document
Dim SourceFile As String = "d:\Data\TEMPLATES\SYMBOLS\Drawing Symbols.idw"
            strSourceIDW = ThisApplication.Documents.Open(SourceFile, False)
            Dim symbolDef As SketchedSymbolDefinition
            For Each symbolDef In strSourceIDW.SketchedSymbolDefinitions
				If (StrComp(symbolDef.Name, "N_NOTES-X##", vbTextCompare) = 0) Then
                    CopyFrom = symbolDef.CopyTo(oDrawDoc, True)
                End If
            Next
            strSourceIDW.Close()

'Insert The Symbol
'Dim strDrawDoc As DrawingDocument = ThisDrawing.Document
        Dim oSheet As Sheet = oDrawDoc.ActiveSheet
		'Dim strSketchedSymbolDef As SketchedSymbolDefinition = strDrawDoc.SketchedSymbolDefinitions.Item(SymbName)
		Dim oSketchedSymbolDef As SketchedSymbolDefinition = oDrawDoc.SketchedSymbolDefinitions.Item("N_NOTES-X##")
        
	'----------------------------------
	'If (doc.ActiveSheet.SketchedSymbols IsNot Nothing AndAlso doc.ActiveSheet.SketchedSymbols.Count > 0) Then
		' Iterate through all sketched symbols in active sheet
		For Each actualSymbol As Inventor.SketchedSymbol In oDrawDoc.ActiveSheet.SketchedSymbols
			' If sketched symbol is found
			If (actualSymbol.Name = "N_NOTES-X##") Then
'				MessageBox.Show("Message", "Title")
				Return
			End If

			Next
'--------------
		Dim oTransGeom = ThisApplication.TransientGeometry
        Dim oInsertionPoint As Point2d = oTransGeom.CreatePoint2d(72.1, 57.4)
		Dim oSketchedSymbol As SketchedSymbol= oSheet.SketchedSymbols.Add(oSketchedSymbolDef, oInsertionPoint, 0, 1, Nothing)
oSketchedSymbol.Static = True
'Done

 

 

Reg
2026.1
0 Likes