Hello
I have a plugin that replaces images in an indeisgn document. When a user has selected to show one object layer in a psd but not another layer, Indesign looses this information when I replace the old image.
I can store the layers that are visisble before I replace the image, but I have not been able to change the visibility of tha layers back in a correct way.
When the image is replaced, all the layers becomes visible, but if I open the "Object layers options" dialog, only the layers I want to be visible is marked as visible in the list. What I see in the dialog does not correspond with what is shown on the screen.
I use the folowing code to store info about the visible layers:
K2Vector<int32> PnlTrvUtils::GetGraphicLayer(UIDRef imageRef) {
ErrorCode result;
K2Vector<int32> visibleLayers;
InterfacePtr<IGraphicLayerInfo> iGraphicLayerInfo(imageRef,IID_IGRAPHICLAYERINFO);
if ( iGraphicLayerInfo != 0 ) {
if ( ! iGraphicLayerInfo->GetIsInitialized() ) {
InterfacePtr<ICommand> iInitializeGraphicLayersCmd(CmdUtils::CreateCommand( kInitializeGraphicLayersCmdBoss ));
if ( ! iInitializeGraphicLayersCmd ) {
result = kFailure;
} else {
iInitializeGraphicLayersCmd->SetItemList( UIDList( imageRef ));
result = CmdUtils::ProcessCommand( iInitializeGraphicLayersCmd );
if ( result == kSuccess )
if ( ! iGraphicLayerInfo->GetIsInitialized() )
result = kFailure;
}
}
int32 i;
int32 iLayerCount = iGraphicLayerInfo->GetNumberLayers();
for ( i = 0; i < iLayerCount; i++ ) {
if (IGraphicLayerInfo::kVisibilityShowing ==iGraphicLayerInfo->GetNthLayerCurrentVisibility(i)) {
// CAlert::ErrorAlert("visible");
visibleLayers.push_back(i);
}
}
}
return visibleLayers;
}
And I use the folowing code to select the layers I want to be visisble:
void PnlTrvUtils::SetVisibleGraphicLayer(UIDRef imageRef, K2Vector<int32> visibleLayers) {
ErrorCode result;
InterfacePtr<IGraphicLayerInfo> iGraphicLayerInfo(imageRef,IID_IGRAPHICLAYERINFO);
if ( iGraphicLayerInfo != 0 ) {
if ( ! iGraphicLayerInfo->GetIsInitialized() ) {
InterfacePtr<ICommand> iInitializeGraphicLayersCmd(CmdUtils::CreateCommand( kInitializeGraphicLayersCmdBoss ));
if ( ! iInitializeGraphicLayersCmd ) {
result = kFailure;
} else {
iInitializeGraphicLayersCmd->SetItemList( UIDList( imageRef ));
result = CmdUtils::ProcessCommand( iInitializeGraphicLayersCmd );
if ( result == kSuccess )
if ( ! iGraphicLayerInfo->GetIsInitialized() )
result = kFailure;
}
}
InterfacePtr<ICommand> setLayerCmd(CmdUtils::CreateCommand(kSetGraphicLayerInfoCmdBoss));
if (setLayerCmd) {
setLayerCmd->SetItemList(UIDList(imageRef));
InterfacePtr<IGraphicLayerInfo> setLayerCmdLayerInfo(setLayerCmd, UseDefaultIID());
// copy over the new settings
setLayerCmdLayerInfo->Copy(iGraphicLayerInfo);
int32 i;
InterfacePtr<IGraphicLayerInfo> resetLayerInfo(setLayerCmdLayerInfo,IID_IGRAPHICLAYERINFO);
if (resetLayerInfo) {
int32 iLayerCount = resetLayerInfo->GetNumberLayers();
for ( i = 0; i < iLayerCount; i++ ) {
bool16 visible = false;
for(int32 j = 0; j < visibleLayers.size(); j ++) {
if (i == visibleLayers[j]) {
visible = true;
}
}
if (visible) {
resetLayerInfo->SetNthLayerCurrentVisibility(i, IGraphicLayerInfo::kVisibilityShowing);
} else {
resetLayerInfo->SetNthLayerCurrentVisibility(i, IGraphicLayerInfo::kVisibilityHidden);
}
}
// clear out the flag
int32 currFlags = static_cast<int32>(setLayerCmdLayerInfo->GetGraphicLayerFlags());
currFlags &= ~IGraphicLayerInfo::kValidationFailed;
setLayerCmdLayerInfo->SetGraphicLayerFlags(static_cast<IGraphicLayerInfo::GraphicLayerFla gs>(currFlags));
// process the command
CmdUtils::ProcessCommand(setLayerCmd);
}
}
}
}