CATScript - Copy/Paste Hybrid Bodies or Geometric Set
CATScript - Copy/Paste Hybrid Bodies or Geometric Set
(OP)
I am using the following code to copy and past a geometric set from one part to another:
This results in an empty geometric set. If I use
(instead of "paste result"), then CATIA complains "INTERNAL ERROR IN MECHANICAL MODELER".
If I manually copy/paste it works fine. What is the trick to making the CATScript behave like the manual copy/paste?
Thanks,
Jeff
CODE
sel.Add HybridBodies1.Item(i)
sel.Copy
Set documents2 = CATIA.Documents
Set partDocument2 = documents2.Add("Part")
partDocument2.Product.PartNumber = HybridBodyName(i)
Set partDocument2 = CATIA.ActiveDocument
Set specsAndGeomWindow1 = CATIA.ActiveWindow
Set part2 = partDocument2.part
sel.Add part2
sel.Paste ("CATPrtResult")
sel.Copy
Set documents2 = CATIA.Documents
Set partDocument2 = documents2.Add("Part")
partDocument2.Product.PartNumber = HybridBodyName(i)
Set partDocument2 = CATIA.ActiveDocument
Set specsAndGeomWindow1 = CATIA.ActiveWindow
Set part2 = partDocument2.part
sel.Add part2
sel.Paste ("CATPrtResult")
This results in an empty geometric set. If I use
CODE
sel.Paste
If I manually copy/paste it works fine. What is the trick to making the CATScript behave like the manual copy/paste?
Thanks,
Jeff





RE: CATScript - Copy/Paste Hybrid Bodies or Geometric Set
Dim ActDoc As Document
Set ActDoc = CATIA.ActiveDocument ' Makes the Current Document the Active one
Dim partDocument1 As Document
Set partDocument1 = CATIA.ActiveDocument
Dim selection1 As Selection
Set selection1 = partDocument1.Selection
selection1.Search "CATPrtSearch.OpenBodyFeature,all"
Set ActSel = ActDoc.Selection ' This is the Selection Object
ActSel.Copy ' Copy the Geometry
ActSel.Clear ' Clear the selection
' create part
Dim part2
Set part2 = CATIA.Documents.Add("CATPart") ' Makes a new CATPart and thusly, new actdoc
Set ActDoc = CATIA.ActiveDocument ' New ActDoc
' Retrieving HybridBodies collection in Part Document
Dim hybridBodies2 As HybridBodies
Set hybridBodies2 = part2.Part.HybridBodies
Dim GSet1 As HybridBody
Set GSet1 = hybridBodies2.Add()
Set GSet1 = part2.Part.HybridBodies.Item(1)
Set ActSel = ActDoc.Selection ' Create an object of selection for the Target document
ActSel.Add GSet1 ' Add the Set where the copied data will be pasted in the selection
ActSel.Paste ' Pastes in the new Window
End Sub
Regards
Fernando
https://picasaweb.google.com/102257836106335725208
RE: CATScript - Copy/Paste Hybrid Bodies or Geometric Set
I'm not sure I understand the technical differences between the "active selection" method and what I tried - but I incorporated your code into mine and now it works the way I expected.
Thanks again,
Jeff
RE: CATScript - Copy/Paste Hybrid Bodies or Geometric Set
I just selected all Geo Sets (by searching them with a search criteria), copy in clipboard and add them to a collection to paste in the new document.
Regards
Fernando
https://picasaweb.google.com/102257836106335725208