Hallo zusammen,
ich habe bereits in mehreren Foren gesucht und bin leider auf keine Lösung gekommen.
Ich versuche ein PowerCopy in ein neues CATPart hinzuzufügen in meinem vb.net Code. Der Pfad etc. sind korrekt angegeben. Ich hatte zu Beginn ohne den BeginInstatntiate() probiert, da hat er mir einen Fehler in der PutInputData gegeben. Jetzt kommt kein Fehler mehr, aber der Code erstellt keine PowerCopy, sondern macht einfach nichts
.
Dim CATIA As INFITF.Application = CType(GetObject(, "CATIA.Application"), INFITF.Application)
CATIA.Visible = True
' === Aktives Dokument als Zielpart verwenden ===
Dim partDoc As PartDocument = CType(CATIA.ActiveDocument, PartDocument)
Dim part As Part = partDoc.Part
Dim selection As Selection = partDoc.Selection
Dim bodies As Bodies = part.Bodies
Dim firstBody As Body = bodies.Item(1)
part.InWorkObject = firstBody
' === Benutzer auffordern, eine Fläche zu wählen ===
selection.Clear()
MessageBox.Show("Bitte eine Fläche im Modell auswählen. Diese wird als Referenz für das PowerCopy verwendet.")
Dim filter(0) As Object
filter(0) = "Face"
Dim status As String = Selection.SelectElement2(filter, "Bitte eine Fläche auswählen", False)
If status <> "Normal" Then
MessageBox.Show("Keine gültige Fläche ausgewählt. Vorgang abgebrochen.")
Exit Sub
End If
' === Referenz aus der Auswahl holen ===
Dim selectedFaceRef As AnyObject = selection.Item(1).Value
' === PowerCopy aus externer Datei laden ===
Dim pcPath As String = AppPath & "\START_DOCUMENTS\ENGRAVING_POWERCOPY_2.CATPart"
'Dim sourceDoc As PartDocument = CType(CATIA.Documents.Open(pcPath), PartDocument)
'Dim sourcePart As Part = sourceDoc.Part
Dim factory As InstanceFactory = part.GetCustomerFactory("InstanceFactory")
factory.EndInstanceFactory() ' Ensure factory is closed before opening it again.
factory.BeginInstanceFactory("ENGRAVING", pcPath) ' Open the factory.
factory.BeginInstantiate()
factory.PutInputData("InputSurf", selectedFaceRef)
factory.EndInstantiate()
factory.EndInstanceFactory()
part.Update()
MessageBox.Show(MainForm, "PowerCopy erfolgreich mit gewählter Fläche eingefügt!")
' Auswahl bereinigen
selection.Clear()
Ich danke euch schonmal für eure Hilfe.
Gruß
Flo
Eine Antwort auf diesen Beitrag verfassen (mit Zitat/Zitat des Beitrags) IP