[VBA] Can I use multiple Selection objects independently?

Ivelin Peychev

[VBA] Can I use multiple Selection objects independently?

Is it possible to have two independent Selection objects that you can for example:

Sel1.Clear

Sel1.Add SomeLine

Sel2.Clear

Sel2.Add Sel1.Item(1).Value

Sel2.Copy

Sel1.Clear

Sel1.Add Some3DShape

Sel1.PasteSpecial "CATPrtResult"

 

And now we should have copy of the line inside the 3dshape, but no...

After Sel2.Clear Sel1 is cleared as well.

 

How could this kind of procedure be implemented?

 

Thanks in advance.

 UPDATE:

Real use case is as follows:

using sel1.Search to find a bunch of lines spread across multiple 3dshapes

I want to copy all these lines into a different 3dshape->geometrical set.

 

Trying Copy on all objects and sel1.Paste results in error.

So alternatively I need to do with loop and copy/paste one object at a time.

However for that I need another selection object and be able to clear it between each object.

That fails because the original selection object is also cleared.


Best Regards,

Ivelin PEYCHEV


 

Edited By:
Ivelin Peychev[AITAC d.o.o.] @ Dec 14, 2022 - 02:28 PM (Europe/Paris)

Josh Bender

RE: [VBA] Can I use multiple Selection objects independently?
(in response to Ivelin Peychev)

The simple answer is no - you can't have two independent selection objects within a file. The selection object does exactly what your mouse does (in regards to selecting).

 

There are a few different ways to copy and paste each item one at a time -

But I am confused about your statement in the update that using sel1.paste doesn't work. Can you select those objects with the mouse, copy, and then paste without error? What type of error do you get?

Ivelin Peychev

RE: [VBA] Can I use multiple Selection objects independently?
(in response to Josh Bender)

Thanks for the reply Josh,

 

Fully interactively I would do this:

- Make the target 3dshape active (double click)

- Ctrl+F find all the lines

- While all lines are selected run command c:join, remove all checks and click ok.

Result is a join is created and all lines are added as external references.

 

with VBA, you use selection.Search find all objects, identify the target 3dshape and the geometrical set.

do selection.Copy, selection.Clear, and selection.Add 3dshape (Part) object

selection.PasteSpecial "CATPrtResult"

that leads to error message:

"Error Copying Data: Paste is forbidden: Selected elements must be in the same 3D Shape."

Trying to create Join (HybridShapeAssemble) also fails

 


Best Regards,

Ivelin PEYCHEV


Josh Bender

RE: [VBA] Can I use multiple Selection objects independently?
(in response to Ivelin Peychev)

To make sure we're on the same page, which version of CATIA are you using?

 

And if I understand correctly you are performing this operation within an assembly and not within a part?

Ivelin Peychev

RE: [VBA] Can I use multiple Selection objects independently?
(in response to Josh Bender)

3DExperience R2023x

 Yes, it's done on assembly level containing multiple physical products, 3d parts and 3dshapes.


Best Regards,

Ivelin PEYCHEV


Josh Bender

RE: [VBA] Can I use multiple Selection objects independently?
(in response to Ivelin Peychev)

Ah. I only have experience with V5 in this. Sorry.

As far as V5 goes, the selection object doesn't allow copy-paste between different parts within the product level using the product level selection object. I haven't dug through that as I found it easier to copy between part files themselves.

For example:

part1.activate

set sel1 = part1.selection

Sel1.add items

Sel1.copy

Part2.activate

set Sel2 = part2.selection

sel2.add (location where objects are to go)

sel2.paste