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: 

Create Clash Test from Search

9 REPLIES 9
Reply
Message 1 of 10
Anonymous
2549 Views, 9 Replies

Create Clash Test from Search

I'm having the same problem as a recent post here trying to import a Clash Test XML using APIs.  Since they don't exist, I'm trying to create my clash test based on a couple of searchs that I add.  Here's my code:

            // Create 1st Selection Set
            Search p1st = new Search();
            p1st.SearchConditions.Add(
                new SearchCondition(
                    null,
                    new NamedConstant("LcOaNodeLayer", "Layer"),
                    SearchConditionOptions.IgnoreCategoryName | SearchConditionOptions.IgnorePropertyName,
                    SearchConditionComparison.DisplayStringContains,
                    VariantData.FromDisplayString("Layer1")
                    )
                );

            SavedItem p1stItem = new SelectionSet(p1st);
            p1stItem.DisplayName = "Layer1 Contents";
            Autodesk.Navisworks.Api.Application.ActiveDocument.SelectionSets.InsertCopy(0, p1stItem);

            // Create 2nd Selection Set
            Search p2nd = new Search();
            p2nd.SearchConditions.Add(
                new SearchCondition(
                    null,
                    new NamedConstant("LcOaNodeLayer", "Layer"),
                    SearchConditionOptions.IgnoreCategoryName | SearchConditionOptions.IgnorePropertyName,
                    SearchConditionComparison.DisplayStringContains,
                    VariantData.FromDisplayString("Layer2")
                    )
                );

            SavedItem p2ndItem = new SelectionSet(p2nd);
            p2ndItem.DisplayName = "Layer2 Contents";
            Autodesk.Navisworks.Api.Application.ActiveDocument.SelectionSets.InsertCopy(0, p2ndItem);

            // Create the Clash Test
            ClashTest pTest = new ClashTest();
            pTest.CustomTestName = "Layer1 against Layer2";
            pTest.DisplayName = pTest.CustomTestName;
            pTest.TestType = ClashTestType.Hard;
            pTest.Tolerance = 0;
            pTest.SelectionA.SelfIntersect = false;
            pTest.SelectionA.PrimitiveTypes = Autodesk.Navisworks.Api.PrimitiveTypes.Triangles;
            pTest.SelectionB.SelfIntersect = false;
            pTest.SelectionB.PrimitiveTypes = Autodesk.Navisworks.Api.PrimitiveTypes.Triangles;

            ModelItemCollection pSelA = new Autodesk.Navisworks.Api.ModelItemCollection();
            ModelItemCollection pSelB = new Autodesk.Navisworks.Api.ModelItemCollection();

            //******  How do I get my two Selections into this Clash Test?

            pClashTests.TestsAddCopy(pTest);

The part I can't figure out is how to use the Selections that I created with the two Layers in the Clash Test that I am trying to add.  Any help would be appreciated and please give a complete code example for the missing section in my snipet.

 

Thanks,

Joe

9 REPLIES 9
Message 2 of 10
Anonymous
in reply to: Anonymous

Should I open a DevHelp issue for this one?

Message 3 of 10
xiaodong_liang
in reply to: Anonymous

I am writing down what I have replied with Joe in other thread. for other's reference.

ClashTest.SelectionA and ClashTest.SelectionB are the properties to set the selection. The usage is

ClashTest.SelectionA.Selection.CopyFrom(your selection)

Please refer to this blog:
http://adndevblog.typepad.com/aec/2012/05/navisworks-net-api-2013-new-feature-clash-2.html
Selection.CopyFrom does not accept SelectionSet directly. You can find the overridden methods of CopyFrom that are available in API help.

So you will need to get the selection from SelectionSet. e.g.

if(selectionset.HasExplicitModelItems )
{
//get explicit selected items
ModelItemCollection oMC = selectionset.ExplicitModelItems ;
pTest.SelectionA.Selection.CopyFrom(oMC);
}

if(selectionset.HasSearch )
{
//get explicit selected items
ModelItemCollection oMC = selectionset.Search.FindAll();
pTest.SelectionA.Selection.CopyFrom(oMC);
}
Message 4 of 10
Anonymous
in reply to: xiaodong_liang

