×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

CATScript - Copy/Paste Hybrid Bodies or Geometric Set

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:

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

RE: CATScript - Copy/Paste Hybrid Bodies or Geometric Set

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

https://picasaweb.google.com/102257836106335725208

RE: CATScript - Copy/Paste Hybrid Bodies or Geometric Set

(OP)
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

RE: CATScript - Copy/Paste Hybrid Bodies or Geometric Set

You are welcome, glad that you solved the problem.

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

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources