Skip to main content
April 8, 2010
Question

How to update the document after deleting Layer

  • April 8, 2010
  • 2 replies
  • 809 views

Hi

I have a basic problem after deleting the layer

i am deleting the layer and saving the document using the below code

but the layers and the artwork for that layer still shows up in the Illustrator

if i close the document and open it back then i can see the changes on the document for the deleted layer

is there any way that i can refresh the document with out closing and opening it back?

sAILayers->GetNthLayer(1,&tempLayer);

error = sAILayers->DeleteLayer(tempLayer);

sAIDocumentList->Save(documentMain);

Thanks

Srinivas

Message was edited by: SriBSri

This topic has been closed for replies.

2 replies

Participant
April 15, 2010

Use RedrawDocument API of AIDocumentSuite

In a typical scenario,

sAIDocumentList->Save(document);                         // AIDocumentListSuite

sAIDocumentList->SetDocumentModified(false);

sAIDocument->RedrawDocument();                         // AIDocumentSuite

Let me know if it helps.

A. Patterson
Inspiring
April 8, 2010

Two things:

  1. Check that you got a non-NULL layer handle back from the first line. If its null, that's your problem (you're asking for a non-existant layer)
  2. Check error -- is kNoErr (0)? If not, it might give you a reason why its not deleting the layer.

There's no earthly reason why that code shouldn't work if the above check out. I do this all the time with similar code.

April 8, 2010

Thanks for the quick reply Patterson

as i said the layer is getting deleted but is not updating the document

if i close and open the document i can see the change that the layer got deleted

my requirement is delete the first layer on the save event (for sure i ll be having more than 2 layers)

Another Question

can we handle the save event, in the addNotifiers i add the after save event which will fire at the save event

now i would like to do some operations in the

AIErr goNotifier( AINotifierMessage *message ) {

}

if the logic in the goNotifier is correct then it should save the file

or else it should not save the file

is there any event that i can stop saving the ai file at that point?

Thanks

Srinivas

A. Patterson
Inspiring
April 8, 2010

For the layer deletion -- are you sure its actually saving then? You can check the error code from the Save call and double-check. If the layer is being deleted there's no reason I can think of why the save wouldn't pick that up -- as far as I know there's no synch call or anything required to make a subsequent document operation realize something has changed.

If all else fails, you could try a common kludge: use an AI timer. It could be that it doesn't like you doing a save in that context; in that case you could try creating a timer with a period of zero. That would cause it to immediately fire at its first opportunity, which I believe is "when everything else is done" (like maybe finalizing the layer deletion). Then you catch the timer event, kill the timer and do your save. That's clumsy, but it might work if you can't get anything else to do the trick.

For the save question, no, I don't think you can interrupt the save. I've never tried, but I don't think there's any mechanism like there is with, say, filters (where you can return kCancelErr or whatever the constant is to indicate the user stopped). The best you can probably do is indicate to the user that the save won't contain what they think it will contain -- you can do all this before a save, so it might let you warn them to hit cancel themselves, though I'm 100% sure it comes before the 'save' dialog (if there even is one).