Пример #1
0
        public void HomeViewpoint_Set(out InwOpView oSV)
        //Get home viewpoint, reset appearences and set as current viewpoint
        {
            Document oDoc = Autodesk.Navisworks.Api.Application.ActiveDocument;

            //Reset appearences
            oDoc.Models.ResetAllPermanentMaterials();
            oDoc.Models.ResetAllHiddenToModelState();
            oDoc.SetGraduatedBackground(Autodesk.Navisworks.Api.Color.FromByteRGB(105, 140, 230),
                                        Autodesk.Navisworks.Api.Color.FromByteRGB(210, 240, 255));

            //Set properties for home view
            Viewpoint oVP = new Viewpoint
            {
                //Set quaternion for home view
                Rotation    = new Rotation3D(0.425, 0.176, 0.340, 0.821),
                Projection  = ViewpointProjection.Perspective,
                RenderStyle = ViewpointRenderStyle.Shaded
            };

            Autodesk.Navisworks.Api.Application.ActiveDocument.CurrentViewpoint.CopyFrom(oVP);


            // Get a hold of the state object (it is a singleton)
            InwOpState10 myState = ComApiBridge.State;

            //Set viewpoint to all model
            myState.ViewAll();

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

            //Set viewpoint
            oSV.anonview.ViewPoint = myState.CurrentView.ViewPoint.Copy();
        }
        // 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
            Document doc = Application.ActiveDocument;
            // COM state object
            InwOpState10 cdoc = ComApiBridge.State;
            // current selected items
            ModelItemCollection items = doc.CurrentSelection.SelectedItems;
            // convert ModelItem to COM Path
            InwOaPath citem = ComApiBridge.ToInwOaPath(items[0]);
            // Get item's PropertyCategoryCollection object
            InwGUIPropertyNode2 cpropcates = (InwGUIPropertyNode2)cdoc.GetGUIPropertyNode(citem, true);
            // Get PropertyCategoryCollection data
            InwGUIAttributesColl propCol = cpropcates.GUIAttributes();

            // loop propertycategory
            foreach (InwGUIAttribute2 i in propCol)
            {
                // if category's name match
                if (i.UserDefined && i.ClassUserName == "Premier League")
                {
                    // overwritten the existing propertycategory with
                    // newly created propertycategory(existing + new)
                    cpropcates.SetUserDefined(1, "Premier League", "PremierLeague_InternalName",
                                              AddNewPropertyToExtgCategory(i));
                }
            }

            return(0);
        }
Пример #4
0
        private static void SetValues(ModelItem m, string CategoryName, string PropertyName, string value)
        {
            state = ComApiBridge.State;
            InwOaPath oPath = ComApiBridge.ToInwOaPath(m);

            // get properties collection of the path

            InwGUIPropertyNode2 propertyNode = state.GetGUIPropertyNode(oPath, true) as InwGUIPropertyNode2;

            // creating tab (Category), property null variables as placeholders
            InwGUIAttribute2 existingCategory = null;

            //Index of userDefined Tab
            int index = 1;

            //Case 1: Look for an existing category with the same CategoryName

            foreach (Autodesk.Navisworks.Api.Interop.ComApi.InwGUIAttribute2 attribute in propertyNode.GUIAttributes())
            {
                if (attribute.UserDefined)
                {
                    if (attribute.ClassUserName == CategoryName)
                    {
                        existingCategory = attribute;
                        NavisProperties properties = new NavisProperties(PropertyName, value, existingCategory);
                        setProperty(properties, index, propertyNode);
                        return;
                    }

                    index++;
                }
            }


            //Case 2: Category doesn´t exist, create category and property
            if (existingCategory == null)
            {
                NavisProperties properties = new NavisProperties(PropertyName, value, CategoryName);
                setCategoryAndProperty(properties, propertyNode);
                return;
            }
        }
        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);
        }