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!

How to paste to a specific part in a script

Status
Not open for further replies.

Alan Lowbands

Aerospace
May 17, 2017
274
GB
Hi Guys,
Can anyone tell me how I paste to a specific part in a script.
Simply, how do I make it the active part. the part is called Collector and I create it in the product I'm currently working in.
I have tried 'Set Collector = CATIA.ActiveDocument' but it wont work.

sorry if this is a stupid question but I'm stuck

thanks
Alan
 
Replies continue below

Recommended for you

Cheers guys,
Will post some images.
Could I be approaching this wrong.
My code searched for the axis systems in the selected parts using.

Set sSel = CATIA.ActiveDocument.Selection
sSel.Search "CATGmoSearch.AxisSystem,sel"

Which I assume let’s me run through them one at a time with the next command.

Should I searching for the part itself and then in turn searching that for the axis system and name etc ?

I don’t know if this makes any sense as I’m not sure how the *.search command works.

Cheers
Alan
 
Hi Gents,
Can anyone tell me why this code only copies the last instance of the parts. ie ABCD.4 and not all four instances.

cheers guys
Alan

Sub CATMain()

Dim sSel 'As Selection
Set sSel = CATIA.ActiveDocument.Selection
sSel.Search "CATGmoSearch.AxisSystem,sel"

icount = sSel.Count
MsgBox icount & " Axis-Systems Selected" 'THIS SHOWS THAT ALL INSTANCES ARE SELECTED

Dim i 'As Integer
For i = 1 To sSel.Count
'sSel.Item(i).Value.Name = sSel.Item(i).Value.Name&i 'WHEN ACTIVE THIS LINE ADDS a number 1 TO THE NAME
'OF THE FIRST AXIS COPIED
sSel.Copy()

' MAKE COLLECTOR ACTIVE FOR PASTE
Dim documents1 'As Documents
Set documents1 = CATIA.Documents
Dim partDocument1 'As Document
Set partDocument1 = documents1.Item("Collector.CATPart")
Dim part1 'As Part
Set part1 = partDocument1.Part
Dim selectPart
Set selectPart = CATIA.ActiveDocument.Selection
Dim editPart
Set editPart = partDocument1
selectPart.Add(partDocument1.Part)
CATIA.StartWorkbench("Collector")
'selectPart.Clear() * CODE WONT RUN WITH THESE TWO LINES ACTIVE *
'editPart.Activate() **********************************************************

sSel.PasteSpecial("CATPrtResult") ' WORKS BUT ONLY COPIES LAST INSTANCE

sSel.Clear
Next
End sub
 
What do you want to do in this step? I never used it.

CATIA.StartWorkbench("Collector")

Before make the past action, select the part that you want to past the axis system.

You can make.
sSel.Clear()
sSel.Add(partDocument1.Part)

sSel.PasteSpecial("CATPrtResult")

Tiago Figueiredo
Tooling Engineer

Youtube channel:
 
Thanks Tiago,
No matter what I do I cannot get the code to copy all instances of a part.
The product I'm using to test it on has.
1 x one.part
2 x two.part
3 x three.part
4 x four. part
&
1 x collector.part.

it says that it has found 10 axis systems but only copies four of them.
the last instance of each part.
I really don't know where to go from here.

best regards
Alan
 
If you select an item in one instance, it highlights in all instances--it is just the same part... so it really is just one coordinate system... why would you like to have it repeated the number of instances? but if that is what you want, then count the instances and copy in the ONE and same axis system so many times

regards,
LWolf
 
Hi Lwolf,
The collector copies the axis systems position.
If I had 50 bolts all the same part I would need to know where each one is placed inside the product.

Cheers
Alan
 
In past, I did a macro to create negative copy, and copes well with various instances.

What I did:

step 1.

Select the parts
Code:
 selection1.Clear()
        Dim InputObjectType(0)
        InputObjectType(0) = "Product"

        Dim Status = selection1.SelectElement3(InputObjectType, "Seleccione os componentes a alojar.", True, CATMultiSelTriggWhenUserValidatesSelection, False)

        If Status = "Normal" Then
            Num_Parts = selection1.Count
            ReDim Preserve Parts_number(Num_Parts)
            ReDim Preserve Parts_name(Num_Parts)
            ReDim Preserve Parts(Num_Parts)

            For i = 1 To Num_Parts
                Parts(i) = selection1.Item(i).Value
                Parts_number(i) = selection1.Item(i).Value.partnumber
                Parts_name(i) = selection1.Item(i).Value.name
            Next
        Else
            Exit Sub
        End If
        selection1.Clear()

Here I did the selection manually, but you can make the selection, similar to the way that I suggested you a few post ahead. But the main idea is to create an Array of parts. In this case the array that we need is Parts().

