×
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

Copy from a search and paste on first selection

Copy from a search and paste on first selection

Copy from a search and paste on first selection

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

RE: Copy from a search and paste on first selection

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

RE: Copy from a search and paste on first selection

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

RE: Copy from a search and paste on first selection

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

RE: Copy from a search and paste on first selection

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

RE: Copy from a search and paste on first selection

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

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