Community
Navisworks API
Welcome to Autodesk’s Navisworks API Forums. Share your knowledge, ask questions, and explore popular Navisworks API topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Adding a comment to a Clash result through C# API

2 REPLIES 2
SOLVED
Reply
Message 1 of 3
airpro_chris
1895 Views, 2 Replies

Adding a comment to a Clash result through C# API

Hey all, has anyone managed to add a comment to a clash result item through the NW2014 API (C#)? I have dropped a sample of my code in below. A short explanation as follows

1. The function accepts a Dictionary object containing strings for Result name(key) and the comment text(value).

2. The clash result names are unique so these are used to find a match for comments in the incoming dictionary.

3. When a name match is found a comment is added to the result item. The code seems to be failing in creating the comment and unfortunatley the API help file for comments gives an example for getting the centre point of a selected object (a little hint here ADesk..)

 

Any help much appreciated.

 

Cheers,

Chris

 

        static public void WriteComments(Dictionary<string,string> dictComments)
        {
            Document oDoc = Autodesk.Navisworks.Api.Application.ActiveDocument;
            if (oDoc == null || oDoc.IsClear)
                return;
            DocumentClash oDC = oDoc.GetClash();
            DocumentClashTests oDCT = oDC.TestsData;
            if (oDC == null || oDCT == null)
                return;
            string strResultName;
            string strCommentNew;
            foreach (ClashTest oClashTest in oDCT.Tests)
            {
                foreach (IClashResult oIClashResult in oClashTest.Children)
                {                
                    ClashResultGroup oClashResultGroup = oIClashResult as ClashResultGroup;
                    if (null != oClashResultGroup)
                    {
                        foreach (IClashResult oIResult in oClashResultGroup.Children)
                        {
                            ClashResult oResult = oIResult as ClashResult;
                            if (null != oResult)
                            {
                                strResultName = oResult.DisplayName.ToString();
                                if(dictComments.TryGetValue(strResultName, out strCommentNew))
                                {
                                    Comment oComment = new Comment("A comment found",CommentStatus.Active,"AB");
                                    //oResult.Comments.Insert(0, oComment);
                                    oResult.Comments.Add(oComment);
                                }
                            }                           
                        }
                    }
                }

            }
        }

 

2 REPLIES 2
Message 2 of 3
susan_tate
in reply to: airpro_chris

Hi Chris,

 

Is the code failing when you actually try to add the comment to collection? I think it is because you can't edit the comment collection directly. You can make a copy of the comment collection, add your new comment, and then call the method to replace the comment collection for the specified result:

 

CommentCollection copy = new CommentCollection();
copy.CopyFrom(oResult.Comments);

copy.Add(oComment);

oDCT.TestsEditResultComments(oResult, copy);

 

Does that work for you?

 

Regards, Susan

 

 

 

 

 

 



Susan Tate

Principal Engineer

Message 3 of 3
airpro_chris
in reply to: susan_tate

@susan_tate, thanks for quick response on this. Solution works well and I should have investigated this one. It seems like comments follow a similar stucture to SavedViewPoints in this respect.

 

Thanks again,

Chris.

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

Post to forums  

Rail Community


 

Autodesk Design & Make Report