Ok.. I feel I'm missing something really basic hear, but I'm just spinning my wheels! Any help would be appreciated?!
I'm trying manipulate the AutoCAD Architecture project information. i'm able to do it succesfully, in memory, by I cannot seem to get it to save it back to the apj file.
I am working with AutoCAD Architecture 2015 x64.
I'm guessing I should be using the Project.UpdateFile(ProjectFile) tool?
The problem, I think is I cannot find a way of getting the correct ProjectFile for the apj file, if it is even intended to be used this way?
Below is a sample of my code. No error happen, just.. the data is not saved.
Any helps, or pointers to more information would be helpful!
ps. also the "ForRead" "ForWrite" does not work as expected
If i have it as ForWrite.. it seems to stay locked open and I cannot see access the properties in Project Navigator
public static string GetDetailValueFromActiveAPJ(string sectionStringToBeAddedIn)
{
ProjectBaseManager projectManager = ProjectBaseServices.Service.ProjectManager;
ProjectFileName projectFileName = projectManager.CurrentProjectFileName;
Project activeProj = projectManager.OpenProject(OpenMode.ForRead, projectFileName.Path);
// this seems to need to be set to "read" even when writting? bug in AutoCAD api?
Project activeProj = GetProjectClass();
bool isWriteEnabled = activeProj.IsWriteEnabled; \\ this is true even though it is opened as ForRead
string returnValue = string.Empty;
foreach (ProjectStringProperty stringProp in activeProj.Configuration.StringProperties)
{
if (stringProp.Name.Equals(sectionStringToBeAddedIn))
{
StringPair newPair = new StringPair("testA", "testB");
stringProp.StringPairs.Add(newPair);
if(activeProj.IsUpdateProjectFileNeeded) // this is always true
{
ProjectFile prjFile = new ProjectFile(activeProj);
prjFile.DrawingFullPath = ProjectBaseServices.Service.ProjectManager.CurrentProjectFileName.Path;
bool b = activeProj.UpdateFile(prjFile); //return true
activeProj.UpdateProjectInformationInDwg(prjFile);
}
}
activeProj.Close(); \\\when I try to close this, I get a crash, probably because the Project File is not right.
activeProj.Dispose();
return returnValue;
}
Solved! Go to Solution.
Solved by gpuerini. Go to Solution.
ok...I was missing an obvious command.
fyi.. here's how i fixed it.
(do I need to dispose active proj? )
-GP