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:
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
Solved! Go to Solution.
Solved by MairA_DUKA. Go to Solution.
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
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
Now I have tried your code but I will receive also an error on the blue line:
Hi
Is it possible that there is a typo in the symbol name?
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.