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!

Copy from a search and paste on first selection

Status
Not open for further replies.

Olivia86

Automotive
Sep 23, 2016
29
IT
I have a first selected item.

Then i perform a search-select-copy in the whole document, i copy, and i would like to paste in the first selection, but i cant find the metod
to recall the first selection.


Sub CATMain()

Dim objSel As Selection
Dim objSel2 As Selection

Set objSel2 =CATIA.ActiveDocument.Selection
Set objSel =CATIA.ActiveDocument.Selection

objSel.Search "name=*ITEMTOCOPY*,all"
objSel.Copy

End Sub


I NEED TO PASTE THE objSel in the objSel2
Sorry for the noob question :) !

 
Replies continue below

Recommended for you

dim myfirstselectionobject
set myfirstselectionobject = catia.activedocument.selection.item(1).value

dim objsel as selection
[..]
objsel.copy

objsel.clear
objsel.add myfirstselectionobject
objsel.paste

Eric N.
indocti discant et ament meminisse periti
 
Great, this code is indeed working. Though i have a small issue.

Sub CATMain()


Dim objSel2 As Selection
Dim myfirstselectionobject
set myfirstselectionobject = CATIA.ActiveDocument.Selection.Item(1).Value

Dim objSel as Selection

Set objSel =CATIA.ActiveDocument.Selection

objSel.Search "name=Pal_DX,all"
objSel.copy

objSel.clear
objSel.add myfirstselectionobject
objSel.paste



End Sub


If i play this the first time, this is working without any problem. The second and thirtd etc.. the Pal_DX is copied multiple times.
What i should tell the program is to copy or paste just the first result of the selection. I think the item(1) pointer should be added somewhere.
 
well if you have one Pal_DX before first run, you have TWO after first run , FOUR after second run...remember COPY paste

unless you rename the elements after paste them...


Eric N.
indocti discant et ament meminisse periti
 
Is it not possible to tell the search command to take only the first item on the search array? The first copied-pasted item is in the Detail sheet, maybe this is helpful?
But i think is easyer the first metod. I think is the Item2 command i am searching for. Though i cant understand it's using.
 
Here we go... is here any improvement i can make to the code?

Sub CATMain()


Dim objSel2 As Selection
Dim myfirstselectionobject
set myfirstselectionobject = CATIA.ActiveDocument.Selection.Item(1).Value

Dim objSel as Selection

Set objSel =CATIA.ActiveDocument.Selection

objSel.Search "name=Pal_DX,all"
set objSel2 = CATIA.ActiveDocument.Selection.Item(1).Value
objSel.clear
objSel.add objSel2


objSel.copy

objSel.clear
objSel.add myfirstselectionobject
objSel.paste



End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top