Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations waross on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

CATScript - Copy/Paste Hybrid Bodies or Geometric Set 1

Status
Not open for further replies.

jmarkus

Mechanical
Jul 11, 2001
377
I am using the following code to copy and past a geometric set from one part to another:

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")

This results in an empty geometric set. If I use
Code:
sel.Paste
(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
 
Replies continue below

Recommended for you

Sub CATMain()

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

 
Thanks Fernando,

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
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor