Esempio n. 1
0
 public NavisGeometry()
 {
     // Add Selected Items to oModelColl Property
     oModelColl = NavisApplication.ActiveDocument.CurrentSelection.SelectedItems;
     //convert to COM selection
     oSel = ComBridge.ToInwOpSelection(oModelColl);
 }
Esempio n. 2
0
        GetSortedFragments(ModelItemCollection modelItems)
        {
            ComApi.InwOpState     oState = ComBridge.State;
            ComApi.InwOpSelection oSel   = ComBridge.ToInwOpSelection(modelItems);

            // To be most efficient, you need to lookup an efficient
            // EqualityComparer for the int[] key

            var pathDict = new Dictionary <int[], Stack <ComApi.InwOaFragment3> >();

            foreach (ComApi.InwOaPath3 path in oSel.Paths())
            {
                // This yields ONLY unique fragments
                // ordered by geometry they belong to

                foreach (ComApi.InwOaFragment3 frag in path.Fragments())
                {
                    int[] pathArr = ((Array)frag.path.ArrayData).ToArray <int>();
                    if (!pathDict.TryGetValue(pathArr,
                                              out Stack <ComApi.InwOaFragment3> frags))
                    {
                        frags             = new Stack <ComApi.InwOaFragment3>();
                        pathDict[pathArr] = frags;
                    }
                    frags.Push(frag);
                }
            }
            return(pathDict);
        }
        public void ViewpointsCreation(out bool ClashTestsResultsExist)
        {
            InwOpGroupView TopGroup = null;

            ProjectionChange_Ort();
            ChangeModelColor();

            ClashTestsResultsExist = false;

            try
            {
                foreach (InwOclClashTest clashTest in m_clash.Tests())
                {
                    clashTest.status = nwEClashTestStatus.eClashTestStatus_OK;

                    if (clashTest.results().Count == 0)
                    {
                        continue;
                    }

                    ClashTestsResultsExist = true;

                    if (TopGroup == null)
                    {
                        TopGroup = TopGroupCreate();
                    }

                    InwOpGroupView SubGroup = SubGroupCreate(clashTest, TopGroup);

                    // get the first Test and its first clash result
                    foreach (InwOclTestResult clashResult in clashTest.results())
                    {
                        if (clashResult.status == nwETestResultStatus.eTestResultStatus_ACTIVE |
                            clashResult.status == nwETestResultStatus.eTestResultStatus_NEW)

                        {
                            ModelItem oItem1 = null;
                            ModelItem oItem2 = null;

                            //Get clashed items
                            oItem1 = ComApiBridge.ToModelItem(clashResult.Path1);
                            oItem2 = ComApiBridge.ToModelItem(clashResult.Path2);

                            //Put clashed items to model collection
                            ModelItemCollection ClashedItems = new ModelItemCollection
                            {
                                oItem1,
                                oItem2
                            };

                            //Overwrite items color
                            oDoc.Models.OverridePermanentColor(new ModelItem[1] {
                                ClashedItems.ElementAtOrDefault(0)
                            },
                                                               Autodesk.Navisworks.Api.Color.Red);
                            oDoc.Models.OverridePermanentColor(new ModelItem[1] {
                                ClashedItems.ElementAtOrDefault(1)
                            },
                                                               Autodesk.Navisworks.Api.Color.Green);

                            // Create a copy of current selection
                            ComApi.InwOpSelection ComClashSelection = ComApiBridge.ToInwOpSelection(ClashedItems);

                            // Create a new empty selection
                            InwOpSelection2 AllModel = oState.ObjectFactory(nwEObjectType.eObjectType_nwOpSelection, null, null) as InwOpSelection2;

                            // Get the new selection to contain the entire model
                            AllModel.SelectAll();

                            // Subtract the current selection, so it contains the unselected part of model
                            AllModel.SubtractContents(ComClashSelection);

                            // create a temporary saved viewpoint
                            InwOpView oSV = oState.ObjectFactory(nwEObjectType.eObjectType_nwOpView);

                            //Apply attributes
                            oSV.ApplyHideAttribs     = true;
                            oSV.ApplyMaterialAttribs = true;

                            oSV.name = clashResult.name;

                            //Get and save viewpoint
                            oSV.anonview.ViewPoint = clashResult.GetSuitableViewPoint().Copy();

                            SubGroup.SavedViews().Add(oSV);

                            oDoc.Models.OverridePermanentColor(new ModelItem[1] {
                                ClashedItems.ElementAtOrDefault(0)
                            },
                                                               Autodesk.Navisworks.Api.Color.FromByteRGB(63, 63, 63));
                            oDoc.Models.OverridePermanentColor(new ModelItem[1] {
                                ClashedItems.ElementAtOrDefault(1)
                            },
                                                               Autodesk.Navisworks.Api.Color.FromByteRGB(63, 63, 63));

                            oDoc.CurrentSelection.Clear();
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }

            if (TopGroup == null)
            {
                return;
            }

            oState.SavedViews().Add(TopGroup);
        }