kevin.rahhal
New member
Hello,
I am writting a macro to be able to copy/paste and breaklink products between 2 different windows. I am able to do it manually so I know it's possible.
I've also written a macro that does it but limited to same window for paste.
I'm wondering what I would have to change with my code to be able to paste to another window.
Any help is appreciated.
Here is what I have :
"Dim selection1 As Object, selStatus, InputObject(0) ' Objects used for selection
InputObject(0) = "Product" ' Only allow products to be selected
Set selection1 = CATIA.ActiveDocument.Selection ' Object used to handle selections
selStatus = selection1.SelectElement3(InputObject, "Select items to copy", True, CATMultiSelTriggWhenUserValidatesSelection, True)
If (selStatus <> "Normal") Then
MsgBox ("Selection cancelled of items to copy. Macro exiting") ' Inform user macro has been cancelled.
Exit Sub
End If
Dim arraySelectedElements() As SelectedElement
ReDim arraySelectedElements(selection1.Count2)
Dim arrayElementCount
For arrayElementCount = 1 To UBound(arraySelectedElements)
Set arraySelectedElements(arrayElementCount - 1) = selection1.Item2(arrayElementCount)
Next
selection1.Clear
selStatus = selection1.SelectElement2(InputObject, "Select where you want to paste the items", False)
If (selStatus <> "Normal") Then
MsgBox ("Selection of location to paste products cancelled. Macro exiting") ' Inform user macro has been cancelled.
Exit Sub
End If
Dim pasteSelectedElement As SelectedElement
Set pasteSelectedElement = selection1.Item2(1)
selection1.Clear
For arrayElementCount = 1 To UBound(arraySelectedElements)
selection1.Add arraySelectedElements(arrayElementCount - 1).LeafProduct
Next
selection1.Copy 'Copies current selected items
selection1.Clear ' Clears the selection of items, so the new product can be selected
selection1.Add pasteSelectedElement.LeafProduct
selection1.PasteSpecial ("CATSpecBreakLink") ' Paste & break link on root product"
When I execute this macro, it will always paste within the same window even if I select a different one
I am writting a macro to be able to copy/paste and breaklink products between 2 different windows. I am able to do it manually so I know it's possible.
I've also written a macro that does it but limited to same window for paste.
I'm wondering what I would have to change with my code to be able to paste to another window.
Any help is appreciated.
Here is what I have :
"Dim selection1 As Object, selStatus, InputObject(0) ' Objects used for selection
InputObject(0) = "Product" ' Only allow products to be selected
Set selection1 = CATIA.ActiveDocument.Selection ' Object used to handle selections
selStatus = selection1.SelectElement3(InputObject, "Select items to copy", True, CATMultiSelTriggWhenUserValidatesSelection, True)
If (selStatus <> "Normal") Then
MsgBox ("Selection cancelled of items to copy. Macro exiting") ' Inform user macro has been cancelled.
Exit Sub
End If
Dim arraySelectedElements() As SelectedElement
ReDim arraySelectedElements(selection1.Count2)
Dim arrayElementCount
For arrayElementCount = 1 To UBound(arraySelectedElements)
Set arraySelectedElements(arrayElementCount - 1) = selection1.Item2(arrayElementCount)
Next
selection1.Clear
selStatus = selection1.SelectElement2(InputObject, "Select where you want to paste the items", False)
If (selStatus <> "Normal") Then
MsgBox ("Selection of location to paste products cancelled. Macro exiting") ' Inform user macro has been cancelled.
Exit Sub
End If
Dim pasteSelectedElement As SelectedElement
Set pasteSelectedElement = selection1.Item2(1)
selection1.Clear
For arrayElementCount = 1 To UBound(arraySelectedElements)
selection1.Add arraySelectedElements(arrayElementCount - 1).LeafProduct
Next
selection1.Copy 'Copies current selected items
selection1.Clear ' Clears the selection of items, so the new product can be selected
selection1.Add pasteSelectedElement.LeafProduct
selection1.PasteSpecial ("CATSpecBreakLink") ' Paste & break link on root product"
When I execute this macro, it will always paste within the same window even if I select a different one