Programmatically Adding Profiles to Document Trees

Discussions concerning general integration topics.

Moderator: Phil Barton

Post Reply
timothymeyer16
Posts: 11
Joined: Mon Jun 14, 2021 9:47 am

Programmatically Adding Profiles to Document Trees

Post by timothymeyer16 » Tue Sep 14, 2021 2:35 pm

Good Afternoon,

I'm working on a script to clean up our document tree profiles.

The code below shows how I am able to pull the profiles associated to an IDocumentTree item.

However, I can not seem to set or add or remove profiles to said IDocumentTree instance.

Is this possible?

Code: Select all

foreach (IDocumentTreeInfo treeInfo in DocumentManager.DocumentTrees)
                {

                    IDocumentTree documentTree = DocumentManager.GetDocumentTree(treeInfo);
                    Console.WriteLine(treeInfo.Name);
                    foreach (IProfileInfo profile in documentTree.Profiles)
                    {
                        Console.WriteLine(profile);
                    }
                    Console.ReadLine();

                }

BobRichards
Posts: 1116
Joined: Wed Jan 15, 2014 3:50 pm
Location: Raleigh, NC
Contact:

Re: Programmatically Adding Profiles to Document Trees

Post by BobRichards » Sun Sep 19, 2021 2:10 pm

This is been passed to R&D. I will report any information when I get it.
Bob Richards, Senior Software Developer, SoftPro

timothymeyer16
Posts: 11
Joined: Mon Jun 14, 2021 9:47 am

Re: Programmatically Adding Profiles to Document Trees

Post by timothymeyer16 » Fri Sep 24, 2021 10:56 am

I was able to get something working - Essentially I just treated it like a list and then applied changes:

This is how I reset the profiles

Code: Select all

 IDocumentTree tree = DocumentManager.GetDocumentTree(treeInfo);
tree.Profiles.Clear();
DocumentManager.ApplyChanges(tree);

This is how I added a profile

Code: Select all

foreach (IProfileInfo profileinfo in selectProfiles)
{
	 IDocumentTree tree = DocumentManager.GetDocumentTree(treeInfo);
           if (!tree.Profiles.Contains(profileinfo))
            {
                   tree.Profiles.Add(profileinfo);
                   DocumentManager.ApplyChanges(tree);
             }
}

BobRichards
Posts: 1116
Joined: Wed Jan 15, 2014 3:50 pm
Location: Raleigh, NC
Contact:

Re: Programmatically Adding Profiles to Document Trees

Post by BobRichards » Tue Sep 28, 2021 5:35 pm

I'm glad you figured it out and posted an answer for others that run into this problem. :D

Also I'm sorry that I could not help in a timely fashion.
Bob Richards, Senior Software Developer, SoftPro

Post Reply