Continue to Site

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 Paste Script

Status
Not open for further replies.

akhtar07

Mechanical
Mar 8, 2015
59
AE
Hello Everyone,

I need a macro for copy pasting picture from one drawing sheet_01 background to another drawing sheet_01 background. I have like 1000+ parts for this job and it scares me a lot, not bcox of the work load but there is a greater chances of making a mistake.

The tricky part is the sheets are having different names, I need a general macro which can be used on every two drawings regardless of the names and titles.

Please guys help me out here.

Warm regards,
Akhtar Aziz
 
Replies continue below

Recommended for you

ready to help...

did you search and find anything close to what you need?

how much you know about vba / scripting ?

can you post your start and tell us when the problem is?

Thanks

Eric N.
indocti discant et ament meminisse periti
 
Thanks for your interest.

There are two different types of things that I need to copy from one drawing to another drawing.

1. Picture in the sheet background
2. Text in normal drawing sheet

I got successful with the text somehow but when I tried to record the macro for the picture, something weird happened. The macro executes normally buh the image is pasted in the form of raster or stl type with size reduced by like 10 times and you cannot edit it, select it or delete it.

I have attached an image to clear the confusion. I am trying to copy the picture "Controlled Copy" from drawing01 to drawing02 in the sheet background but it changes to something undetectable.

I don't have a knowledge of VBS, I just record the macro and then use my intuition to make it working or I post things on this forum and get help from the people.

Below is the script:

Sub CATMain()

Set specsAndGeomWindow1 = CATIA.ActiveWindow

specsAndGeomWindow1.ActivateNext

Set windows1 = CATIA.Windows

Set specsAndGeomWindow2 = windows1.Item("Controlled copy sample.CATDrawing")

specsAndGeomWindow2.Activate

Set drawingDocument1 = CATIA.ActiveDocument

Set selection1 = drawingDocument1.Selection

selection1.Clear

Set drawingSheets1 = drawingDocument1.Sheets

Set drawingSheet1 = drawingSheets1.Item("84615-805")

Set drawingViews1 = drawingSheet1.Views

Set drawingView1 = drawingViews1.Item("Background View")

Set drawingPictures1 = drawingView1.Pictures

Set drawingPicture1 = drawingPictures1.Item("Picture.6")

selection1.Add drawingPicture1

selection1.Copy

specsAndGeomWindow2.ActivateNext

specsAndGeomWindow1.Activate

Set drawingDocument2 = CATIA.ActiveDocument

Set selection2 = drawingDocument2.Selection

selection2.Clear

Set drawingSheets2 = drawingDocument2.Sheets

Set drawingSheet2 = drawingSheets2.Item("84465-810-1-L")

selection2.Add drawingSheet2

selection2.Paste

End Sub

Warm regards,
Akhtar Aziz
 
 http://files.engineering.com/getfile.aspx?folder=79ec742d-85e6-4cbd-a808-1e11630796fd&file=CC-01.jpg
I have the following code in R24SP5 and it works for me. what is your catia level?

I copy a PNG picture inserted with "insert / picture" command from the background of doc1 to the background of doc2.

position and size are kept from doc1 to doc2 (so if doc2 if bigger, then position will have to be adjusted, also if scale1 and scale2 are not the same some action might be required... but here background view scale is 1 on both drawing)

Code:
Sub main()

Dim drawing1, drawing2 As DrawingDocument

Set drawing1 = CATIA.ActiveDocument
Set drawing2 = CATIA.Documents.Item(CATIA.Documents.Count - 1) ' you have to find which item # is the doc2...


Dim bgview1, bgview2 As DrawingView

Set bgview1 = drawing1.Sheets.ActiveSheet.Views.Item(2)
Set bgview2 = drawing2.Sheets.ActiveSheet.Views.Item(2)

Dim pic1 As DrawingPicture

Set pic1 = bgview1.Pictures.Item(1)

Dim osel1, osel2 As Selection

Set osel1 = drawing1.Selection
Set osel2 = drawing2.Selection

osel1.Clear
osel2.Clear

osel1.Add pic1
osel1.Copy


osel2.Add bgview2
osel2.Paste

End Sub

Eric N.
indocti discant et ament meminisse periti
 
after looking at your code again I see that after you copy the picture, you select sheet from doc2 and add it to selection (as destination for paste), I do add the backgroundview (not the sheet) to my selection.

That will bring your picture into the Mainview.
You can check the scale of the mainview by checking the scale of the sheet.
the scale of the background view is visible from VBA code

Eric N.
indocti discant et ament meminisse periti
 
Hi,

I don't get the part of what is your CATIA level?

Position and size of the both of the documents are exactly the same. The drawing is A3.

I will try this code and let you know how it goes for me.

Warm regards,
Akhtar Aziz
 
Hey,

Just tried to run your macro but it gave error on the following line:

Dim drawing1, drawing2 As DrawingDocument

don't know the reason .. !!!

Warm regards,
Akhtar Aziz
 
what version of catia you using?

Eric N.
indocti discant et ament meminisse periti
 
what release of v5 you using?

Eric N.
indocti discant et ament meminisse periti
 
guess it's something with your file.
my script give me same result in R20 and R24

Eric N.
indocti discant et ament meminisse periti
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Top