I am trying to do what someone did in this other thread regarding Exporting to PNG.
reference: http://forums.adobe.com/thread/320685
We have multiple layers (some off and locked).
I'd like to pass all the selected items to the Image Optimization Action as a group instead of optimizing each one. I am using AIMatchingArt Suite to get the selected items, but it points to an array of AIArtHandles... any thoughts?
You may be right... I was very tired when writing that (still am). Also my C++ dereferenced pointer logic is a little fuzzy.... been many years since I've used it.
sAIMatchingArt->GetSelectedArt(&store,&count) populates the variable store which is an AIArtHandle** and I need to get that into an AIArtHandle art;
The FOR loop in the code sets art = (*store)[index]; That is great if I want individuals... but I want a single reference to the group. Can I do the following?
art = **store;
Or will the whole thing blow up when I pass it to the sAIImageOptimization->AsPNG(art, dstfilter, params); call?
If you need it to be a group, that will mean copying or moving the art into a single group (I recommend copying if you want to leave the document as it was when you're done!). If that's the case, just create a kGroupArt somewhere and then start iterating your list of handles using AIArtSuite::DuplicateArt() or AIArtSuite::ReorderArt(). Do your optimizing and kill
One thing to be aware of w.r.t. the matching art array -- it may do something that some of the other mass 'get selected art' functions do. The AIArtSuite's GetSelectedArt() call will get you a handle to a compound path AND each of its children. So if you had only a compound path with two sub-paths in a document and the compound was selected, you'd get three handles back: the compound parent and the two sub-paths. That means if you copied all three you'd double up the two sub-paths and they might not be rendered correctly (since they likely inherit properties like stroke & fill from their parent). There's an attribute you can test for, kArtPartOfCompound, to sort this problem out with the help of AIArtSuite::GetArtUserAttr().
I actually needed to set some of the AIImageOptPNGParams2 parameters, so I went with a call to MakePNG24 like the original poster did.
It seems to work just using:
art = **store;
So I don't need to create the group.
I'll have to test it more to verify that I am not getting the duplicate sub-paths you mentioned. My first pass was a very simple test.
Once I finish testing, I'll post the code.
This is how I ended up doing it and it works. (In addition to the other code that was referenced in the original post).
I don't know if it would work better with an ArtSet, but this works. Perhaps if the images I am flattening were a little more complicated, I'd run into the duplication you've mentioned.
result = sAIActionManager->PlayActionEvent(kAISelectAllAction, kDialogOff, NULL);
result = sAIMatchingArt->GetSelectedArt( &store, &count );
if ( result ) {
store = NULL;
count = 0;
}else {
result = sAILayer->InsertLayer (NULL, kPlaceAboveAll, &newLayer);
if (newLayer && !result)
{
sAILayer->SetLayerVisible (newLayer, true); // show layer
sAILayer->SetLayerIsTemplate (newLayer, false); // mark as NOT a template layer so does get exported
sAILayer->SetLayerEditable (newLayer, true);
result = sAIArt->NewArt(kGroupArt,kPlaceAboveAll,nil,&group);
for ( index = 0; ( result == kNoErr ) && ( index < count ); index++ ) {
AIArtHandle art = (*store)[index];
AIArtHandle copy;
//add art to the group
result = sAIArt->DuplicateArt(art,kPlaceInsideOnBottom,group,©);
}
}
}
The duplication only comes into play if you have compound paths, so its easy enough to test. The trick is you could easily have compound paths that DO cause duplication and still not see an artifact visually. You could still see some in other cases though. I think one that would be a good example is a donut: take two squares, one inside the other and compound them. If you get no duplicates, you'll just get the donut and it will obviously look okay. If you do get duplicates, you'll get the compound, with its two paths inside when you copy, but also the two paths separately. If you have a fill (e.g. black) then you'd probably get both squares as filled black -- and since they're not a compound, they'd just appear on top of one another, providing what would seem to be just a large black square (as opposed to one with a hole in it). The test, as I said earlier, is fairly easy if you do see this problem: just ask the art before you copy it if it has the kArtPartOfCompound attribute. Again, this is assuming you actually have the problem ![]()
Also, and this is another consideration I just thought of: is Z-order preserved? Maybe you've tested this, but you might try layering three coloured boxes and making sure they get rendered correctly. One would assume that the array of art handles would be in the order they were encountered, but you never know. Well, you don't know until you test it, which you may have already done ![]()
Yeah, I think we basically test for kArtPartOfCompound and skip it, knowing we'll handle the parent. Obviously if you want to do something with compound children, you'd handle it ![]()
Z-order is trickier, but I think you'll get the selected art in top-to-bottom order. Either that, or the reverse ![]()
North America
Europe, Middle East and Africa
Asia Pacific