Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Inventor 2020.2.1 - iLogic Insert Sketched Symbol to Sheet

6 REPLIES 6
SOLVED
Reply
Message 1 of 7
MairA_DUKA
1117 Views, 6 Replies

Inventor 2020.2.1 - iLogic Insert Sketched Symbol to Sheet

Hello

I have written this code to insert a sketched symbol to the sheet, but on the red line I will riceive an error like this:

image.png

I want add the sketched symbol directly ton the sheet (not on a view).

What is wrong?

 

Sub Main()
	Try
		Break
		Dim oDoc As DrawingDocument
		oDoc = ThisDoc.Document
		
		Dim oSketchSymLib As SketchedSymbolDefinitionLibrary
		oSketchSymLib = oDoc.SketchedSymbolDefinitions.SketchedSymbolDefinitionLibraries.Item("Simboli")
		
		Dim oSSDEf As SketchedSymbolDefinition
		oSSDEf = oDoc.SketchedSymbolDefinitions.AddFromLibrary(oSketchSymLib, "Note - Codice articolo LEFT-HAND", True)
		
		'Obtain a reference to the desired sketched symbol definition.
		Dim oSketchedSymbolDef As SketchedSymbolDefinition
		oSketchedSymbolDef = oDoc.SketchedSymbolDefinitions.Item("Note - Codice articolo LEFT-HAND")
		 
		Dim oSheet As Sheet = oDoc.ActiveSheet
		 
		'Create insertion point, coordinates - in cm
		Dim oTG As TransientGeometry = ThisApplication.TransientGeometry
		Dim oInsertionPoint As Point2d = oTG.CreatePoint2d(10, 10)
		
		'Add an instance of the sketched symbol definition to the sheet.
		Dim oSketchedSymbol As SketchedSymbol
		oSketchedSymbol = oSheet.SketchedSymbols.Add(oSketchedSymbolDef, oInsertionPoint, 0, 1, Nothing)
		
	Catch ex As Exception
		MessageBox.Show(ex.Message, "Error iLogic-Rule Check_left-right-hand_part")
	End Try
End Sub

  

6 REPLIES 6
Message 2 of 7

Hi @MairA_DUKA 

 

Try this version that breaks try/catch down into smaller bites, it might tell you where the problem is.

 

I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com

 

Sub Main()
	
	Break
	Dim oDoc As DrawingDocument
	oDoc = ThisDoc.Document
	
	Dim oSketchSymLib As SketchedSymbolDefinitionLibrary
	
	Try
		
		oSketchSymLib = oDoc.SketchedSymbolDefinitions.SketchedSymbolDefinitionLibraries.Item("Simboli")
	Catch ex As Exception
		MessageBox.Show("Error getting symbol library: " & vbLf & ex.Message)
	End Try
	
	Dim oSSDEf As SketchedSymbolDefinition
	Try		
		oSSDEf = oDoc.SketchedSymbolDefinitions.AddFromLibrary(oSketchSymLib, "Note - Codice articolo LEFT-HAND", True)
	Catch ex As Exception
		MessageBox.Show("Error adding symbol from library: " & vbLf & ex.Message)
	End Try
	
		'Obtain a reference to the desired sketched symbol definition.
		Dim oSketchedSymbolDef As SketchedSymbolDefinition
	Try	
		oSketchedSymbolDef = oDoc.SketchedSymbolDefinitions.Item("Note - Codice articolo LEFT-HAND")
	Catch ex As Exception
		MessageBox.Show("Error getting symbol definition: " & vbLf & ex.Message)
	End Try	 
	
	Dim oSheet As Sheet = oDoc.ActiveSheet
	 
	'Create insertion point, coordinates - in cm
	Dim oTG As TransientGeometry = ThisApplication.TransientGeometry
	Dim oInsertionPoint As Point2d = oTG.CreatePoint2d(10, 10)
		
	Try	
		'Add an instance of the sketched symbol definition to the sheet.
		Dim oSketchedSymbol As SketchedSymbol
		oSketchedSymbol = oSheet.SketchedSymbols.Add(oSketchedSymbolDef, oInsertionPoint, 0, 1,)
		
	Catch ex As Exception
		MessageBox.Show("Error adding symbol to sheet: " & vbLf & ex.Message)
	End Try	 
End Sub

 

 

 

Message 3 of 7
rhasell
in reply to: MairA_DUKA

Hi

 

I can share my code with you.

 

@Curtis_Waguespack, Thanks for the error checking ideas.

 

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

'---0o0---
Dim oDrawDoc As Inventor.DrawingDocument = ThisApplication.ActiveDocument
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 oSheet As Sheet = oDrawDoc.ActiveSheet
		Dim oSketchedSymbolDef As SketchedSymbolDefinition = oDrawDoc.SketchedSymbolDefinitions.Item("N_NOTES-X##")
        
	'----------------------------------
		For Each actualSymbol As Inventor.SketchedSymbol In oDrawDoc.ActiveSheet.SketchedSymbols
			' If sketched symbol is found
			If (actualSymbol.Name = "N_NOTES-X##") Then
				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
2025.1.2
Please Accept as a solution / Kudos
Message 4 of 7

Hello

I have tried your code, but i receive this error:

image.png

on this line:

image.png

Message 5 of 7
MairA_DUKA
in reply to: rhasell

Now I have tried your code but I will receive also an error on the blue line:

image.png

Message 6 of 7
rhasell
in reply to: MairA_DUKA

Hi

 

Is it possible that there is a typo in the symbol name?

 

Reg
2025.1.2
Please Accept as a solution / Kudos
Message 7 of 7
MairA_DUKA
in reply to: MairA_DUKA

I have solved the Problem with this code:

 

Sub Main()
Try
Break
Dim oDoc As DrawingDocument
oDoc = ThisDoc.Document

Dim oSketchSymLib As SketchedSymbolDefinitionLibrary
oSketchSymLib = oDoc.SketchedSymbolDefinitions.SketchedSymbolDefinitionLibraries.Item("Simboli")

Dim oSSDEf As SketchedSymbolDefinition
oSSDEf = oDoc.SketchedSymbolDefinitions.AddFromLibrary(oSketchSymLib, "Note - Codice articolo LEFT-HAND", True)

'Obtain a reference to the desired sketched symbol definition.
Dim oSketchedSymbolDef As SketchedSymbolDefinition
oSketchedSymbolDef = oDoc.SketchedSymbolDefinitions.Item("Note - Codice articolo LEFT-HAND")

Dim oSheet As Sheet = oDoc.ActiveSheet

'Create insertion point, coordinates - in cm
Dim oTG As TransientGeometry = ThisApplication.TransientGeometry
Dim oInsertionPoint As Point2d = oTG.CreatePoint2d(10, 10)

'Add an instance of the sketched symbol definition to the sheet.
Dim oPromptStrings As String() = {"Test"}

Dim oSketchedSymbol As SketchedSymbol
oSketchedSymbol = oSheet.SketchedSymbols.Add(oSketchedSymbolDef, oInsertionPoint, 0, 1, oPromptStrings)

Catch ex As Exception
MessageBox.Show(ex.Message, "Error iLogic-Rule Check_left-right-hand_part")
End Try
End Sub

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report