Ok, it's done!
1. read the APJ file and print the result in a text box:
MyCommands.cs
public static string GetDetailValue(int _prop, int _pair)
{
ProjectBaseManager projectManager = ProjectBaseServices.Service.ProjectManager;
Project activeProj = projectManager.OpenProject(OpenMode.ForRead, projectManager.CurrentProjectFileName.Path);
ProjectStringProperty stringProp = (ProjectStringProperty)activeProj.Configuration.StringProperties[_prop];
StringPair strPair = (StringPair)stringProp.StringPairs[_pair];
return strPair.Right;
}
Palette.Designer.cs
// textBox_0_1
...
this.textBox_0_1.Name = "textBox_0_1";
this.textBox_0_1.Text = MyCommands.GetDetailValue(0,1);
2. Saving the changes to APJ file:
MyCommands.cs:
public static void SetDetailValue(int _prop, int _pair, string _right)
{
ProjectBaseManager projectManager = ProjectBaseServices.Service.ProjectManager;
Project activeProj = projectManager.OpenProject(OpenMode.ForRead, projectManager.CurrentProjectFileName.Path);
projectManager.UpgradeOpen(activeProj);
ProjectStringProperty stringProp = (ProjectStringProperty)activeProj.Configuration.StringProperties[_prop];
StringPair strPair = (StringPair)stringProp.StringPairs[_pair];
string _left = strPair.Left;
StringPair newPair = new StringPair(_left, _right);
stringProp.StringPairs.RemoveAt(_pair);
stringProp.StringPairs.Insert(_pair, newPair);
if (activeProj.IsUpdateProjectFileNeeded)
{
ProjectFile prjFile = new ProjectFile(activeProj);
prjFile.DrawingFullPath = ProjectBaseServices.Service.ProjectManager.CurrentProjectFileName.Path;
bool b = activeProj.UpdateFile(prjFile);
activeProj.UpdateProjectInformationInDwg(prjFile);
}
bool isGoodSave = projectManager.SaveProject(activeProj);
projectManager.DowngradeOpen(activeProj);
}
Palette.Designer.cs
// textBox_0_1
...
this.textBox_0_1.LostFocus += new System.EventHandler(this.textBox_0_1_TextLostFocus);
Palette.cs
private void textBox_0_1_TextLostFocus(object sender, System.EventArgs e)
{
string _value = textBox_0_1.Text;
MyCommands.SetDetailValue(0,1,_value);
}