.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

saving changes to a "Project" not reflected in apj

2 REPLIES 2
SOLVED
Reply
Message 1 of 3
gpuerini
409 Views, 2 Replies

saving changes to a "Project" not reflected in apj

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;
}

 

Tags (1)
2 REPLIES 2
Message 2 of 3
gpuerini
in reply to: gpuerini

ok...I was missing an obvious command.

fyi.. here's how i fixed it.

 

  • open the project in read mode (does not work if opened dorectly in write)
      Project activeProj = projectManager.OpenProject(OpenMode.ForRead, projectManager.CurrentProjectFileName.Path); 

  • before making change, upgrade to write:
    projectManager.UpgradeOpen(activeProj);

  • make change to project
     
  • save project (this is was the commnad I was looking for!!)
    bool isGoodSave = projectManager.SaveProject(activeProj);

  • downgrade to readonly
    projectManager.DowngradeOpen(activeProj);

(do I need to dispose active proj? )

-GP

Message 3 of 3
faugustom
in reply to: gpuerini

Hi @gpuerini

 

 

I'm new in programing, but would like to implement a palette to manipulate the APJ file;
For now, I have a custom empty tool palette... 
Did you get any further with this solution? Could you give me some directions?

 

Thanks'!

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost