• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

cs sdk: copying an item from one document to another

New Here ,
Dec 24, 2008 Dec 24, 2008

Copy link to clipboard

Copied

is there a way to copy any item from one ai document to the other ?
TOPICS
SDK

Views

3.1K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe
Guide ,
Dec 24, 2008 Dec 24, 2008

Copy link to clipboard

Copied

You do it just like you would copy art within a document; you just need the source art & destination art (for use with the relative positioning). Art handles are unique for the life of the documents to which they belong, so if you can get the two handles, it will copy them from one document to the other.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Dec 24, 2008 Dec 24, 2008

Copy link to clipboard

Copied

if I copy a layer (which by now I don't know how to do but still)from one document to another will the contents of the layer be copied as well or will just an empty layer be copied?

i'm asking this because i want the structure of the copied items to be the same as those in the source and I don't want to go through the hassle of creating the structure in the destination item by item.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Dec 29, 2008 Dec 29, 2008

Copy link to clipboard

Copied

I *believe* if you copy the top level group (i.e. the actual group-that-is-really-a-layer) it will copy all the contents as well.

If not though, I don't think it would be that big of a hassle; a simple recursive function carefully constructed should reassemble it exactly in the destination document.

Thinking about it a little more, I wonder if copying the layer group and using a NULL relative art, with kPlaceArtOnTop (or whatever the non-relative one is) might just copy the layer perfectly. I'm not sure though, having never tried it. Looking at AILayer.h I see nothing about copying layers though, which actually leads me to believe what I've suggested would work. I think if it didn't they would have had to add a 'copy layer' method of some sort.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Mar 16, 2009 Mar 16, 2009

Copy link to clipboard

Copied

Back to this discussion - should I use sAIDictionary->Copy(srcDict, destDict) method to copy all items from source to destination document or there is any other API call for that? When I use that Copy method - my destination document stays blank. Do I need any update/refresh as well?

Any help would be appreciated.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Mar 17, 2009 Mar 17, 2009

Copy link to clipboard

Copied

You should be using AIArtSuite::DuplicateArt(). Copying dictionaries won't copy artwork.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Mar 17, 2009 Mar 17, 2009

Copy link to clipboard

Copied

Should I obtain an art(s) of source document via some AIDocumentSuite method?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Mar 18, 2009 Mar 18, 2009

Copy link to clipboard

Copied

No, you'd mostly want calls from AIArtSuite (AIArt.h). All of the tools for navigating the document's art tree are in there. You might want the odd call from AILayerSuite (AILayer.h), depending on whether you're looking to copy art from a specific layer.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Mar 18, 2009 Mar 18, 2009

Copy link to clipboard

Copied

So, my sequence of calls is as such:

// While source document is active
AIArtHandle srcArt;
sAIArt->GetFirstArtOfLayer(nil, &srcArt);

// Now destination doc is opened
AIArtHandle destArt;
sAIArt->DuplicateArt(srcArt, kPlaceAbove, nil, &destArt);

But after this I don't see any changes in destination doc, i.e. it stays blank. And I assume I need to do something in addition with that newly created destArt object. Do I? In my source document I have only one default layer and several Paths on it.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Mar 18, 2009 Mar 18, 2009

Copy link to clipboard

Copied

So far from my tests I could see that I could use that mentioned earlier DuplicateArt method only within same document, but not between different documents. Is it possible then at all to copy art from one document to another?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Mar 18, 2009 Mar 18, 2009

Copy link to clipboard

Copied

Maybe you can't place the art inside nothing. I know that works for some things, but maybe it doesn't work here. Try getting the first art of the destination layer you want and place above inside on that.

I know this is possible because I have working code that does this. I'm looking at it right now and it only uses GetFirstArtOfLayer() & DuplicateArt().

BTW, to switch documents, I use AIDocumentList::Activate(), which expects a handle & a boolean about whether or not it should grab input focus.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Mar 18, 2009 Mar 18, 2009

Copy link to clipboard

Copied

Yes, kPlaceAboveAll setting did the trick. Now I have my art copied into destination doc. But when I click on it I get:

The operation cannot complete because of an unknown error. [PARM]

Did you have that error at all?

And related question - that newly duplicated art is placed into the center of new document. Is there any simple way to move it to a corner? In DuplicateArt description there such statement that I need to use deep move, but I don't see any MoveArt method at all.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Mar 19, 2009 Mar 19, 2009

Copy link to clipboard

Copied

More information - in my source doc I have Layer 1 and several Paths inside it. I could normally expand that layer in Layers palette and see those enclosed Paths objects. Now in destination doc I have again that Layer 1 with expand twistie near it, but when I click it - it doesn't expand. Is it a bug or do I miss something else for DuplicateArt call (like some specific dictionary entries I need to add/set manually)? For that layer in destination doc I don't have available Locate Object menu, which I have for source doc layer.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Mar 19, 2009 Mar 19, 2009

Copy link to clipboard

Copied

I don't have any trouble when copying from one document to another. I'm not sure what's going on; that it gives you an error when you click on the art suggests you didn't do something *quite* right when copying the art, though I'm not sure what that would be. The fact that the layers palette seems to have missed that art was added is further evidence that something isn't quite right. If you've got code, post it and maybe I can spot the problem.

As for placement of the art, it should arrive in the document in the exact 'hard' location as in the previous document. Basically, it should be it's absolute location on the canvas, regardless of what your document setup is, what your artboard size or orientation is.

If you want to shift it, I'd recommend grabbing the extents of your resultant copied art and using that to calculate a translation. Then create a matrix representing the shift and use AITransformArtSuite::TransformArt() to do it all at once.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Mar 19, 2009 Mar 19, 2009

Copy link to clipboard

Copied

I'm using Adobe Illustrator CS3 13.0.2 on Windows XP inside VMware.

My code of copying art is as follow:

//While in source doc
AIArtHandle srcArt;
sAIArt->GetFirstArtOfLayer(nil, &srcArt);

//Now create new doc
AIDocumentHandle docHandle;
ai::UnicodeString preset; // leave it empty to use default preset
AINewDocumentPreset parameter;
parameter.docWidth = newWidth; // 4 times larger than src new width
parameter.docHeight = newHeight; // 4 times larger than src new height

//Here new document opens and becomes active
sAIDocumentList->New(preset, &parameter, kDialogNone, &docHandle);

//Now copy that initial art to new doc
AIArtHandle destArt;
sAIArt->DuplicateArt(srcArt, kPlaceAboveAll, nil, &destArt);

At this point if I click with mouse on that newly copied art - I get that Illustrator error. Should I explicitly call AIDocumentList::Activate() after I call that sAIDocumentList->New(...)? Or is it because I'm trying to set bigger width/height for new doc and thus 'hard' positioning fails to work correctly?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Mar 19, 2009 Mar 19, 2009

Copy link to clipboard

Copied

A couple of things:

1) You might try being more explicit about your destination. Rather than just dumping them into the document using a NULL relative art, try getting the first art of the (only) layer in the destination document. That'll be the group that 'is' the layer; then try kPlaceInsideOnTop or something like that on that group. I don't know why it would matter, but it might.