Step 2

You must create a cycle for, where it will go throw all of the array parts (in this step I don't have a particular code to share, but I will post my idea. You can try to convert this to code)
Here you must select the part from the array

Code:
For i=1 to Num_Parts
selection1.Clear
selection1.add(Parts(i))'Don't forget that the "i" is from cycle for
'Make the search for the desired axis system
selection1.copy
selection1.Clear

'Now you must select the collector part
selection1.add(partDocument1.Part)
selection1.PasteSpecial("CATPrtResult")
selection1.Clear
Next'i

I believe that in this way you will achieve what you are trying to do.

Give me the feedback please




Tiago Figueiredo
Tooling Engineer

Youtube channel:
 
Hi Tiago,
Thanks for the reply.
I’ve been away most of the weekend but will be trying the code tomorrow when I’m back on my cad box.
All the code I’ve played with has been scripts, will this work in a cat script or will it need to be a macro?
I’m going to start doing a couple of hours each night on the course I got before Christmas, I just haven’t had chance to start it properly.
Hopefully I won’t be asking stupid questions much longer :)

Thanks again
Ala;
 
hi Alan, I suspected you wanted the position of the individual instances :) As such, it is not the part coordinate system you want--you want each instance's position in a given reference product.
Try this post --it should give you the right push.

regards,
LWolf
 
Thanks LWolf,
I'll have to read that a few time to make it sink in.
It looked so simple to copy the axis system from each instance, paste it into another part, rename it and 'hay presto' all done.
Things never go to plan lol
What I don't understand is, if you copy and paste from the tree it works no problem. why is it so difficult in a script?
 
Tiago,
I tried to use the code but kept getting error messages. Is some of these commands only available to use in a macro. I'm having to use a catscript for this. :(

LWolf,
Thanks for the link. I'm not sure how this works and need to get my head around what it's doing. :0


Guys,
I noticed that if I run one selection at a time it seems to work and copy each axis system as I need it too. Even the instances.
Is there a way I could select the first part in the tree and then get the code to work its way down the tree one part at a time until it reaches the end?
If this is possible I could look at the renaming part that I haven't even thought about yet :(
I think the big problem I have is that I cant use a macro. I have to run a script from a usb stick so I can't use the features available for macros.
From what I have read it seems I should be using an array but cant :(
Could someone could tell me if I'm barking up the wrong tree lol
I really do appreciate all the help.

woof
Alan
 
Gents,
A massive thank you to everyone who helped me get this to work.
My code is rough to say the least and I can't get it to loop through the selected parts, but, it will save me thousands of mouse clicks over the next few weeks.

very best regards
Alan
 
hi again Gents,
I was wrong, the bit of code wont work :(
It copies and renames the axis ok but puts it in a temp file. When I copy them to the correct part and delete the temp file I loose the links.
Is there anyway I could select the destination for paste so I don't get this problem. May make the destination part as the active document & the part to copy from the active document selection?
The code is below, any help really would be welcome.
cheers
Alan

*****************************************************
Sub CATMain()

Dim uSel 'As User Selection
Set uSel = CATIA.ActiveDocument.selection

Dim nSel 'As Name
nSel = uSel.item(1).value.name

Dim nSel2
nSel2 = nSel
CStr(nSel2)
Dim nSel3 'gets Part number
nSel3 = Mid(nSel2 , 19, InStr(nSel2 , ".") -25)
Dim nSel4 'gets instance number
nSel4 = Mid(nSel2 , 33, InStr(nSel2 , ".") -1)

Dim sSel
Set sSel = uSel

'Set visProperties1 = CATIA.ActiveDocument.Selection.VisProperties 'Hide Part
Set visProperties1 = uSel.VisProperties 'Hide Part
visProperties1.SetShow catVisPropertyNoShowAttr

sSel.Search "CATGmoSearch.AxisSystem,sel"

sSel.Copy()

' MAKE COLLECTOR ACTIVE FOR PASTE

Dim documents1 'As Documents
Set documents1 = CATIA.Documents
Dim partDocument1 'As Document
Set partDocument1 = documents1.Item("TempAxisCollector.CATPart")
Dim part1 'As Part
Set part1 = partDocument1.Part
Dim selectPart
Set selectPart = CATIA.ActiveDocument.Selection

sSel.Add(partDocument1.Part)
sSel.PasteSpecial("CATPrtResult")

Dim pSel
Set pSel = CATIA.ActiveDocument.selection
pSel.item(1).value.name = nSel3 & nSel4

uSel.Clear()
'sSel.Clear()
'nSel.Clear()
'nSel2.Clear()
pSel.Clear()

End sub
*****************************************************************************************************
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top