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

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
 
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 :)
 
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:
 
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
 
@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

- Romania
- EU
 
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
 
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
 
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
 
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

- Romania
- EU
 
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
 
Ferdo, my stupid spell checker changed your name to Fred.
I do apologise.

Alan
 
TiagoFigueiredo,
Sorry I missed your post before I replied to ferdo.
Any help you can offer is really appreciated.
Thanks
Alan
 
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:
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top