Hi sco.smith,
I had exactly that on hand, but it was doing a lot of other things specific to my needs. Here is a stripped down version that you can give a try. Just change the template pointer and the list of symbols as needed.
I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com
Sub Main
'define this document
oDrawDoc = ThisDoc.Document
'define template file
oTemplateFile = "\\server\departments\CAD\Inventor\Templates\Standard.idw"
'capture the current active sheet
Dim oCurrentNumber As Sheet
oCurrentNumber = oDrawDoc.ActiveSheet
'get symbol names
Call SymbolNames()
'get/place symbols
Call PlaceSymbols()
'activate the original current sheet
oCurrentNumber.activate
End Sub
'[ Declare variables passed between subs
'Define the drawing document
Dim oDrawDoc As DrawingDocument
'Define the symbols to look for
Dim sSymbol_01 As String
'create the sketched symbol definition
Dim oSymDef_01 As SketchedSymbolDefinition
'define array list
Dim oSymbolList As New ArrayList
'identify the source template file that contains the symbol definitions
Dim oTemplateFile As String
']
Sub SymbolNames()
'add the symbols to work with to the array list
'and setup standard insert coordinates for each symbol. Note: coordinates are in cm
'assumes a symbol of this name is present in the template
'uses vertical bar as seperator
'uses underscore as seperator X_Y seperator
oSymbolList.add("Standard Notes" & "|" & "3_2")
oSymbolList.add("Approval Stamp" & "|" & "6_2")
oSymbolList.add("CallOut" & "|" & "Null") 'this symbol has no standard insert coordinates
oSymbolList.add("MECHANICAL NOTES" & "|" & "1.5_2.6")
End Sub
Sub PlaceSymbols()
'open the template
Dim strSourceIDW As DrawingDocument
strSourceIDW = ThisApplication.Documents.Open(oTemplateFile, False)
'For Each oItem in oSymbolList
For oItem = 0 To oSymbolList.Count - 1
'split the arraylist value into words using the vertical bar character
Dim words As String() = oSymbolList.Item(oItem).Split(New Char() {"|"c})
'result:
'words(0) = symbol name
'words(1) = insert coordinates
'get the symbol definition from the template
Dim oTemplateSymbol As SketchedSymbolDefinition
Try
oTemplateSymbol = strSourceIDW.SketchedSymbolDefinitions.Item(Trim(words(0)))
Catch
'MessageBox.Show(words(0) & " not found in ", "iLogic")
MessageBox.Show(words(0) & " not found in tempate file.", "iLogic")
Goto NotFound_Exception
End Try
'check for existing symbol definition (just in case)
'if not found, create new symbol definition
'and place the definition In the drawing resources folder
Dim oNewSymbol As SketchedSymbolDefinition
Dim oSymDefs As SketchedSymbolDefinitions = oDrawDoc.SketchedSymbolDefinitions
For Each SketchedSymbolDefinition In oSymDefs
If oSymDefs.Item(Trim(words(0))).Name = Trim(words(0)) Then
'set flag
oSymbolExists = True
End If
Next
If oSymbolExists = True Then
'resue
oNewSymbol = oDrawDoc.SketchedSymbolDefinitions.Item(Trim(words(0)))
Else
'copy and create new
oNewSymbol = oTemplateSymbol.CopyTo(oDrawDoc)
End If
'create insertion point
Dim oTG As TransientGeometry = ThisApplication.TransientGeometry
Dim oInsertionPoint As Point2d
'add the symbols to each sheet
For Each oSheet In oDrawDoc.Sheets
oSheet.Activate
'check for null insert point
'place symbol if insert point is not null
If Trim(words(1)) <> "Null" Then
'split string using underscore
Dim oXY As String() = Trim(words(1)).Split(New Char() {"_"c})
'convert strings to Double
oX = CDblAny(oXY(0)) 'X coordinate
oY = CDblAny(oXY(1)) 'Y coordinate
'insert symbols (assumes symbol has no prompted entry)
oInsertionPoint = oTG.CreatePoint2d(oX,oY)
'SketchedSymbols.Add(SymbolDefinition, InsertPoint,Rotation,Scale,PromptStrings)
oSymbol = oSheet.SketchedSymbols.Add(oNewSymbol,oInsertionPoint,0,1,Nothing)
End If
Next 'next sheet
NotFound_Exception:
Next 'next symbol
'close the template/source file
strSourceIDW.Close()
End Sub
