Servus!
Ich möchte aus einem PartA in einem Produkt den MainBody kopieren und in ein vorhandenes PartB im selben Produkt einfügen.
Siehe folgenden Code:
....
Dim g_oPart As Part
Dim g_oPartDoc As Document
Dim g_oRootDoc As Document
Dim g_oPartDocZiel As Document
Sub CATMain()
' CATProduct öffnen
Set g_oRootDoc = CATIA.ActiveDocument
' Baum aktivieren
Dim oSel As Selection
Set oSel = g_oRootDoc.Selection
oSel.Clear
oSel.Add g_oRootDoc.Product
CATIA.StartCommand ("Activate terminal node")
' Product in DesignMode laden
Dim oPRD As Product
Set oPRD = g_oRootDoc.Product
oPRD.ApplyWorkMode DESIGN_MODE
' Rekursiver Durchlauf
Call IterateNode(oPRD, 1)
End Sub
'Rekursiver Durchlauf
Sub IterateNode(ioNode As Product, ByRef iNumber As Integer)
Dim Datum As Date
Datum = Date
' Prüfen CATPart oder CATProduct
Dim oNodeDoc As Document
Set oNodeDoc = ioNode.ReferenceProduct.Parent
aa = TypeName(oNodeDoc)
If (TypeName(oNodeDoc) = "PartDocument") Then
'Selektion im geladenen CATProduct ersetzen
Dim oSelPrd As Selection
Set oSelPrd = g_oRootDoc.Selection
'Part und MainBody referenzieren
Dim oPart As Part
Dim oMainBody As Body
Set oPart = oNodeDoc.Part
Set oMainBody = oPart.MainBody
' CATProduct Selektion leeren und mit zu kopierenden Mainbody befüllen
oSelPrd.Clear
oSelPrd.Add oMainBody
oSelPrd.Copy
Dim documents1 As Documents
Set documents1 = CATIA.Documents
Dim partDocument1 As PartDocument
Set partDocument1 = documents1.Item("ZielPart.CATPart")
Set g_oPartDocZiel = partDocument1
'Set g_oPartDocZiel = CATIA.Documents.Add("Part") ' )*
' Selektion im neuen Part referenzieren
Dim oSelPart As Selection
Set oSelPart = g_oPartDocZiel.Selection
oSelPart.Clear
oSelPart.Add g_oPartDocZiel.Product
' MainBody in Part einfügen
oSelPart.PasteSpecial ("CATPrtResultWithOutLink")
End If
For i = 1 To ioNode.Products.Count
Call IterateNode(ioNode.Products.Item(i), iNumber)
Next
'g_oPartDoc.Part.Update
End Sub
...
==> hier kommt dann folgende Fehlermeldung
>>Selected element(s) not allowed for this operation.<<
Erzeuge ich allerdings ein neues Part in welches ich den Mainbody kopiere funktioniert es!(geänderte Zeile im Code siehe )* )
Kann mir da jemand weiterhlefen.
Besten Dank schon mal.
Gruß AL-Fonse
Eine Antwort auf diesen Beitrag verfassen (mit Zitat/Zitat des Beitrags) IP