Page 1 of 1

Programmatically Adding Profiles to Document Trees

Posted: Tue Sep 14, 2021 2:35 pm
by timothymeyer16
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();

                }

Re: Programmatically Adding Profiles to Document Trees

Posted: Sun Sep 19, 2021 2:10 pm
by BobRichards
This is been passed to R&D. I will report any information when I get it.

Re: Programmatically Adding Profiles to Document Trees

Posted: Fri Sep 24, 2021 10:56 am
by timothymeyer16
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);
             }
}

Re: Programmatically Adding Profiles to Document Trees

Posted: Tue Sep 28, 2021 5:35 pm
by BobRichards
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.