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

How to get and set an object style to page item

Participant ,
Aug 01, 2023 Aug 01, 2023

Hi everyone,
I was autoflowing an overset page item programmatically, but noticed that autoflowing doesn't apply the ObjectStyle of the overset page item.
So I thought I'd iterate through all the boxes created by AutoFlow and give them an object name and style.
On the name no problem, but as regards the object style I have some problems.
I have no idea how to get and how to give a box an object style.

 

I've tried something like this, but was unsuccessful.

InterfacePtr<ICommand> applyObjectStyleCmd(CmdUtils::CreateCommand(kApplyObjectStyleCmdBoss));
        if(!applyObjectStyleCmd)
            break;
        applyObjectStyleCmd->SetItemList(listOfPageItemToApplyObjectStyle);

        InterfacePtr<IUIDData> UIDData(applyObjectStyleCmd, UseDefaultIID());
        if(!UIDData)
            break;
        UIDData->Set(DATABASE, UIDStyle);

        if(CmdUtils::ProcessCommand(applyObjectStyleCmd) != kSuccess)
            break;

listOfPageItemToApplyObjectStyle --> rapresent all the page item created by autoflow

UIDStyle --> rapresent the style that i want to appy to boxes, I set it simply by looking for it by name, but I would like the page item to be overset

 

Stefano

TOPICS
SDK
353
Translate
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

Participant , Aug 03, 2023 Aug 03, 2023

This is my solution:

Schermata 2023-08-03 alle 15.35.11.png

 

/// GET Object Style from pageItemA and SET to pageItemB
ErrorCode function(UIDRef pageItem_A, UIDRef pageItem_B)
{
    ErrorCode result = kFailure;
    
    do
    {
        // ----- GET OBJECT STYLE -----
        InterfacePtr<IGraphicFrameData> graphicFrameData_A(pageItem_A, UseDefaultIID());
        if(!graphicFrameData_A)
            break;
        
        /// UIDStyle Of pageItemA
        InterfacePtr<IPersistUIDData> persistUIDData(graphicFrameData_A, IID_IPERSISTOBJE
...
Translate
Participant ,
Aug 03, 2023 Aug 03, 2023

This is my solution:

Schermata 2023-08-03 alle 15.35.11.png

 

/// GET Object Style from pageItemA and SET to pageItemB
ErrorCode function(UIDRef pageItem_A, UIDRef pageItem_B)
{
    ErrorCode result = kFailure;
    
    do
    {
        // ----- GET OBJECT STYLE -----
        InterfacePtr<IGraphicFrameData> graphicFrameData_A(pageItem_A, UseDefaultIID());
        if(!graphicFrameData_A)
            break;
        
        /// UIDStyle Of pageItemA
        InterfacePtr<IPersistUIDData> persistUIDData(graphicFrameData_A, IID_IPERSISTOBJECTSTYLEDATA);
        if(!persistUIDData)
            break;
        
        UID UIDStyle = persistUIDData->GetUID();
        if(UIDStyle == kInvalidUID)
            break;
        
        
        
        // ----- SET OBJECT STYLE -----
        InterfacePtr<IGraphicFrameData> graphicFrameData_B(pageItem_B, UseDefaultIID());
        if(!graphicFrameData_B)
            break;
        
        /// UIDListOfPageItemToApplyObjStyle: List fill of UID of PageItem belonging to kSplineItemBoss, otherwise ApplyObjectStyleToUIDList don't apply the ObjectStyle
        UIDList UIDListOfPageItemToApplyObjStyle;
        UIDListOfPageItemToApplyObjStyle.push_back(GetUID(graphicFrameData_B));
        
        /// I haven't clue of how use categoriesToOverride, so i left it empty and it works anyway
        K2Vector<ClassID> categoriesToOverride;
        categoriesToOverride.push_back(kInvalidClass);
        result = Utils<Facade::IObjectStylesFacade>()->ApplyObjectStyleToUIDList(UIDListOfPageItemToApplyObjStyle, CONTEXT->GetContextWorkspace(), UIDStyle, categoriesToOverride, false);
        
    }while(false);
    
    return result;
}

 

If anyone has more elegant solutions feel free to share it.

Stefano

Translate
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
Participant ,
Aug 03, 2023 Aug 03, 2023
LATEST

edit

Translate
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