2) I've never done any of this using sAIDocumentList->New(). My code is used to pull art into the current document from another document. I don't know why that would matter, but if all else fails you might try the code having opened the document manually, just to see if it makes a difference. You'd just use Activate() in that case.

3) I don't think the setup of the destination document should matter at all. It doesn't seem to matter for any of the documents I've tried on our 'import from another open document' code.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Mar 19, 2009 Mar 19, 2009

Copy link to clipboard

Copied

Your 1) suggestion doesn't work. I've changed my code to this:

AIArtHandle group;
sAIArt->GetFirstArtOfLayer(nil, &group);
AIArtHandle destArt;
sAIArt->DuplicateArt(srcArt, kPlaceInsideOnTop, group, &destArt);

And still get exactly the same Illustrator error.

Your 2) suggestion isn't appropriate for me, cause I need to create new doc programatically.

Do you know if Adobe folks monitor this forum or should I try to post a possible bug report somewhere?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Mar 19, 2009 Mar 19, 2009

Copy link to clipboard

Copied

If I do GetArtFirstChild/GetArtSibling of initial group and duplicate them - then it works. So it seems really a bug with unability to properly copy main group with all art childs to destination document.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Mar 20, 2009 Mar 20, 2009

Copy link to clipboard

Copied

One more question - while copying with DuplicateArt I always get my new object centered inside new document. What parameter/call should I use to place it exactly at the corner as it was in original document?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Mar 23, 2009 Mar 23, 2009

Copy link to clipboard

Copied

I don't believe DuplicateArt centers the result, or it shouldn't. I use it and it seems to pick up the underlying coordinate system. Basically, if you were able to overlay both documents, the art should be in the same relative place on the canvas.

As for your solution -- I didn't realize you were copying the layer group (if that's what you were doing) -- I missed that, sorry. Looking at my code, I'm doing it art-by-art, not top-level-group by top-level-group. And I'm sure I would have tried that, so I probably had the same problem.

As for Adobe people reading the forum, I know some read the Photoshop forum, but I've seen little evidence of Adobe traffic in this one unfortunately. I was at a conference last year and I brought that up, but nothing seems to have come of it, at least not yet :)

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jun 24, 2011 Jun 24, 2011

Copy link to clipboard

Copied

I'm not one for bumping old threads, but this problem is really giving me a headache...

I'm having the same exact problem with copying groups from one document to another.  It doesn't seem to matter if it's a top-level group or not; any group that gets copied over results in the copied art not showing up in the layer list and gives errors when trying to click on it.

If my source document looks like this:

Layer 1

  <path 1_1>

  <path 1_2>

  Layer 2

    <path 2_1>

If I DuplicateArt on the GetFirstArtOfLayer(Layer 1), Layer 1 gets copied into the new document, but it doesn't show up in the layer list and I get errors trying to click on any of the art.

If I iterate over the children/siblings of Layer 1 and duplicate them all separately, <path 1_1> and <path 1_2> will show up correctly in the new layer list and are clickable, but Layer 2 will not, and clicking on <path 2_1> results in the error.

At this point, the only solution I can think of is to recursively iterate over the source tree, manually creating the destination groups, and then copying the art work into them.

Very frustrating!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Jun 24, 2011 Jun 24, 2011

Copy link to clipboard

Copied

I had this same problem, and came up with a similar solution, except that you don't need to recreate all the groups. Recreate your layers in the new document (via sAILayers->NewLayer() (or whatever the function is....)), then iterate through and copy all the top-level art from each layer seems to be enough.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jun 24, 2011 Jun 24, 2011

Copy link to clipboard

Copied

LATEST

But the problem is when the top-level art is a group.  Or when any of the children of the top-level art is a group.  Duplicating groups is what seems to break it.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines