I'm facing an issue when trying to set an entry value in an art object's dictionary with AICS6 SDK.
When I click on the "Outline" button, it is supposed to set an entry (named "FB_CurveType") in the dictionary of the selected art object.
newKey = pAIDictionary->Key("FB_CurveType");
pAIDictionary->SetIntegerEntry(dataDict, newKey, type);
The Art Handle named "hArt" is returned by a wrapper function called GetCurrentSelection() :
size_t count = 0;
pAIArtSet->IndexArtSet(set, 0, &hnd);
The returned art handle is valid (not NULL) and I can successfully set the value, and re read it immediatly after setting it (even when disposing/re-getting a reference to the dictionary).
The problem comes when I click on "Get Data", it is supposed to loop through each art handle in the document, and check if it has an entry called "FB_CurveType" in its dictionary. Unfortunately, the returned Art Handle's dictionary is empty, and no error code is returned by the SDK functions.
I have also noticed that the art handle's value is not the same as the one in the selection code above, at first I thought "Well, maybe that's because Illustrator returns some dynamicaly allocated pointer or something", but when I'm clicking on "Outline" again, the art handle's value is the same as the one in the previous call.
My guess is that my function to get all the art objects in the document makes an older or a pale copy of the real art object. Here is the function :
void GetArtsByType(AIArtType artType, AIArtSet set)
specs.type = artType;
specs.whichAttr = 0;
specs.attr = 0;
pAIArtSet->MatchingArtSet(specs, 1, set);
I'm looking forward for your help because you are my last resort !
Thanks in advance !
Sorry about the delay, been on vacation!
I've never seen any evidence that Illustrator creates stale or pale copies of artwork with ArtSets, so that shouldn't be the problem. How are you creating those buttons on the toolbar? Presumably you're using a 3rd party toolkit or an OS API to create the buttons?
If so, are you creating an ApplicationContext in your click handler? If not, you can get wierd results. I wouldn't have thought you'd see something like this, but it's possible that without you'd getting a strange transaction merge happening or something like that. If you're not using a context, add one (you don't need to call anything, just create it) and that should be enough. That might solve your problem.
First of all, thanks for you answer !
Concerning the ApplicationContext, I'm indeed using the PushAppContext/PopAppContenxt methods in my click handler :
I find this problem quite strange, my boss suggested me to use a "get element by name" type of oject retrieval, but I don't really like this approach.
Maybe I have some nested Push/Pop AppContext somewhere, do you know if that could be an issue?
Nested contexts shouldn't be bad, you just need to have at least one somewhere or you get strange results -- hence that being my (almost always!) first suggestion. It sounds like you're fine though (you're doing it for all buttons presumably), so it's not that.
Re-reading your original post, I think I have an idea though. You mention that the art handle isn't the same when you read the dictionary as it is when you write out the dictionary. I'm about 99% sure you're not reading the dictionary of the same object you write to.
Handles in AI don't actually change. There are a few odd exceptions to that, but by & large they don't change. That's not to say you should depend on it 100%, because as I said, there are some exceptions, but if you're selecting art, clicking your button, then clicking the other button and you haven't done anything else, I'm very confident you're not talking to the same art object. A simple test is to get the AIArtType (AIArtSuite::GetArtType) of both handles before you try and access the dictionary. That might reveal a difference. You're using two different methods to get a list of art in the document and I'm not even sure I'd trust the same method to necessarily return the art in the same order if invoked twice (probably it would, but I won't assume that). My guess is you're *probably* getting the layer's group art in the Get Data click, but it could be something else. Even an empty document has at least one art object because a document must have at least one layer & that layer is represented in the art tree by a group.