Skip to main content
Participant
Jun 16, 2025 10:18 AM UTC
Answered

InDesign C++ SDK: How to Programmatically Create or Resize Primary Text Frame?

I’m currently working on a project that involves programmatically resizing the primary text frame in Adobe InDesign, and in some cases, creating one if it doesn’t already exist. I’ve reviewed the InDesign C++ SDK documentation, but I haven’t found any clear guidance or relevant interfaces that address how to create or resize the primary text frame using the SDK.

 

Could someone please clarify:

  • Is it possible to programmatically create or resize the primary text frame using the InDesign C++ SDK?
  • If so, which interfaces and methods should be used to accomplish this?

Any examples, pointers, or references to relevant SDK classes or sample code would be greatly appreciated.

 

Thank you!

Manan JoshiCorrect answer
Community Expert
Jun 17, 2025 7:45 AM UTC

You can use the kSetPrimaryTextFlowCmdBoss to make a textframe present on a parent page as primary textframe. The itemlist of this command would be set with the kMasterPagesBoss and the IFlowData interface needs to be set with the story ref. The following code should work

UIDRef GetStoryFromFrame(UIDRef& frameRef){
	UIDRef toReturn = UIDRef::gNull;
	do
	{
		if(frameRef == UIDRef::gNull)
			break;

		InterfacePtr<IGraphicFrameData> iGraphicFrameData(frameRef, UseDefaultIID());
		ASSERT(iGraphicFrameData);
		if(!iGraphicFrameData)
			break;

		InterfacePtr<IMultiColumnTextFrame> iMultiColumnTextFrame(frameRef.GetDataBase(),iGraphicFrameData->GetTextContentUID(), UseDefaultIID());
		ASSERT(iMultiColumnTextFrame);
		if(!iMultiColumnTextFrame)
			break;

		InterfacePtr<ITextModel> iTextModel(iMultiColumnTextFrame->QueryTextModel());
		ASSERT(iTextModel);
		if(!iTextModel)
			break;

		toReturn = ::GetUIDRef(iTextModel);
	}while(kFalse);
	return toReturn;
}

ErrorCode SetFramePrimaryTextFrame(UIDRef &frameRef){
	ErrorCode status = kFailure;
	do{
		if(frameRef == UIDRef::gNull)
			break;
		
		InterfacePtr<IHierarchy> iHierarchy(frameRef, UseDefaultIID());
		ASSERT(iHierarchy);
		if (!iHierarchy)
			break;

		InterfacePtr<ISpread> iSpread(Utils<IPasteboardUtils>()->QuerySpread(iHierarchy));
		ASSERT(iSpread);
		if (!iSpread)
			break;

		if(!Utils<ILayoutUtils>()->IsAMaster(::GetUID(iSpread), ::GetDataBase(iSpread)))
		   break;

		UIDRef storyRef = GetStoryFromFrame(frameRef);
		if(storyRef == UIDRef::gNull)
			break;

		InterfacePtr<ICommand> iCommand(CmdUtils::CreateCommand(kSetPrimaryTextFlowCmdBoss));
		ASSERT(iCommand);
		if (!iCommand)
			break;

		iCommand->SetItemList(::GetUIDRef(iSpread));
		InterfacePtr<IFlowData> iFlowData(iCommand, UseDefaultIID());
		ASSERT(iFlowData);
		if (!iFlowData)
			break;

		iFlowData->SetPrimaryTextFlowStory(storyRef.GetUID());
		CmdUtils::ProcessCommand(iCommand);
	}while(kFalse);
	return status;
}

-Manan

-Manan

1 reply

Manan JoshiCommunity ExpertCorrect answer
Community Expert
Jun 17, 2025 7:45 AM UTC

You can use the kSetPrimaryTextFlowCmdBoss to make a textframe present on a parent page as primary textframe. The itemlist of this command would be set with the kMasterPagesBoss and the IFlowData interface needs to be set with the story ref. The following code should work

UIDRef GetStoryFromFrame(UIDRef& frameRef){
	UIDRef toReturn = UIDRef::gNull;
	do
	{
		if(frameRef == UIDRef::gNull)
			break;

		InterfacePtr<IGraphicFrameData> iGraphicFrameData(frameRef, UseDefaultIID());
		ASSERT(iGraphicFrameData);
		if(!iGraphicFrameData)
			break;

		InterfacePtr<IMultiColumnTextFrame> iMultiColumnTextFrame(frameRef.GetDataBase(),iGraphicFrameData->GetTextContentUID(), UseDefaultIID());
		ASSERT(iMultiColumnTextFrame);
		if(!iMultiColumnTextFrame)
			break;

		InterfacePtr<ITextModel> iTextModel(iMultiColumnTextFrame->QueryTextModel());
		ASSERT(iTextModel);
		if(!iTextModel)
			break;

		toReturn = ::GetUIDRef(iTextModel);
	}while(kFalse);
	return toReturn;
}

ErrorCode SetFramePrimaryTextFrame(UIDRef &frameRef){
	ErrorCode status = kFailure;
	do{
		if(frameRef == UIDRef::gNull)
			break;
		
		InterfacePtr<IHierarchy> iHierarchy(frameRef, UseDefaultIID());
		ASSERT(iHierarchy);
		if (!iHierarchy)
			break;

		InterfacePtr<ISpread> iSpread(Utils<IPasteboardUtils>()->QuerySpread(iHierarchy));
		ASSERT(iSpread);
		if (!iSpread)
			break;

		if(!Utils<ILayoutUtils>()->IsAMaster(::GetUID(iSpread), ::GetDataBase(iSpread)))
		   break;

		UIDRef storyRef = GetStoryFromFrame(frameRef);
		if(storyRef == UIDRef::gNull)
			break;

		InterfacePtr<ICommand> iCommand(CmdUtils::CreateCommand(kSetPrimaryTextFlowCmdBoss));
		ASSERT(iCommand);
		if (!iCommand)
			break;

		iCommand->SetItemList(::GetUIDRef(iSpread));
		InterfacePtr<IFlowData> iFlowData(iCommand, UseDefaultIID());
		ASSERT(iFlowData);
		if (!iFlowData)
			break;

		iFlowData->SetPrimaryTextFlowStory(storyRef.GetUID());
		CmdUtils::ProcessCommand(iCommand);
	}while(kFalse);
	return status;
}

-Manan

Translate
-Manan