Skip to main content
Legend
December 11, 2025
Answered

How do I get Menu path to a submenu using the C++ SDK?

  • December 11, 2025
  • 1 reply
  • 256 views

How do I get Menu path to a submenu using the C++ SDK?

I need to use it in IMenuCustomizationData::HideSubMenu(const PMString &menuPath).

 

In the script, you can retrieve menuItems and subMenus from the menu. How do you accomplish the same thing using the C++ SDK?

Correct answer 琥珀 猫太郎

So there are also things like IExtendScriptUtils and IUxpScriptUtils.

Utils<IUxpScriptUtils>()->RunScriptInEngine(
    "MyUXP", // engineName
    "let { app } = require(\"indesign\");\n"
    "let myDocument = app.documents.add();"
);

Utils<IUxpScriptUtils>()->DeleteUxpScriptEngine("MyUXP");

 

This one is easier.

1 reply

Legend
December 11, 2025

When a new version comes along with many changes I run a menu filter and action filter that log their input to a file for further reference. Never needed it dynamically, looking at IMenuMgr that is a bit thin indeed. If other interfaces fail, you already mentioned scripts, e.g. learn how to build and execute a script request. Sometimes it also helps to know your tools such as debugger, instruments, activity viewer.

 

Legend
December 11, 2025

Thank you very much. That was very helpful.

I counted the number of MenuItems in the script and obtained that value.

do
{
	InterfacePtr<IScriptManager> iScriptManager(
		Utils<IScriptUtils>()->QueryScriptManager(kJavaScriptMgrBoss)
	);
	if (iScriptManager == nil) break;

	InterfacePtr<IScriptEngine> iScriptEngine(
		iScriptManager->QueryDefaultEngine()
	);
	if (iScriptEngine == nil) break;

	InterfacePtr<IScriptRunner> iScriptRunner(iScriptEngine, UseDefaultIID());
	if (iScriptRunner == nil) break;

	// Dispatch a script.
	ScriptData scriptData_script("app.menus.item(95).menuItems.count();");
	ScriptRecordData scriptRecordData_arguments;
	ScriptData scriptData_return;
	PMString pMString_errorString;
	Utils<IScriptUtils>()->DispatchScriptRunner(
		iScriptRunner, // scriptRunner
		scriptData_script, // script
		scriptRecordData_arguments, // arguments
		scriptData_return, // result
		pMString_errorString, // errorString
		kTrue // showErrorAlert,
	);

	int32 int32_countNum;
	scriptData_return.GetInt32(&int32_countNum);

	PMString pMString_result;
	pMString_result.AsNumber(int32_countNum);

	CAlert::InformationAlert(pMString_result);

	// When a return value is not required.
	RunScriptParams runScriptParams(iScriptRunner);
	ErrorCode errorCode = iScriptRunner->RunScript(
		"alert('test');", runScriptParams
	);

} while (false);

 

琥珀 猫太郎AuthorCorrect answer
Legend
December 14, 2025

So there are also things like IExtendScriptUtils and IUxpScriptUtils.

Utils<IUxpScriptUtils>()->RunScriptInEngine(
    "MyUXP", // engineName
    "let { app } = require(\"indesign\");\n"
    "let myDocument = app.documents.add();"
);

Utils<IUxpScriptUtils>()->DeleteUxpScriptEngine("MyUXP");

 

This one is easier.