I've added the following:

 

            ModelItemCollection pSelA = p1st.FindAll(Autodesk.Navisworks.Api.Application.ActiveDocument, false);
            Selection pSel = new Selection(pSelA);
            pTest.SelectionA.Selection.CopyFrom(pSel);

            ModelItemCollection pSelB = p2nd.FindAll(Autodesk.Navisworks.Api.Application.ActiveDocument, false);
            pSel = new Selection(pSelB);
            pTest.SelectionB.Selection.CopyFrom(pSel);

This will Create the Clash Test but it's not creating it as a selection source ... it's creating it with explicit items.  I need to create it as a selection source.  I've poured through labs and docuementation but there is absolutely nothing on creating a Clash Test with two Selection Sources.  Please help!

 

Joe

Message 5 of 10
xiaodong_liang
in reply to: Anonymous

following up with the update on what I have replied with Joe:


If you set Try-Catch, you would find the exception indicates pTest is read-only. In Navisworks .NET API, the way to edit a object is through the corresponding edit methods, instead of editing the property directly. For some objects, it also needs to create a copy firstly, edit the property of the copy, and copy to the original object. So for your case, the working code should be:

 

 

Document oDoc = Autodesk.Navisworks.Api.Application.ActiveDocument;
foreach (SavedItem oSS in oDoc.SelectionSets.Value)
{ 
{
SelectionSet oSet = (SelectionSet)oSS;
if (oSet.HasExplicitModelItems)
{

}
if (oSet.HasSearch)
{
ModelItemCollection oMC = oSet.Search.FindAll(false);

Autodesk.Navisworks.Api.Clash.DocumentClash documentClash = oDoc.Clash as Autodesk.Navisworks.Api.Clash.DocumentClash;
Autodesk.Navisworks.Api.Clash.DocumentClashTests oDCT = documentClash.TestsData;
Autodesk.Navisworks.Api.Clash.ClashTest t = oDCT.Tests[0] as Autodesk.Navisworks.Api.Clash.ClashTest;
try
{
Autodesk.Navisworks.Api.Clash.ClashTest tcopy = t.CreateCopy() as Autodesk.Navisworks.Api.Clash.ClashTest;
tcopy.SelectionA.Selection.CopyFrom(oMC);
documentClash.TestsData.TestsEditTestFromCopy(t, tcopy);
}
catch(Exception e){

}
}

 

 

Message 6 of 10
Anonymous
in reply to: xiaodong_liang

Hi @xiaodong_liang ,

 

Thank you for the answer. I am after similar process, in fact I opened a new topic regarding with that (I did not find this conversation beforehand).

Please Click here for more info 

 

I understand I did similar approach as yourself. However I wonder if I understood correctly your post. Do you mean it is not possible to achieve the task via API? It is not possible to assign source explicit? and no matter what I do it will be appear in the nwf by elements in (standards selection in Navis)?

 

I personally do not mind as I can create a little code to do the process again and again to get all the object before start the process of clash detection, however if another user need to use the nwf the task will be complicate for that particular person.

 

Is there not workaround on that??

 

Thank you very much.

 

 

Message 7 of 10
nayer.girgis
in reply to: Anonymous

Hi @Anonymous /@xiaodong.liang 

 

I am also looking for exactly the same thing. Creating the clash tests based on search sets not by directly selecting the elements. Is there a solution for this or it is a limitation of the API?

 

Regards

 

Nayer

Message 8 of 10
CJModis
in reply to: Anonymous

var sourceCollectionA = new SelectionSourceCollection();
var sourceCollectionB = new SelectionSourceCollection();

foreach (var savedItem in doc.SelectionSets.Value)
{
    foreach (var selectionSet in GetSelectionSets(savedItem, group1.SearchSets.ToList()))
    {
        sourceCollectionA.Add(doc.SelectionSets.CreateSelectionSource(selectionSet));
    }

    foreach (var selectionSet in GetSelectionSets(savedItem, group2.SearchSets.ToList()))
    {
        sourceCollectionB.Add(doc.SelectionSets.CreateSelectionSource(selectionSet));
    }
}

clashTest.SelectionA.Selection.CopyFrom(sourceCollectionA);
clashTest.SelectionB.Selection.CopyFrom(sourceCollectionB);
Message 9 of 10
Ta7a
in reply to: CJModis

Hello

 

Where could i fount method : GetSelectionSets and also what is froup1 and group 2

 

Best Regards

Message 10 of 10
CJModis
in reply to: Ta7a

In this case you don't need this method. The main thing you need to understand is that you need SelectionSets. And where you will get them from is the task of your implementation according to your needs

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

Post to forums  

Rail Community


 

Autodesk Design & Make Report