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: 

copy and paste symbols in one idw to another idw

4 REPLIES 4
SOLVED
Reply
Message 1 of 5
linuskotte
1770 Views, 4 Replies

copy and paste symbols in one idw to another idw

Hi all

I have one big problem copy and paste symbols in one idw to another idw it takes to much time.

it's possible through macro or ilogic for copying symbols in drawings?

 

please help me?

 

 

Thanks and regards,

LINUS KOTTE

4 REPLIES 4
Message 2 of 5
jdkriek
in reply to: linuskotte

 

This will copy all the symbols from a defined drawing into the active drawing:

 

Public Sub CopySymbols()
'JDK 2013
    Dim oApp As Inventor.Application
    Set oApp = ThisApplication
    Dim thisIDW As DrawingDocument
    Set thisIDW = oApp.ActiveDocument
    
    'Define source path of Symbol Drawing
    Dim pathIDW As String
    pathIDW = "J:\\Templates\Symbols.idw"
    
    Dim sourceIDW As DrawingDocument
    Set sourceIDW = oApp.Documents.Open(pathIDW, False)
    
    Dim symbolDef As SketchedSymbolDefinition
    
    'Copy all the symbols into active drawing
    For Each symbolDef In sourceIDW.SketchedSymbolDefinitions
        Call symbolDef.CopyTo(thisIDW, ReplaceExisting:=True)
    Next
End Sub
Jonathan D. Kriek
MFG Solutions Engineer
KETIV Technologies, Inc.


Message 3 of 5
gary.belisle
in reply to: jdkriek

Here is a similar one that uses a form to select the symbols you want from the source drawing.

 

Public Sub SymbolCopy()

        ' These must already be declared
        '    Dim _invApp As Inventor.Application
        '    Public Shared inventorDoc As Inventor.Document

        ' SymbolName is the Name of the Symbol to be copied 
        ' oSourceDwg is the document that the symbol currently resides in. 
        ' oTargetDwg is the document that the symbol is to be placed into.
        ' Symbols is the name of the Form. The form has an "Insert" and "Cancel", a listbox, and a checkbox.
        ' ListBox_Resource is a list box on Symbols Form. Set up list box to select multiple items.
        ' ReplaceExisting is a checkbox on Symbols Form "Replace existing symbol"

        ' Check to make sure active inventor document is a drawing.
        If Not inventorDoc.DocumentType = DocumentTypeEnum.kDrawingDocumentObject Then

            MessageBox.Show("This is not a drawing document...", "Error...", MessageBoxButtons.OK, MessageBoxIcon.Warning)

            Exit Sub

        End If

        ' Set a reference to the drawing document. 
        Dim oTargetDwg As DrawingDocument
        oTargetDwg = inventorDoc

        ' Open the source drawing document. This could be converted to a OpenFileDialog.
        Dim SourceFile As String = "C:\Vault Workspace\CAD Administration\Templates 2013\Symbols\Symbols.dwg"

        ' Check to see if the file exists.
        If Not System.IO.File.Exists(SourceFile) Then

            MessageBox.Show("Download Symbols.dwg from Vault...", "Missing File", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)

            Exit Sub

        End If

        ' Set a reference to the source document.
        Dim oSourceDwg As DrawingDocument
        oSourceDwg = _invApp.Documents.Open(SourceFile, False)

        ' Create the new sketched symbol definition.
        Dim oSketchedSymbolDef As SketchedSymbolDefinition

        ' Clear items on form listbox named "ListBox_Resource"
        Symbols.ListBox_Resource.Items.Clear()


        ' Add symbol names from source drawing to the list box
        Dim j As Integer
        For j = 1 To oSourceDwg.SketchedSymbolDefinitions.Count

            Dim s As String = oSourceDwg.SketchedSymbolDefinitions.Item(j).Name
            Symbols.ListBox_Resource.Items.Add(s)

        Next

        ' Sort the symbols list box
        Symbols.ListBox_Resource.Sorted = True

        ' capture Symbols Dialog results.
        Dim results As DialogResult = Symbols.ShowDialog()

        ' Exit sub if dialog is canceled
        If results = Windows.Forms.DialogResult.Cancel Then

            ' Close the source drawing
            oSourceDwg.Close(True)
            oSourceDwg = Nothing

            Exit Sub

        End If

        ' Define list of symbols to be added to the drawing based on user selection in the list box
        Dim SymbolNames As List(Of String) = New List(Of String)()
        For n As Integer = 0 To Symbols.ListBox_Resource.SelectedItems.Count - 1
            SymbolNames.Add(Symbols.ListBox_Resource.SelectedItems.Item(n))
        Next

        ' Error check
        If Not SymbolNames.Count > 0 Then

            MessageBox.Show("No symbols selected...", "Error...", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)

            ' Close the source drawing
            oSourceDwg.Close(True)
            oSourceDwg = Nothing

            Exit Sub

        End If

        ' Sets to True or False for the ".CopyTo" which will replace an existing symbol if True
        Dim ReplaceExisting As Boolean = Symbols.CheckBox_ReplaceSymbol.Checked

        ' Add sketched symbols to the target drawing
        Dim i As Integer
        For Each SymbolName As String In SymbolNames
            For i = 1 To oSourceDwg.SketchedSymbolDefinitions.Count
                If oSourceDwg.SketchedSymbolDefinitions.Item(i).Name = (SymbolName) Then
                    oSketchedSymbolDef = oSourceDwg.SketchedSymbolDefinitions.Item(i).CopyTo(oTargetDwg, ReplaceExisting)
                End If
            Next
        Next

        ' Close the source drawing
        oSourceDwg.Close(True)
        oSourceDwg = Nothing

        ' Invoke the drawing symbols command in inventor drawing
        _invApp.CommandManager.ControlDefinitions("DrawingSymbolsCmd").Execute()

    End Sub

 

---------------------------------------------------------------------
i7-4800MQ Dell Precision M6800, Win 7 Enterprise 64-bit, 16GB RAM
Autodesk Product Design Suite Ultimate 2015
Autodesk Vault Professional 2015
PLM 360
Message 4 of 5
akosi
in reply to: gary.belisle

hi

do you have a vba version of this.

 

it would be very helpful...Smiley Happy

 

Message 5 of 5
gary.belisle
in reply to: akosi

Sorry, I do not have a VBA version.
---------------------------------------------------------------------
i7-4800MQ Dell Precision M6800, Win 7 Enterprise 64-bit, 16GB RAM
Autodesk Product Design Suite Ultimate 2015
Autodesk Vault Professional 2015
PLM 360

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

Post to forums  

Autodesk Design & Make Report