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

IsMasterItemOverriddenOnPage always returns False

Explorer ,
Jan 19, 2024 Jan 19, 2024

Copy link to clipboard

Copied

Hello All, 

I am trying to identify overridden items on Master page, but IsMasterItemOverriddenOnPage always written false eventhough there present overridden items. 

in InDesign document we have 2 Master pages, say C, C2. C has 3 Items (text frames). C2 has parent C but in C2 we deleted those Items using shift + Command (local override).

I am loading list of items on C and checking if it is overridden on C2 using IsMasterItemOverriddenOnPage, but this always returns false. Can someone please help me with some inputs. 

 

{
    do
    {
        IDataBase *db = ::GetDataBase(iDocument);
        UIDList masterUIDs(db);
        
        InterfacePtr<IMasterSpreadList> masterSpreadList(iDocument, UseDefaultIID());
        if(masterSpreadList == nil)
            break;
        
        Utils<IMasterSpreadUtils>()->TopoSortMasterSpread(masterSpreadList, &masterUIDs);
        
//        for(int32 spreadIndex = 0;spreadIndex < masterSpreadList->GetMasterSpreadCount();++spreadIndex)
//            masterUIDs.Append(masterSpreadList->GetNthMasterSpreadUID(spreadIndex));
        
        UIDList unusedMasterUID    = Utils<IMasterSpreadUtils>()->GetUnusedMasterUIDs(iDocument);
        for (UIDList::iterator iter = unusedMasterUID.begin(); iter != unusedMasterUID.end(); ++iter)
        {
            if(masterUIDs.Contains(*iter))
                masterUIDs.Remove(masterUIDs.Location(*iter));
        }
        
        if(masterUIDs.IsEmpty())
            break;
        
        long size = masterUIDs.size();
        for(long i =0; i < size; i++)
        {
            UID master_page = masterUIDs.At(i);
            UIDList ancestors(db);
            Utils<IMasterSpreadUtils>()->GetAncestorsOf(masterSpreadList, master_page,&ancestors);
            long size_ancestors = ancestors.size();
            for(long j =0; j < size_ancestors; j++)
            {
                UID ancestor_page = ancestors.At(j);
                if(ancestor_page.Get() == master_page.Get())
                    continue;
                
                InterfacePtr<IHierarchy> masterSpreadHierarchy(db, ancestor_page, UseDefaultIID());
                if(!masterSpreadHierarchy)
                    continue;
                
                InterfacePtr<ISpread> iMasterSpread(masterSpreadHierarchy,UseDefaultIID());
                if(!iMasterSpread)
                    continue;
                
                for (int32 j = 0; j < iMasterSpread->GetNumPages() ; ++j)
                {
                    UIDList masterItemsUIDList(db);
                    iMasterSpread->GetItemsOnPage(j, &masterItemsUIDList, kFalse,kFalse, kFalse);
                    
                    for(UIDList::iterator masterItemUIDIter = masterItemsUIDList.begin(); masterItemUIDIter != masterItemsUIDList.end(); ++masterItemUIDIter)
                    {
                        InterfacePtr<IMasterOverrideable> masterOverrideable(db, *masterItemUIDIter, IID_IMASTEROVERRIDEABLE);
                        if(masterOverrideable && masterOverrideable->IsMasterNotOverrideable())
                            masterOverrideable->Set(IMasterOverrideable::kMasterOverrideable);
                        
                        UIDRef masterItemUIDRef(db, *masterItemUIDIter);
                        
                        if(Utils<IMasterSpreadUtils>()->IsMasterItemOverriddenOnPage(masterItemUIDRef,UIDRef(db,master_page)) == false)
                        {
                            UIDRef overriddenItem;
                            Utils<IMasterSpreadUtils>()->OverrideMasterPageItem(masterItemUIDRef,UIDRef(db,master_page),ICommand::kRegularUndo,&overriddenItem);
                            if(overriddenItem)
                            {
                            }
                        }
                    }
                }
            }
        }
    }while(false);
}

 

TOPICS
SDK

Views

118

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

correct answers 1 Correct answer

Contributor , Jan 19, 2024 Jan 19, 2024

Hi @Chetan S ,

 

You should validate 2 things -

 

Firstly -  

Utils<IMasterSpreadUtils>()->TopoSortMasterSpread(masterSpreadList, &masterUIDs);

 

As per SDK Documentation -

 

"sort the specified IMasterSpreadList such that masters with other masters applied to them are later in the list than the masters they derive from (e.g. if 'B-Master' has 'C-Master' applied, and 'A-Master' and 'C-Master' have 'None' applied, the sorted order would be 'A-Master', 'C-Master', 'B-Master'.). Useful for duplicating a mas

...

Votes

Translate

Translate
Contributor ,
Jan 19, 2024 Jan 19, 2024

Copy link to clipboard

Copied

LATEST

Hi @Chetan S ,

 

You should validate 2 things -

 

Firstly -  

Utils<IMasterSpreadUtils>()->TopoSortMasterSpread(masterSpreadList, &masterUIDs);

 

As per SDK Documentation -

 

"sort the specified IMasterSpreadList such that masters with other masters applied to them are later in the list than the masters they derive from (e.g. if 'B-Master' has 'C-Master' applied, and 'A-Master' and 'C-Master' have 'None' applied, the sorted order would be 'A-Master', 'C-Master', 'B-Master'.). Useful for duplicating a master spread list to a new document.

Warning: I think the above comment is wrong. It seems that TopoSortMasterSpread sorts all the masters so that a given master in the list depends only on masters appearing later in the list. That is the root masters are sorted to the end of the list and the most dependent masters are sorted to the beginning."

 

Refer the Warning as mentioned in the SDK Documentation. It seems, it might be sorting otherway round i.e first "B-Master" and then "C-Master"...

I am not sure but this is what written in Documenation. You need to validate this.

 

To validate this, you can get the name of master spread check -

IMasterSpread->GetName and validate in which sequence you are getting the master page sorted.

 

Secondly -

 

Utils<IMasterSpreadUtils>()->IsMasterItemOverriddenOnPage(masterItemUIDRef, UIDRef(db, master_page))

 

Check second parameter "UIDRef(db, master_page") - You are passing UIDRef of MasterSpread and not the UIDRef of Master Page.

 

Refer ISpread->GetNthPageUID().

 

Hope this helps.

 

- Rahul Rastogi

Adobe InDesign SDK C++ Custom Plugin Architect

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