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

How to Read and Write Text Files Using the C++ SDK

Engaged ,
Dec 10, 2025 Dec 10, 2025

How to Read and Write Text Files Using the C++ SDK.

I also want to know how to obtain the path to the folder containing my own PlugIn.

TOPICS
SDK
242
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 2 Correct answers

Mentor , Dec 10, 2025 Dec 10, 2025

Have a look at IDFile, AFile and related cross platform file utils / helpers. For actual access open a termnal and type "man stdio", in other words that's territory of OS and C++ standard library. boost and ICU are also in the SDK, they may help to get beyond ASCII / latin encodings.

Translate
Mentor , Dec 16, 2025 Dec 16, 2025

Have a look at IPluginList::GetPathName if you still need your plugin path.

 

ScriptData knows how to pass an IDFile, and RunScriptParams knows how to pass a list of ScriptData. You'd then pick it up from "arguments" array, but beware - UXP chose a more convoluted way.

 

Not sure what you're doing with the stream, but in general separate execution paths for read + write can get avoided.

Translate
Mentor ,
Dec 10, 2025 Dec 10, 2025

Have a look at IDFile, AFile and related cross platform file utils / helpers. For actual access open a termnal and type "man stdio", in other words that's territory of OS and C++ standard library. boost and ICU are also in the SDK, they may help to get beyond ASCII / latin encodings.

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
Engaged ,
Dec 12, 2025 Dec 12, 2025

I tried various approaches.

// We cannot be held responsible for any problems that may occur.
// Please try it at your own risk.
do
{
	IDFile iDFile;
	// AppLocalCachedDataFolder
	if (FileUtils::GetAppLocalCachedDataFolder(
		&iDFile, PMString("MyPlugInCache.txt")) == kFalse) break;

	// Write
	InterfacePtr<IPMStream> iPMStream(StreamUtil::CreateFileStreamWrite(iDFile, kOpenOut | kOpenTrunc));

	// Read
	//InterfacePtr<IPMStream> iPMStream(StreamUtil::CreateFileStreamRead(iDFile));

	if (iPMStream == nil) break;

	std::vector<ActionID> vector_actionID;
	int32 int32_size = 0;
	if (iPMStream->IsWriting()) // Write
	{
		vector_actionID.push_back(273);
		vector_actionID.push_back(271);

		// Size must be specified
		for (ActionID actionID : vector_actionID)
		{
			int32_size++;
		}

		// Write size
		iPMStream->XferInt32(int32_size);

		// Write actionID
		for (ActionID actionID : vector_actionID)
		{
			iPMStream->XferID(actionID);
		}
	}
	else if (iPMStream->IsReading()) // Read
	{
		// Query size
		iPMStream->XferInt32(int32_size);

		// Read actionID
		for (int32 i = 0; i < int32_size; i++)
		{
			ActionID actionID;
			iPMStream->XferID(actionID);
			vector_actionID.push_back(actionID);
		}
	}

	// Check
	if (iPMStream->IsReading())
	{
		for (ActionID actionID : vector_actionID)
		{
			PMString num;
			num.AsNumber(actionID.Get());
			CAlert::InformationAlert(num);
		}
	}

	// Close
	iPMStream->Flush();
	iPMStream->Close();

	// Open folder
	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;

	PMString pMString_path;
	FileUtils::GetPathOnly(iDFile, pMString_path);

	RunScriptParams runScriptParams(iScriptRunner);
	ErrorCode errorCode = iScriptRunner->RunScript(
		"Folder(\""+ FileUtils::PMStringToFileURL(pMString_path) + "\").execute();"
		, runScriptParams
	);

} while (false);

 

I'm starting to think it might be easier to run the script from the C++ SDK and save it that way.

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
Mentor ,
Dec 16, 2025 Dec 16, 2025
LATEST

Have a look at IPluginList::GetPathName if you still need your plugin path.

 

ScriptData knows how to pass an IDFile, and RunScriptParams knows how to pass a list of ScriptData. You'd then pick it up from "arguments" array, but beware - UXP chose a more convoluted way.

 

Not sure what you're doing with the stream, but in general separate execution paths for read + write can get avoided.

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