// add new property to existing category
        public InwOaPropertyVec AddNewPropertyToExtgCategory(InwGUIAttribute2 propertyCategory)
        {
            // COM state (document)
            InwOpState10 cdoc = ComApiBridge.State;
            // a new propertycategory object
            InwOaPropertyVec category = (InwOaPropertyVec)cdoc.ObjectFactory(
                nwEObjectType.eObjectType_nwOaPropertyVec, null, null);

            // retrieve existing propertydata (name & value) and add to category
            foreach (InwOaProperty property in propertyCategory.Properties())
            {
                // create a new Property (PropertyData)
                InwOaProperty extgProp = (InwOaProperty)cdoc.ObjectFactory(nwEObjectType.eObjectType_nwOaProperty,
                                                                           null, null);
                // set PropertyName
                extgProp.name = property.name;
                // set PropertyDisplayName
                extgProp.UserName = property.UserName;
                // set PropertyValue
                extgProp.value = property.value;
                // add to category
                category.Properties().Add(extgProp);
            }

            // create a new PropertyData and add to category
            InwOaProperty newProp = (InwOaProperty)cdoc.ObjectFactory(nwEObjectType.eObjectType_nwOaProperty,
                                                                      null, null);

            newProp.name     = "2021Champions_Internal";
            newProp.UserName = "******";
            newProp.value    = "Who Knows!!";
            category.Properties().Add(newProp);
            return(category);
        }
        public override int Execute(params string[] parameters)
        {
            // current document (.NET)
            Document doc = Application.ActiveDocument;
            // current document (COM)
            InwOpState10 cdoc = ComApiBridge.State;
            // current selected items
            ModelItemCollection items = doc.CurrentSelection.SelectedItems;

            if (items.Count > 0)
            {
                // input dialog
                InputDialog dialog = new InputDialog();
                dialog.ShowDialog();
                foreach (ModelItem item in items)
                {
                    // convert ModelItem to COM Path
                    InwOaPath citem = (InwOaPath)ComApiBridge.ToInwOaPath(item);
                    // Get item's PropertyCategoryCollection
                    InwGUIPropertyNode2 cpropcates = (InwGUIPropertyNode2)cdoc.GetGUIPropertyNode(citem, true);
                    // create a new Category (PropertyDataCollection)
                    InwOaPropertyVec newcate = (InwOaPropertyVec)cdoc.ObjectFactory(nwEObjectType.eObjectType_nwOaPropertyVec, null, null);
                    // create a new Property (PropertyData)
                    InwOaProperty newprop = (InwOaProperty)cdoc.ObjectFactory(nwEObjectType.eObjectType_nwOaProperty, null, null);
                    // set PropertyName
                    newprop.name = dialog.PropertyName + "_InternalName";
                    // set PropertyDisplayName
                    newprop.UserName = dialog.PropertyName;
                    // set PropertyValue
                    newprop.value = dialog.PropertyValue;
                    // add PropertyData to Category
                    newcate.Properties().Add(newprop);
                    // add CategoryData to item's CategoryDataCollection
                    cpropcates.SetUserDefined(0, dialog.CategoryName, dialog.CategoryName + "_InternalName", newcate);
                }
            }
            return(0);
        }
Esempio n. 3
0
        private void lbTesteSelClash_MouseUp(object sender, MouseEventArgs e)
        {
            //var acd = NavisworksApp.ActiveDocument;
            //DocumentClash documentClash = acd.GetClash();
            //DocumentClashTests documentClashTests = documentClash.TestsData;
            //ClashTest clashTest = documentClashTests.Tests.First() as ClashTest;

            //var testesave = clashTest.Children;
            //List<ClashResult> clashResults = new List<ClashResult>();
            //foreach (var item in testesave)
            //{
            //    clashResults.Add(item as ClashResult);
            //}

            //if (clashResults.Count() > 0)
            //{
            //    var testeViewpoint = clashResults.First(x => x.DisplayName == "Clash3");
            //    ClashItem1 = new ModelItemCollection();
            //    ClashItem2 = new ModelItemCollection();
            //    ClashSelectionTransparent = new ModelItemCollection();
            //    ClashItem1.Add(testeViewpoint.Item1);
            //    ClashItem2.Add(testeViewpoint.Item2);
            //    acd.CurrentSelection.AddRange(ClashItem1);
            //    acd.CurrentSelection.AddRange(ClashItem2);
            //    ClashSelectionTransparent = acd.CurrentSelection.SelectedItems;
            //    acd.State.InvertSelection();
            //    SaveCurrentViewPointClash();

            //    //var testeData = teste.TestsData.Tests.FirstOrDefault();

            //    //if (testeData != null)
            //    //{
            //    //    var save = teste.TestsData;
            //    //    var testeSave = testeData as ClashTest;
            //    //    var listClahs = testeSave.Children.ToList();

            //    //    var ItemFirst = listClahs.First();


            //    //}
            //}

            InwOpState10 oState;

            oState = ComApiBridge.State;



            //find the clash detective plugin

            InwOpClashElement m_clash = null;



            foreach (InwBase oPlugin in oState.Plugins())

            {
                if (oPlugin.ObjectName == "nwOpClashElement")

                {
                    m_clash = (InwOpClashElement)oPlugin;

                    break;
                }
            }



            if (m_clash == null)

            {
                System.Windows.Forms.MessageBox.Show(

                    "cannot find clash test plugin!");

                return;
            }



            //Run all  clash test or specific clash

            //or assume the UI has the results already



            //m_clash.RunAllTests(null);



            // get the plug-in of exporting image

            InwOaPropertyVec options =

                oState.GetIOPluginOptions("lcodpimage");



            // set to the format to png

            foreach (InwOaProperty opt in options.Properties())

            {
                if (opt.name == "export.image.format")
                {
                    opt.value = "lcodpexpng";
                }
            }



            try

            {
                // get the first Test and its first clash result

                InwOclClashTest clashTest = m_clash.Tests()[1];

                InwOclTestResult clashResult = clashTest.results()[1];



                // create a temporary saved viewpoint

                InwOpView oSV =

                    oState.ObjectFactory(

                        nwEObjectType.eObjectType_nwOpView);

                oSV.name = "temp-view";

                oSV.anonview.ViewPoint = clashResult.GetSuitableViewPoint().Copy();

                oState.SavedViews().Add(oSV);



                // apply the temp saved viewpoint

                oState.ApplyView(oState.SavedViews().Last());



                // export it to an image

                //string tempFileName =

                //    "c:\\temp\\" +

                //    clashTest.name + "- " +

                //    clashResult.name + ".PNG";

                //oState.DriveIOPlugin(

                //    "lcodpimage",

                //    tempFileName,

                //    options);



                // delete the temp saved viewpoint

                oState.SavedViews().RemoveLast();
            }

            catch (Exception ex)

            {
                MessageBox.Show(ex.ToString());
            }
        }