Edit APJ details (Autocad Arch.) in a new palette

Edit APJ details (Autocad Arch.) in a new palette

faugustom
Advocate Advocate
1,233 Views
8 Replies
Message 1 of 9

Edit APJ details (Autocad Arch.) in a new palette

faugustom
Advocate
Advocate

Hi all;

 

I'm new in programming; know only the very basics;

My goal is to edit the project details in AutoCAD Architecture using a tool palette;
Form my little knowledge, I have an empty palette set with this files;

- MyPaletteSet.cs;
- MyCommands.cs;

My questions are:
- How and where to load the apj file;
- How to show a especifique detail, like this:

	<Details Name="Obra">
		<Entry Name="Data" Value="01/01/2023"/>
	</Details>

in a textbox field, then change it and save back to APJ file;

@Ed__Jobe, I was asking in the AUGI forum (https://forums.augi.com/showthread.php?67326-ACA-2008-Project-Details&p=1354550#post1354550); It would be a similar program, but running on the palette;

 

Thanks'

0 Likes
Accepted solutions (1)
1,234 Views
8 Replies
Replies (8)
Message 2 of 9

Ed__Jobe
Mentor
Mentor

If i remember right, the apj file is just an xml file with the extension renamed. You would need an api for the project similar to the SheetSet api. I haven't used ACA for years, and I don't have it installed so I can't tell you if an api is available. But since it's an xml, you could create your own api to read/write the apj. I think that ACA installs some dll's and COM type libraries, so you could look there for an apj api.

Ed


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
How to post your code.

EESignature

0 Likes
Message 3 of 9

Gepaha
Collaborator
Collaborator

Add reference to "C:\Program Files\Autodesk\AutoCAD xxxx\ACA\AecProjectBaseMgd.dll".
using Autodesk.Aec.Project;

Example in "C:\Program Files\Autodesk\AutoCAD xxxx\Sample\CS.NET\AecProjectBaseSampleMgd".

 

This is old so it may have changed:

  • Autodesk.Aec.Project – The main project class.
  • Autodesk.Aec.ProjectBaseManager – The system wide Project Manager. This contains many utility methods to manipulate projects.
  • Autodesk.Aec.ProjectBaseServices – A helper class used to obtain the single ProjectBaseManager object.
  • Autodesk.Aec.ProjectConfiguration – Contains information about the project (such as the name, description, and number).

UI Interaction from API requires the use of commands:

  • _AecProjectNavigator – This a documented command that will display the project navigator palette. If there is no “current” project, the command will also run the Project Browser dialog.
  • _AecRefreshProject – This refreshes mainly the palette. Note that the API has a different method to reload a project, but is different than this command. This command does the same as the refresh project button on the palette.
  • _AecSetCurrentProject – This is currently the only way to properly set a project as current from the API.
  • _AecCloseProjectNavigator – Closes the project navigator palette. Note it only closes the dialog and the same project is still open and current.
  • _AecProjectNavigatorToggle – Simply toggles the project navigator palette on or off.

 

0 Likes
Message 4 of 9

faugustom
Advocate
Advocate

Some progress...

 

Using this code from another thread, I can read the first details of the firt section:

 

        public static string GetDetailValue()
        {
            ProjectBaseManager projectManager = ProjectBaseServices.Service.ProjectManager;
            ProjectFileName projectFileName = projectManager.CurrentProjectFileName;
            Project activeProj = projectManager.OpenProject(OpenMode.ForRead, projectManager.CurrentProjectFileName.Path);

            string returnValue = string.Empty;

            foreach (ProjectStringProperty stringProp in activeProj.Configuration.StringProperties)
            {
                string a = stringProp.Name;

                foreach (StringPair strpair in stringProp.StringPairs)
                {
                    string b = strpair.Left;
                    string c = strpair.Right;

                    returnValue = String.Concat(a, b, c);

                    return returnValue;
                }

                return returnValue;
            }

            return returnValue;
        }

 

The foreach functions weall, but I want to access each item individually;

Somehow, I have to access the ProjectStringProperty from activeProj.Configuration.StringProperties, an then strpair from stringPair... but I didn't discovered how it is indexed...

 

 

 

 

0 Likes
Message 5 of 9

Ed__Jobe
Mentor
Mentor

Download Notepad++  and open the apj file and select xml as the format. Then you can read the sections.

Ed


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
How to post your code.

EESignature

0 Likes
Message 6 of 9

Gepaha
Collaborator
Collaborator

Analyzing the code you go through only one loop. Use "return returnValue;" only at the end.

 

public static void ListProjectDetails()
{
    Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
    ProjectBaseManager projectManager = ProjectBaseServices.Service.ProjectManager;
    Project activeProj = projectManager.OpenProject(OpenMode.ForRead, projectManager.CurrentProjectFileName.Path);

    foreach (ProjectStringProperty stringProp in activeProj.Configuration.StringProperties)
    {
       foreach (StringPair strpair in stringProp.StringPairs)
       {                    
          ed.WriteMessage($"\nName: {stringProp.Name}, Left: {strpair.Left}, Right: {strpair.Right}");
       }                
    }           
}

 

 

gphanauer_1-1688056757448.png

 

gphanauer_2-1688056812484.png

 

gphanauer_3-1688057189265.png

Message 7 of 9

faugustom
Advocate
Advocate

Ok, now I'm able to read the details contents by their index (inside []):

        public static string GetDetailValue()
        {
            ProjectBaseManager projectManager = ProjectBaseServices.Service.ProjectManager;
            ProjectFileName projectFileName = projectManager.CurrentProjectFileName;
            Project activeProj = projectManager.OpenProject(OpenMode.ForRead, projectManager.CurrentProjectFileName.Path);
            ProjectStringProperty stringProp = (ProjectStringProperty)activeProj.Configuration.StringProperties[0];
            StringPair strpair = (StringPair)stringProp.StringPairs[1];
                string a = stringProp.Name;
                string b = strpair.Left;
                string c = strpair.Right;
                            
                return String.Concat(a, b, c);
        }

 

Next steps are: 
- put this values in a text field;
- save back the changes made in the palette;

 

 

 

 

0 Likes
Message 8 of 9

faugustom
Advocate
Advocate

Ok, text box done; showing correct value:

Captura de Tela (629).png

 

 

 

 

 

* the label texts will be hardcoded, I don't need to edit then;

 

code for now, using only right side of the detail:

        public static string GetDetailValue(int _prop,int _pair)
        {
            ProjectBaseManager projectManager = ProjectBaseServices.Service.ProjectManager;
            ProjectFileName projectFileName = projectManager.CurrentProjectFileName;
            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;
        }

 

Next step, save back changes in the text field 😅

0 Likes
Message 9 of 9

faugustom
Advocate
Advocate
Accepted solution

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);
        }
0 Likes