×
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

How to paste to a specific part in a script

How to paste to a specific part in a script

How to paste to a specific part in a script

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

RE: How to paste to a specific part in a script

(OP)
Hi,
thanks for the replies.
I know this is very basic to you guys but finding an explanation of how to do some of the basic tasks is sometimes more difficult than the more complex stuff.
If someone can tell me how you make a part active for either copying/pasting it would be a massive help.
Ferdo, I took a look at the link but cant make sense of it. not knowing what each line is achieving is where I'm struggling.
the code is below, any help, as always, is appreciated


Sub CATMain()

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

icount = sSel.Count 'check there is only one axis system
MsgBox icount

sSel.Copy ()

'Dim sName ***Ignore this bit****
'sName = CATIA.ActiveDocument.Selection.Name
'MsgBox sName


Dim PartDoc1 'As PartDocument 'Pointing the paste to this part
Set PartDoc1 = CATIA.ActiveDocument("Collector.Part") 'is where im stuck

sSel.PasteSpecial("CATPrtResult")
sSel.Clear
End sub

RE: How to paste to a specific part in a script

How do you want to identify, the part from where you want to copy the axis, and how do you want to identify the part that you want to past?
Do you want to past as result with link or without link?

Tiago Figueiredo
Tooling Engineer

Youtube channel:
https://www.youtube.com/channel/UC1qdlBeJJEgMgpPLV...

RE: How to paste to a specific part in a script

(OP)
TiagoFigueiredo,
Basically I need to open the product and create my collector part.
Make the top level active and then highlight a part and run the macro.
The axis system would then be copied into the collector part.
At the moment it just copies it into the highlighted part.
I also need to rename the axis system once its copied with its original part number but take one little baby step at a time :)

RE: How to paste to a specific part in a script

Try this.
In this code you must have the PN the same as the CATPart. Problably there is a better way to do it. I would like to learn it.

CODE -->

Sub CATMain()

Dim documents1 As Documents
Dim partDocument1 As PartDocument
Dim productDocument1 As ProductDocument
Dim i As Integer
Dim parts As Integer
Dim part1 'as part
Dim PN As String
Dim sSel As Selection
Dim product1 As Product
Dim product2 As Product



Set documents1 = CATIA.Documents


Set productDocument1 = CATIA.ActiveDocument
Set sSel = CATIA.ActiveDocument.Selection

Set product1 = productDocument1.Product
parts = product1.Products.Count

For i = 1 To parts
sSel.Clear
PN = product1.Products.Item(i).PartNumber
Set partDocument1 = documents1.Item(PN & ".CATPart")
Set part1 = partDocument1.Part
sSel.Add (part1)

'then you can past what you need.

Next


End Sub 

Tiago Figueiredo
Tooling Engineer

Youtube channel:
https://www.youtube.com/channel/UC1qdlBeJJEgMgpPLV...

RE: How to paste to a specific part in a script

(OP)
Thanks TiagoFigueiredo,
Ill take a look at that when I get home.
Could I be cheeky and ask where exactly I would enter the collector.part name and how I would Pastespecial(CATPtResult).

I was hoping to be able to call the colletor file to paste in to as eventually I'm going to have to reneme the axis system with the part instance name&number.

regards
Alan

RE: How to paste to a specific part in a script

@Alan
Please specify if the Collector.CATPart is already created or should be created by the macro. If is already inserted/created with an known name then you should read my link...You need to make that CATPart active (blue) and then do what you want inside that (search,copy and paste axis from CATProduct).

Regards
Fernando

https://picasaweb.google.com/102257836106335725208 - Romania
https://picasaweb.google.com/103462806772634246699... - EU

RE: How to paste to a specific part in a script

(OP)
Hi ferdo,
I create the part manually before I start collecting the data from the other parts.
I will take another look at the link.

thanks
Alan

RE: How to paste to a specific part in a script

(OP)
Cheers guys,
got the copy to work. Just have to sus out the renaming now.

@ferdo,
I used the code on the link and it works perfect for a single selection. If I use a loop it copies the last instance of a part and does it multiple times.
Have you any idea why? I have tried moving the *Sel.clear around but that makes no difference.
I also found some code you wrote that gets the name of the file. the part I pinched was:
MsgBox(sSel.Item(1).Value.Name), ,"VBScript"
This shows the instance number when you do a single selection but doesn't on a multiple selection.
I'm wondering if you can have multiple selections in a script or that I need to use a macro?

anyway
thanks for the help

alan

RE: How to paste to a specific part in a script

(OP)
Hi TiagoFigueiredo,
I did try the code but couldn't get it to work.
I couldn't figure out where/how I put the collector.part name. ?
I'm going to have another go over the weekend.

thanks
Alan

RE: How to paste to a specific part in a script

Alan

Usually when I'm writing a script for my users, I'm staying near them and watch (and ask) what exactly are their actions. Then I'm writing a short list...let's see which is yours (your scope is to copy all Axis from different CATParts inside active CATProduct in a single Collector.CATPart, isn't it? If not, define the scope as much accurate you can do):
1. Open a CATProduct (can be done manually or by script)
2. Insert a new CATPart (?) or an existing one from network? (can be done manually or by script)
3. Do you know the exactly name of this CATPart (yes/no) ? ( you can have different options to do this)
4. Activate Collector.CATPart (suppose this is the name)
5. Do the axis have already their names according to the CATParts?
6. If yes then Search your axis, copy and Paste
7. If not....think how to continue (in detail)...

Regards
Fernando

https://picasaweb.google.com/102257836106335725208 - Romania
https://picasaweb.google.com/103462806772634246699... - EU

RE: How to paste to a specific part in a script

Ferdo is Right, before made a script we need to know exactly what we want it to do.

Make a complete description of your ideas, and show an example.

Tiago Figueiredo
Tooling Engineer

Youtube channel:
https://www.youtube.com/channel/UC1qdlBeJJEgMgpPLV...

RE: How to paste to a specific part in a script

(OP)
Hi Fred
Thanks for the reply.
I’ll jot down the steps, if you can tell me wether if flogging a dead horse or not it would be welcomed.

1. Open the cat product. This would be done manually for each product and sub product.

2. Insert a new cat part. This would be done manually and the part named collector.
Each product already has a part (skeleton.part) for collecting the data but as the name changes in each product I thought it easier to collect them in a pre-named part then copy them all manually into the correct part when finished. Then delete the collector part. Maybe I should have called it temp-collector.

3. Yes if I use the collector part. No if there was a way to select the skeleton.part.

4. Yes

5. No, the axis systems are just called axis system.
The part file contains 32 numbers. I need to split this down to a specific 6 numbers plus the instance number. Ei 123456.1
I was going to try and alter some code I have that renames the part properties with the file name. Useing the split function I was hoping to add the new number to maybe the nomenclature property. This hopefully could then be used in the copy code to rename the axis systems.

As I’m still struggling with the basics I can see this taking some time.
Most of the code (actually all the code) I have done has been botched together from other code I’ve found on the internet.
I thought this would be a good learner project and it would save me some time if I got it to work.
My first step is to try and get the axis to copy correctly. Either using a pre-named part or by being able to active one (blue) and then selecting the parts to copy (red).
Then I’ll try and mod the code to rename the nomenclature box.
Then I’ll try and add the rename to the copy code.

Wish me luck, I’m going to need plenary :)

Regards
Alan

RE: How to paste to a specific part in a script

(OP)
Ferdo, my stupid spell checker changed your name to Fred.
I do apologise.

Alan

RE: How to paste to a specific part in a script

(OP)
TiagoFigueiredo,
Sorry I missed your post before I replied to ferdo.
Any help you can offer is really appreciated.
Thanks
Alan

RE: How to paste to a specific part in a script

Let me try to figure out what you are trying to do. It's still not clear in my head what you are trying to do.

Let's make step by step, baby steps :)
For now let's concentrate in step 2

after you open the catproduct, macro insert a new part to the CATProduct.
Questions:
1-For this new part created in CATProduct, which Part Number you want to give her?
2-Where you want to save this part


Later for step 3, if you can show with images what are you trying to do would be really usefull, I'm still trying to understand what you want.

Tiago Figueiredo
Tooling Engineer

Youtube channel:
https://www.youtube.com/channel/UC1qdlBeJJEgMgpPLV...

RE: How to paste to a specific part in a script

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

RE: How to paste to a specific part in a script

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

RE: How to paste to a specific part in a script

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:
https://www.youtube.com/channel/UC1qdlBeJJEgMgpPLV...

RE: How to paste to a specific part in a script

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

RE: How to paste to a specific part in a script

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

RE: How to paste to a specific part in a script

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

RE: How to paste to a specific part in a script

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:
https://www.youtube.com/channel/UC1qdlBeJJEgMgpPLV...

RE: How to paste to a specific part in a script

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

RE: How to paste to a specific part in a script

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 http://www.coe.org/p/fo/et/thread=17535 --it should give you the right push.

regards,
LWolf

RE: How to paste to a specific part in a script

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

RE: How to paste to a specific part in a script

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

RE: How to paste to a specific part in a script

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

RE: How to paste to a specific part in a script

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

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


Close Box

Join Eng-Tips® Today!

Join your peers on the Internet's largest technical engineering professional community.
It's easy to join and it's free.

Here's Why Members Love Eng-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close