OberonPlace.com Forums  

Go Back   OberonPlace.com Forums > Developer Forums > VBA > CorelDRAW/Corel DESIGNER VBA

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 14-04-2010, 07:09
basti.schneider
Guest
 
Posts: n/a
Default Copying Shapes from one File to another

Hello,

does anyone know a trick how to reliably copy shapes from one file to another?

I have a few methods but none is perfect.


Method 1: Copy & Paste
===============

Shape.copy
TargetLayer.paste

Problems: it's not as fast as one could hope as the shape is added to the clipboard in several formats (I think).
And the resulting files are sometimes corrupted. The clipboard doesn't seem to be too reliable (at least in X3).


Method 2: Virtual Shapes
================
dim tn as TreeNode
set tn = QuellShape.TreeNode.GetCopy
tn.UnLink
tn.LinkAsChildOf(TargetLayer.TreeNode)
TargetLayer.Page.Parent.Parent.LogCreateShape(tn.VirtualShape)

Advantage: fast
Disadvantage: not reliable. The resulting files are often corrupted and can't be opened after they are saved.
And the ObjectDatas of the shapes get lost.


Method 3: Exporting an importing
=====================

SourceShape.CreateSelection;
ActiveDocument.SaveAs(TempFilename, cdrCurrentVersion, cdrSelection)
ImportFileToLayer(TargetLayer, TempFilename)

Advantage: the only reliable method I know.
Disadvantage: sloooow


Method 4: CopyToLayer
===============

sh.CopyToLayer TargetLayer

Problem: this doesn't work.
Error: "The layer object doesn't belong to this document."



Does anyone know another method to copy shapes from one document to another document?

Are there any new methods in X4 or X5 that make it possible to move shapes from one document to another document?

Any suggestions would be greatly appreciated!

Thanks,

Basti
Reply With Quote
  #2  
Old 14-04-2010, 09:50
runflacruiser's Avatar
runflacruiser runflacruiser is offline
Senior Member
 
Join Date: Jun 2009
Location: Pigeon Forge, TN USA
Posts: 811
Default

Depending on what type of shape your copying this method by Alex may work.
You can even save to registry and retrieve later:

http://forum.oberonplace.com/showthread.php?t=978

-John
Reply With Quote
  #3  
Old 14-04-2010, 10:31
basti.schneider
Guest
 
Posts: n/a
Default

Thanks for the interesting suggestion!

Unfortunately the shapes I have to copy are as complex as Corel shapes can get:
groups with bitmaps and powerclips and lenses and...
Reply With Quote
  #4  
Old 14-04-2010, 10:36
runflacruiser's Avatar
runflacruiser runflacruiser is offline
Senior Member
 
Join Date: Jun 2009
Location: Pigeon Forge, TN USA
Posts: 811
Default

Ah.
Another idea...
You could also incorporate all of your working methods into the code and transfer shapes depending on shape type using conditionals. This should enable virtual shapes to work some of the time therefore speeding up processing (if your batch processing many that is)
-John
Reply With Quote
  #5  
Old 14-04-2010, 12:50
shelbym's Avatar
shelbym shelbym is offline
Senior Member
 
Join Date: Nov 2002
Location: Cheyenne, WY
Posts: 1,769
Blog Entries: 9
Send a message via ICQ to shelbym Send a message via AIM to shelbym Send a message via MSN to shelbym Send a message via Yahoo to shelbym
Default

Quote:
Originally Posted by basti.schneider View Post
Are there any new methods in X4 or X5 that make it possible to move shapes from one document to another document?
In X5, there is a feature to create a new document from a shape or shaperange.

ShapeRange.CreateDocumentFrom
Function CreateDocumentFrom(TemporaryDocument As Boolean = False) As Document

Code:
ActiveSelectionRange.CreateDocumentFrom
Would copy the current selection to a new document.

-Shelby
Reply With Quote
  #6  
Old 12-03-2012, 19:05
Dima DD
Guest
 
Posts: n/a
Default

I've tried another very simple method, it works fine for me :

Code:
dim al as layer
dim tmpl as layer
dim sh1 as shape
dim sh2 as shape

set al = ActiveLayer
set tmpl = ActivePage.CreateLayer("Temp")
tmpl.Import ("sourcefile.cdr")
tmpl.Shapes.First.Ungroup
Then I decide which sh1 I want to take from tmpl and...

Code:
Set sh2 = sh1.Duplicate
sh2.MoveToLayer al
(unfortunately, CopyToLayer method reports errors in my X5... )
And finally...

Code:
tmpl.delete
This method is enough fast, especially with

Code:
Optimization = true

Last edited by Dima DD; 12-03-2012 at 19:07.
Reply With Quote
  #7  
Old 05-05-2012, 08:35
FaneDuru FaneDuru is offline
Member
 
Join Date: May 2012
Posts: 35
Question

What is strange using 'CopyToLayer' (X5) is the fact that it does the job... It stops the code reporting an error (automation). If you use it between 'On Error Resume Next' and 'On Error GoTo 0' it works...
Reply With Quote
  #8  
Old 05-05-2012, 10:32
FaneDuru FaneDuru is offline
Member
 
Join Date: May 2012
Posts: 35
Default

This code works too. You need to name the shape which must be copied (on the cdr file):
Code:
Dim al As Layer

Optimization = True

Set al = ActiveLayer
With al
    .Import ("sourcefile.cdr")
    .Shapes.First.Ungroup
    .Shapes.AllExcluding("Test", "Rect_test").Delete
End With

Optimization = False
Inside the excluding paranthesis in case you have on the active layer some other shapes, these must also be here...
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Import text file to create shapes jess916 Macros/Add-ons 3 12-08-2008 20:21
Copying perspective from objects LaffRiot General 4 15-06-2008 11:09
Problem copying text and knowbodynow CorelDRAW/Corel DESIGNER VBA 7 28-05-2008 08:01
Copying Objects From Master Layers? knowbodynow CorelDRAW/Corel DESIGNER VBA 4 02-06-2007 02:38
Glitches in Copying and Pasting Shapes? Granite Golem CorelDRAW/Corel DESIGNER VBA 4 24-05-2005 18:31


All times are GMT -5. The time now is 22:53.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
Copyright © 2011, Oberonplace.com