/// <summary>
        /// Return the property of a the specified Property within a Document object. Uses a short-form signature.
        /// </summary>
        /// <param name="document">Inventor.Document</param>
        /// <param name="propertyName">Property Name as a string.</param>
        /// <returns>Object</returns>
        public static Property GetProperty(this Document document, string propertyName)
        {
            PropertySets propertySets = document.PropertySets;

            //get the propertySet for the provided propertyName (if it exists)
            if (NativePropertyLookup.TryGetValue(propertyName, out string setName))
            {
                return(propertySets[setName][propertyName]);
            }

            //not found in the standard properties, search the custom properties
            PropertySet currentPropertySet = propertySets["Inventor User Defined Properties"];

            try
            {
                return(currentPropertySet[propertyName]);
            }
            catch { };

            //still not found, search other custom property sets!
            if (UserPropertySetsExist(propertySets))
            {
                return(GetSuperCustomProperty(document, propertyName) ?? null);
            }

            //still not found, return nothing...
            return(null);
        }
Example #2
0
        public void PropertyTypeTest()
        {
            using (PropertySets propertySets = new PropertySets(s_testFile, false))
            {
                Console.WriteLine("Before:");
                DumpPropertySets(propertySets);

                if (propertySets.Contains(PropertySetIds.UserDefinedProperties))
                {
                    /* Clear all custom properties */
                    propertySets[PropertySetIds.UserDefinedProperties].Delete();
                }

                PropertySet custom = propertySets.Add(PropertySetIds.UserDefinedProperties, false);

                custom.Add("TestString", "Hello");
                custom.Add("TestDate", DateTime.Now);
                custom.Add("TestDouble", 1.0d);
                custom.Add("TestBoolean", false);

                Console.WriteLine();
                Console.WriteLine("After:");
                DumpPropertySets(propertySets);
            }
        }
        /// <summary>
        /// Set the specified document property's value.  If the iproperty name exist it will set the value.
        /// If the name does not exist, it will add the property with the value you have specified in the
        /// "User Defined Properties" property set.  The long signature function must be used to specify custom
        /// property groups.
        /// </summary>
        /// <param name="document">Inventor.Document</param>
        /// <param name="propertySetName">Property Set Name as a string</param>
        /// <param name="propertyName">Property Name as a string</param>
        /// <param name="value"></param>
        public static void SetPropertyValue(this Document document, string propertySetName, string propertyName, object value)
        {
            PropertySets documentPropertySets = document.PropertySets;

            //If the property set exists, set the value, or add it if needed...
            if (PropertySetExists(document, propertySetName))
            {
                try
                {
                    documentPropertySets[propertySetName][propertyName].Value = value;
                    return;
                }
                catch
                {
                    documentPropertySets[propertySetName].Add(value, propertyName);
                }
            }
            else
            {
                try
                {
                    documentPropertySets.Add(propertySetName);
                    documentPropertySets[propertySetName].Add(value, propertyName);
                }
                catch { };
            }
        }
        /// <summary>
        /// Set the specified document property's value.  If the iproperty name exist it will set the value.
        /// If the name does not exist, it will add the property with the value you have specified in the
        /// "User Defined Properties" property set.  This is the short-form signature.
        /// </summary>
        /// <param name="document">Inventor.Document</param>
        /// <param name="propertyName">Property Name as a string</param>
        /// <param name="value">Property value</param>
        public static void SetPropertyValue(this Document document, string propertyName, Object value)
        {
            PropertySets propertySets = document.PropertySets;

            //If the property exists as a built-in property, set the value
            if (NativePropertyLookup.TryGetValue(propertyName, out string setName))
            {
                try
                {
                    propertySets[setName][propertyName].Value = value;
                    return;
                }
                catch { };
            }

            //The property was not found in standard properties.  Search the custom properties...
            PropertySet i = propertySets["Inventor User Defined Properties"];

            try
            {
                i[propertyName].Value = value;
                return;
            }
            catch
            {
                i.Add(value, propertyName);
            }
        }
Example #5
0
        /// <summary>
        /// Processes IfcRelDefinesByProperties.
        /// </summary>
        /// <param name="ifcRelDefinesByProperties">The IfcRelDefinesByProperties handle.</param>
        void ProcessIFCRelDefinesByProperties(IFCAnyHandle ifcRelDefinesByProperties)
        {
            IFCAnyHandle propertySetDefinition = IFCAnyHandleUtil.GetInstanceAttribute(ifcRelDefinesByProperties, "RelatingPropertyDefinition");

            if (IFCAnyHandleUtil.IsNullOrHasNoValue(propertySetDefinition))
            {
                IFCImportFile.TheLog.LogNullError(IFCEntityType.IfcPropertySetDefinition);
                return;
            }

            IFCPropertySetDefinition ifcPropertySet = IFCPropertySetDefinition.ProcessIFCPropertySetDefinition(propertySetDefinition);

            if (ifcPropertySet != null)
            {
                int propertySetNumber = 1;
                while (true)
                {
                    string name = (propertySetNumber == 1) ? ifcPropertySet.Name : ifcPropertySet.Name + " " + propertySetNumber.ToString();
                    if (PropertySets.ContainsKey(name))
                    {
                        propertySetNumber++;
                    }
                    else
                    {
                        PropertySets[name] = ifcPropertySet;
                        break;
                    }
                }
            }
        }
        /// <summary>
        /// Removes the specified Document property.  If the property is native, it will only delete the iproperty's value.
        /// This is the long-form signature version of this method.
        /// </summary>
        /// <param name="document">Inventor.Document</param>
        /// <param name="propertySetName">Property Set Name as a string</param>
        /// <param name="propertyName">Property Name as a string</param>
        public static void RemoveProperty(this Document document, string propertySetName, string propertyName)
        {
            PropertySets documentPropertySets = document.PropertySets;

            //If the property set exists...
            if (PropertySetExists(document, propertySetName))
            {
                //remove it...
                try
                {
                    documentPropertySets[propertySetName][propertyName].Delete();
                    return;
                }
                catch { }
                //if property still exists...
                if (CustomPropertyExists(documentPropertySets[propertySetName], propertyName))
                {
                    //set it to ""
                    try
                    {
                        documentPropertySets[propertySetName][propertyName].Value = "";
                        return;
                    }
                    catch { }
                }
            }
        }
Example #7
0
        /// <summary>
        /// Adds a new client PropertySet to the PropertySets collection. If a client property set
        /// of the same name exists, the method returns.
        /// </summary>
        /// <param name="displayName"></param>
        public void AddClientPropertySet(string displayName)
        {
            if (IsClientPropertySet(displayName))
            {
                return;
            }
            var newPropSet = PropertySets.Add(displayName);

            propertySetsList.Add(newPropSet);
            clientPropertySetsList.Add(newPropSet);
        }
Example #8
0
 private static void DumpPropertySets(PropertySets propertySets)
 {
     foreach (PropertySet propertySet in propertySets)
     {
         Console.WriteLine(string.Format("{0} (Unicode: {1})", propertySet.Name, propertySet.IsUnicode));
         foreach (Property property in propertySet)
         {
             Console.WriteLine(string.Format("\t{0} ({1}): {2}", property.Name, property.Id, property.Value));
         }
     }
 }
        public ObjectTypeTree GetAttributes()
        {
            ObjectTypeTree ret = SchemaClass.ToObjectTypeTree();

            ret.AddNodeRange(PropertySets.Select(c => c.ToObjectTypeTree()));
            ObjectTypeTree unclass = DirectoryServiceUtils.DefaultPropertySet.ToObjectTypeTree();

            unclass.AddNodeRange(Attributes.Where(a => !a.InPropertySet).Select(a => a.ToObjectTypeTree()));
            ret.AddNode(unclass);
            return(ret);
        }
Example #10
0
        public static Inventor.PropertySet GetPropertySet(PropertySets sets, string name, bool createIfDoesNotExist = true)
        {
            foreach (Inventor.PropertySet set in sets)
            {
                if (set.Name == name)
                {
                    return(set);
                }
            }

            return(createIfDoesNotExist ? sets.Add(name) : null);
        }
 private Property GetProperty(Document doc, string propetySet, string propertyName)
 {
     try
     {
         PropertySets propSets = doc.PropertySets;
         PropertySet  propSet  = propSets[propetySet];
         Property     prop     = propSet[propertyName];
         return(prop);
     }
     catch
     {
         throw new Exception($"Could not find the {propertyName} property");
     }
 }
        public void Nsub_test()
        {
            Document doc = Substitute.For <Document>();

            doc.PropertySets["99"]["hhgf"].Value.Returns("hello");
            doc.NeedsMigrating.Returns(true);
            Assert.IsTrue(doc.NeedsMigrating);
            Assert.Equals(doc.PropertySets["99"]["hhgf"].Value, "hello");

            PropertySets fakePropSets = Substitute.For <PropertySets>();

            doc.PropertySets.Returns(fakePropSets);

            Assert.IsNotNull(doc.PropertySets);
        }
Example #13
0
        private async void UpdatePropertySets(string Id)
        {
            if (!string.IsNullOrEmpty(InnerItem.CatalogId))
            {
                var propSets = await Task.Run(() => _catalogRepositoryFactory.GetRepositoryInstance().PropertySets.ExpandAll().Where(x => x.CatalogId == InnerItem.CatalogId && (x.TargetType == "All" || x.TargetType == InnerItem.EntityImporter)));

                PropertySets = propSets.ToArray();
                if (PropertySets.Any() && string.IsNullOrEmpty(Id))
                {
                    InnerItem.PropertySetId = PropertySets.First().PropertySetId;
                }

                SetMappingItems();
            }
        }
Example #14
0
 public void EnumerationTest()
 {
     Console.WriteLine(IntPtr.Size);
     using (PropertySets propertySets = new PropertySets(s_testFile, true))
     {
         DumpPropertySets(propertySets);
         if (propertySets.IsFamilyMaster)
         {
             foreach (PropertySets member in propertySets.FamilyMembers)
             {
                 DumpPropertySets(member);
             }
         }
     }
 }
Example #15
0
        public dataModel.Category GetPropertyCategory(string propId)
        {
            dataModel.Category retVal = null;
            var propSet = PropertySets.FirstOrDefault(x => x.PropertySetProperties.Any(y => y.PropertyId == propId));

            if (propSet != null)
            {
                var categoryId = Categories.Where(x => x.PropertySetId == propSet.Id)
                                 .Select(x => x.Id).FirstOrDefault();
                if (categoryId != null)
                {
                    retVal = GetCategoryById(categoryId);
                }
            }
            return(retVal);
        }
Example #16
0
        public dataModel.Catalog GetPropertyCatalog(string propId)
        {
            dataModel.Catalog retVal = null;
            var propSet = PropertySets.FirstOrDefault(x => x.PropertySetProperties.Any(y => y.PropertyId == propId));

            if (propSet != null)
            {
                var catalogId = Catalogs.OfType <dataModel.Catalog>()
                                .Where(x => x.PropertySetId == propSet.Id)
                                .Select(x => x.Id).FirstOrDefault();
                if (catalogId != null)
                {
                    retVal = GetCatalogById(catalogId) as dataModel.Catalog;
                }
            }
            return(retVal);
        }
Example #17
0
        private void QueryBOM(BOMRowsEnumerator bomRows)
        {
            for (int i = 1; i < bomRows.Count + 1; i++)
            {
                try
                {
                    BOMRow bomRow = bomRows[i];

                    ComponentDefinition compDef = bomRow.ComponentDefinitions[1];

                    Document     doc          = (Document)compDef.Document;
                    PropertySets propertySets = doc.PropertySets;
                    PropertySet  propertySet  = propertySets["Design Tracking Properties"];

                    Property descProp = propertySet["Description"];
                    //Property weightProp
                    Property materialProp = propertySet["Material"];
                    Property costProp     = propertySet["Cost"];

                    matBreakdown.Rows.Add(bomRow.ItemQuantity, descProp.Value, materialProp.Value, costProp.Value);

                    Marshal.ReleaseComObject(costProp);
                    costProp = null;
                    Marshal.ReleaseComObject(materialProp);
                    materialProp = null;
                    Marshal.ReleaseComObject(descProp);
                    descProp = null;
                    Marshal.ReleaseComObject(propertySet);
                    propertySet = null;
                    Marshal.ReleaseComObject(propertySets);
                    propertySets = null;
                    Marshal.ReleaseComObject(doc);
                    doc = null;
                    Marshal.ReleaseComObject(compDef);
                    compDef = null;
                    Marshal.ReleaseComObject(bomRow);
                    bomRow = null;
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
            }
        }
        /// <summary>
        /// Removes the specified document property.  If the property is native, it will only delete the iproperty's value.
        /// This is the short-form signature version of this method.
        /// </summary>
        /// <param name="document">Inventor.Document</param>
        /// <param name="propertyName">Property Name as a string</param>
        public static void RemoveProperty(this Document document, string propertyName)
        {
            PropertySets propertySets = document.PropertySets;

            //If the property exists as a built-in property, remove the value
            if (NativePropertyLookup.TryGetValue(propertyName, out string setName))
            {
                try
                {
                    propertySets[setName][propertyName].Value = "";
                    return;
                }
                catch { };
            }

            //The property was not found in standard properties.  Search the custom properties...
            PropertySet i = propertySets["Inventor User Defined Properties"];

            try
            {
                i[propertyName].Delete();
                return;
            }
            catch { }

            //still not found, search other custom property sets!
            if (UserPropertySetsExist(propertySets))
            {
                foreach (PropertySet j in document.PropertySets)
                {
                    if (NativePropertySetLookup.Contains(j.DisplayName))
                    {
                        return;
                    }

                    try
                    {
                        j[propertyName].Delete();
                        return;
                    }
                    catch { };
                }
            }
        }
Example #19
0
        public void ModifyDeleteAddPropertyTest()
        {
            using (PropertySets propertySets = new PropertySets(s_testFile, false))
            {
                Console.WriteLine("Before:");
                DumpPropertySets(propertySets);

                PropertySet projectInfo = null;
                if (propertySets.Contains(PropertySetIds.ProjectInformation))
                {
                    projectInfo = propertySets[PropertySetIds.ProjectInformation];
                }
                else
                {
                    projectInfo = propertySets.Add(PropertySetIds.ProjectInformation, false);
                }

                Property docNumber = null;
                if (projectInfo.Contains(ProjectInfoIds.DocumentNumber))
                {
                    docNumber = projectInfo[ProjectInfoIds.DocumentNumber];
                }
                else
                {
                    docNumber = projectInfo.Add(ProjectInfoIds.DocumentNumber, string.Empty);
                }
                docNumber.Value = "Testing";
                Console.WriteLine();
                Console.WriteLine("After modification:");
                DumpPropertySets(propertySets);

                docNumber.Delete();
                Console.WriteLine();
                Console.WriteLine("After deletion:");
                DumpPropertySets(propertySets);

                docNumber = projectInfo.Add(ProjectInfoIds.DocumentNumber, "New property");
                Console.WriteLine();
                Console.WriteLine("After adding:");
                DumpPropertySets(propertySets);
            }
        }
        public void AssemblyDocumentIn_ReturnsDocument()
        {
            var doc = tests.TestUtilities.CreateAssemblyDocument();

            var doc2 = doc.GetDocumentFromObject();

            var tt = PropertyShim.GetPropertyValue(doc2, "Author");
            //only exists in ParDocuments
            PropertySets test = null;

            try
            {
                test = doc2.PropertySets;
            }
            catch { }

            try
            {
                Assert.IsNotNull(test);
            }
            finally { doc.Close(true); }
        }
Example #21
0
        public void DeleteAddPropertySetTest()
        {
            File.Copy(s_testFile, s_testFile + ".tmp");
            using (PropertySets propertySets = new PropertySets(s_testFile + ".tmp", false))
            {
                Console.WriteLine("Before deletion:");
                DumpPropertySets(propertySets);

                if (propertySets.Contains(PropertySetIds.SummaryInformation))
                {
                    propertySets[PropertySetIds.SummaryInformation].Delete();
                }

                PropertySet summaryInfo = propertySets.Add(PropertySetIds.SummaryInformation, false);

                summaryInfo.Add(SummaryInfoIds.Author, "Me");
                summaryInfo.Add(SummaryInfoIds.Created, DateTime.Now);

                Console.WriteLine();
                Console.WriteLine("After adding:");
                DumpPropertySets(propertySets);
            }
            File.Delete(s_testFile + ".tmp");
        }
        public void AssemblyDocumentIn_ReturnsDocument()
        {
            Inventor.Application app = ApplicationShim.Instance();
            var      path            = app.DesignProjectManager.ActiveDesignProject.TemplatesPath;
            Document doc             = app.Documents.Add(DocumentTypeEnum.kAssemblyDocumentObject, path + "Standard.iam", true);

            var doc2 = doc.GetDocumentFromObject();

            var tt = PropertyShim.GetPropertyValue(doc2, "Author");
            //only exists in ParDocuments
            PropertySets test = null;

            try
            {
                test = doc2.PropertySets;
            }
            catch { }

            try
            {
                Assert.IsNotNull(test);
            }
            finally { doc.Close(true); }
        }
Example #23
0
        /// <summary>
        /// Recursive utility for JointDataLoad.
        /// </summary>
        /// <param name="propertySets">Group of property sets to add any new property sets to.</param>
        /// <param name="currentNode">Current node to save joint data of.</param>
        /// <returns>True if all data was loaded successfully.</returns>
        private static bool LoadJointData(PropertySets propertySets, RigidNode_Base currentNode)
        {
            var allSuccessful = true;

            foreach (var connection in currentNode.Children)
            {
                var joint = connection.Key;
                var child = connection.Value;

                // Name of the property set in inventor
                var setName = "bxd-jointdata-" + child.GetModelID();

                // Attempt to open the property set
                var propertySet = InventorDocumentIOUtils.GetPropertySet(propertySets, setName, false);

                // If the property set does not exist, stop loading data
                if (propertySet == null)
                {
                    return(false);
                }

                joint.weight = InventorDocumentIOUtils.GetProperty(propertySet, "weight", 10);

                // Get joint properties from set
                // Get driver information
                if (InventorDocumentIOUtils.GetProperty(propertySet, "has-driver", false))
                {
                    if (joint.cDriver == null)
                    {
                        joint.cDriver = new JointDriver((JointDriverType)InventorDocumentIOUtils.GetProperty(propertySet, "driver-type", (int)JointDriverType.MOTOR));
                    }
                    var driver = joint.cDriver;

                    joint.cDriver.motor      = (MotorType)InventorDocumentIOUtils.GetProperty(propertySet, "motor-type", (int)MotorType.GENERIC);
                    joint.cDriver.port1      = InventorDocumentIOUtils.GetProperty(propertySet, "driver-port1", 0);
                    joint.cDriver.port2      = InventorDocumentIOUtils.GetProperty(propertySet, "driver-port2", -1);
                    joint.cDriver.isCan      = InventorDocumentIOUtils.GetProperty(propertySet, "driver-isCan", false);
                    joint.cDriver.lowerLimit = InventorDocumentIOUtils.GetProperty(propertySet, "driver-lowerLimit", 0.0f);
                    joint.cDriver.upperLimit = InventorDocumentIOUtils.GetProperty(propertySet, "driver-upperLimit", 0.0f);
                    joint.cDriver.InputGear  = InventorDocumentIOUtils.GetProperty(propertySet, "driver-inputGear", 0.0f);  // writes the gearing that the user last had in the exporter to the current gearing value
                    joint.cDriver.OutputGear = InventorDocumentIOUtils.GetProperty(propertySet, "driver-outputGear", 0.0f); // writes the gearing that the user last had in the exporter to the current gearing value
                    joint.cDriver.hasBrake   = InventorDocumentIOUtils.GetProperty(propertySet, "driver-hasBrake", false);

                    // Get other properties stored in meta
                    // Wheel information
                    if (InventorDocumentIOUtils.GetProperty(propertySet, "has-wheel", false))
                    {
                        if (driver.GetInfo <WheelDriverMeta>() == null)
                        {
                            driver.AddInfo(new WheelDriverMeta());
                        }
                        var wheel = joint.cDriver.GetInfo <WheelDriverMeta>();

                        wheel.type         = (WheelType)InventorDocumentIOUtils.GetProperty(propertySet, "wheel-type", (int)WheelType.NORMAL);
                        wheel.isDriveWheel = InventorDocumentIOUtils.GetProperty(propertySet, "wheel-isDriveWheel", false);
                        wheel.SetFrictionLevel((FrictionLevel)InventorDocumentIOUtils.GetProperty(propertySet, "wheel-frictionLevel", (int)FrictionLevel.MEDIUM));
                    }

                    // Pneumatic information
                    if (InventorDocumentIOUtils.GetProperty(propertySet, "has-pneumatic", false))
                    {
                        if (driver.GetInfo <PneumaticDriverMeta>() == null)
                        {
                            driver.AddInfo(new PneumaticDriverMeta());
                        }
                        var pneumatic = joint.cDriver.GetInfo <PneumaticDriverMeta>();

                        pneumatic.width        = InventorDocumentIOUtils.GetProperty(propertySet, "pneumatic-diameter", (double)0.5);
                        pneumatic.pressureEnum = (PneumaticPressure)InventorDocumentIOUtils.GetProperty(propertySet, "pneumatic-pressure", (int)PneumaticPressure.MEDIUM);
                    }

                    // Elevator information
                    if (InventorDocumentIOUtils.GetProperty(propertySet, "has-elevator", false))
                    {
                        if (driver.GetInfo <ElevatorDriverMeta>() == null)
                        {
                            driver.AddInfo(new ElevatorDriverMeta());
                        }
                        var elevator = joint.cDriver.GetInfo <ElevatorDriverMeta>();

                        elevator.type = (ElevatorType)InventorDocumentIOUtils.GetProperty(propertySet, "elevator-type", (int)ElevatorType.NOT_MULTI);
                        if (((int)elevator.type) > 7)
                        {
                            elevator.type = ElevatorType.NOT_MULTI;
                        }
                    }

                    for (var i = 0; i < InventorDocumentIOUtils.GetProperty(propertySet, "num-sensors", 0); i++)
                    {
                        RobotSensor addedSensor;
                        addedSensor                  = new RobotSensor((RobotSensorType)InventorDocumentIOUtils.GetProperty(propertySet, "sensorType" + i, (int)RobotSensorType.ENCODER));
                        addedSensor.portA            = ((int)InventorDocumentIOUtils.GetProperty(propertySet, "sensorPortA" + i, 0));
                        addedSensor.portB            = ((int)InventorDocumentIOUtils.GetProperty(propertySet, "sensorPortB" + i, 0));
                        addedSensor.conTypePortA     = ((SensorConnectionType)InventorDocumentIOUtils.GetProperty(propertySet, "sensorPortConA" + i, (int)SensorConnectionType.DIO));
                        addedSensor.conTypePortB     = ((SensorConnectionType)InventorDocumentIOUtils.GetProperty(propertySet, "sensorPortConB" + i, (int)SensorConnectionType.DIO));
                        addedSensor.conversionFactor = InventorDocumentIOUtils.GetProperty(propertySet, "sensorConversion" + i, 0.0);
                        joint.attachedSensors.Add(addedSensor);
                    }
                }

                // Recur along this child
                if (!LoadJointData(propertySets, child))
                {
                    allSuccessful = false;
                }
            }

            // Save was successful
            return(allSuccessful);
        }
 /// <summary>
 /// Returns the propertyset of the specified name, null if it does not exist
 /// </summary>
 /// <param name="pSetName"></param>
 /// <param name="caseSensitive"></param>
 /// <returns></returns>
 public IfcPropertySet GetPropertySet(string pSetName, bool caseSensitive = true)
 {
     return(PropertySets.FirstOrDefault(ps => string.Compare(ps.Name, pSetName, !caseSensitive) == 0));
 }
Example #25
0
        public void CostOf(Document bomItem)
        {
            double mass;
            string material;

            if (bomItem.DocumentType == DocumentTypeEnum.kPartDocumentObject)
            {
                PartDocument            partDoc      = (PartDocument)bomItem;
                PartComponentDefinition partCompDef  = partDoc.ComponentDefinition;
                PropertySets            propertySets = partDoc.PropertySets;
                PropertySet             propertySet  = propertySets["Design Tracking Properties"];
                Property costProp = propertySet["Cost"];

                if (partCompDef.BOMStructure == BOMStructureEnum.kPurchasedBOMStructure || partCompDef.BOMStructure == BOMStructureEnum.kInseparableBOMStructure)
                {
                    cost = Convert.ToDouble(costProp.Value);
                    // purchasedCost = Convert.ToDouble(costProp.Value);

                    Marshal.ReleaseComObject(costProp);
                    costProp = null;

                    Marshal.ReleaseComObject(propertySet);
                    propertySet = null;

                    Marshal.ReleaseComObject(propertySets);
                    propertySets = null;

                    Marshal.ReleaseComObject(partCompDef);
                    partCompDef = null;

                    Marshal.ReleaseComObject(partDoc);
                    partDoc = null;

                    return;
                }

                Property materialProp = propertySet["Material"];



                // Mass of Part
                mass = partCompDef.MassProperties.Mass;

                // Material of Part
                if (materialProp.Value.ToString().Contains("MESH"))
                {
                    material = "MESH";
                }
                else if (materialProp.Value.ToString().Contains("EXPANDED METAL"))
                {
                    material = "EXPANDED METAL";
                }
                else
                {
                    material = materialProp.Value.ToString();
                }


                // Cost
                try
                {
                    // Multiple by 2.20462262 for kg to lbs conversion
                    cost = mass * 2.20462262 * materialMap[material];
                }
                catch (Exception)
                {
                    cost = 0.0;
                }

                costProp.Value = cost;  // Set Estimated Cost

                Marshal.ReleaseComObject(materialProp);
                materialProp = null;

                Marshal.ReleaseComObject(costProp);
                costProp = null;

                Marshal.ReleaseComObject(propertySet);
                propertySet = null;

                Marshal.ReleaseComObject(propertySets);
                propertySets = null;

                Marshal.ReleaseComObject(partCompDef);
                partCompDef = null;

                Marshal.ReleaseComObject(partDoc);
                partDoc = null;

                return;
            }

            foreach (Document nestedAsm in bomItem.ReferencedDocuments)
            {
                CostOf(nestedAsm);
            }

            if (bomItem.DocumentType == DocumentTypeEnum.kAssemblyDocumentObject)
            {
                cost = 0;

                AssemblyDocument assemblyDoc  = (AssemblyDocument)bomItem;
                PropertySets     assemblySets = assemblyDoc.PropertySets;
                PropertySet      assemblySet  = assemblySets["Design Tracking Properties"];
                Property         asmCost      = assemblySet["Cost"];

                AssemblyComponentDefinition asmCompDef = assemblyDoc.ComponentDefinition;
                ComponentOccurrences        occurances = asmCompDef.Occurrences;

                foreach (Document nestedPart in bomItem.ReferencedDocuments)
                {
                    try
                    {
                        PropertySets propertySets = nestedPart.PropertySets;
                        PropertySet  propertySet  = propertySets["Design Tracking Properties"];
                        Property     costProp     = propertySet["Cost"];

                        cost = cost + Convert.ToDouble(costProp.Value.ToString()) * GetOccurances(nestedPart, occurances);

                        Marshal.ReleaseComObject(costProp);
                        costProp = null;

                        Marshal.ReleaseComObject(propertySet);
                        propertySet = null;

                        Marshal.ReleaseComObject(propertySets);
                        propertySets = null;
                    }
                    catch
                    {
                        continue;
                    }
                }

                asmCost.Value = cost;

                Marshal.ReleaseComObject(occurances);
                occurances = null;

                Marshal.ReleaseComObject(asmCompDef);
                asmCompDef = null;

                Marshal.ReleaseComObject(asmCost);
                asmCost = null;

                Marshal.ReleaseComObject(assemblySet);
                assemblySet = null;

                Marshal.ReleaseComObject(assemblySets);
                assemblySets = null;

                Marshal.ReleaseComObject(assemblyDoc);
                assemblyDoc = null;
            }
        }
Example #26
0
		static void Main(string[] args)
		{
			DrawProgramInfo();

			Console.Write("Input folder path: (empty for current folder)");
			Path = Console.ReadLine();

			StartWatch();

			if (string.IsNullOrWhiteSpace(Path))
				Path = System.Environment.CurrentDirectory;

			Files = Directory.GetFiles(Path, "*.*", SearchOption.AllDirectories);

			Console.WriteLine($"Number of files: {Files.Length}");

			foreach (var file in Files)
			{
				string line = $"file: {file}:";
				result.Add(line);

				if (!File.Exists(file))
				{
					err_file_not_found.Add($"File NOT EXIST. ({file})."); 
					continue;
				}

				PropertySets psets = new PropertySets(file, true);
				PropertySet psi = null;

				if (psets.Contains(PropertySetIds.UserDefinedProperties))
				{
					if ((psi = psets[PropertySetIds.UserDefinedProperties]) != null)
					{ ReadProp(file, psi); }
				}
				if (psets.Contains(PropertySetIds.DocumentSummaryInformation))
				{
					if ((psi = psets[PropertySetIds.DocumentSummaryInformation]) != null)
					{ ReadProp(file, psi); }
				}
				if (psets.Contains(PropertySetIds.ProjectInformation))
				{
					if ((psi = psets[PropertySetIds.ProjectInformation]) != null)
					{ ReadProp(file, psi); }
				}
				if (psets.Contains(PropertySetIds.SummaryInformation))
				{
					if ((psi = psets[PropertySetIds.SummaryInformation]) != null)
					{ ReadProp(file, psi); }
				}
				if (psets.Contains(PropertySetIds.ExtendedSummaryInformation))
				{
					if ((psi = psets[PropertySetIds.ExtendedSummaryInformation]) != null)
					{ ReadProp(file, psi); }
				}

				result.Add("------------------------------------------------------");
				result.Add(string.Empty);
			}

			PauseWatch();

			Console.Write("\nInput folder with links files: ");
			Path = Console.ReadLine();

			UnpauseWatch();

			if (string.IsNullOrWhiteSpace(Path))
				Console.WriteLine("Null path. Continue...");
			else
				ReadDummyFiles(Path);

			
			DrawHeader(err_too_long_props, "TOO LONG PROPERTIES");
			DrawHeader(err_file_not_found, "FILES NOT FOUND");
			DrawHeader(err_too_long_links, "TOO LONG LINKS");

			TimeSpan time = StopWatch();

			string output = $"{DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss")}_PropsInfo.txt";
			File.AppendAllLines(output, err_too_long_props, Encoding.UTF8);
			File.AppendAllLines(output, err_file_not_found, Encoding.UTF8);
			File.AppendAllLines(output, err_too_long_links, Encoding.UTF8);
			File.AppendAllLines(output, result, Encoding.UTF8);

			Console.WriteLine($"\nLogfile '{output}' was created.");
			Console.WriteLine($"end program (duration: {time.TotalMilliseconds} ms, {time.TotalSeconds} s, {time.TotalMinutes} m)");
			Console.ReadLine();
		}
        private void InitializeMembers()
        {
            this.propertySets = document.PropertySets;
            this.allPropertiesList = new List<Property>();
            this.propertySetsList = new List<PropertySet>();
            this.userDefinedPropertiesList = new List<Property>();
            this.summaryInfoPropertiesList = new List<Property>();
            this.docSummaryInfoPropertiesList = new List<Property>();
            this.designTrackingPropertiesList = new List<Property>();
            this.clientPropertySetsList = new List<PropertySet>();
            this.clientPropertiesList = new List<Property>();

            foreach(PropertySet propSet in this.propertySets)
            {
                foreach(Inventor.Property property in propSet)
                {
                    this.allPropertiesList.Add(property);
                }

                string propertySetInternalName = propSet.InternalName;

                switch(propertySetInternalName)
                {
                    case "{F29F85E0-4FF9-1068-AB91-08002B27B3D9}":
                        this.summaryInfoPropSet = propSet;
                        foreach(Property summInfoProp in propSet)
                        {
                            this.summaryInfoPropertiesList.Add(summInfoProp);
                        }
                        break;
                    case "{D5CDD502-2E9C-101B-9397-08002B2CF9AE}":
                        this.docSummaryInfoPropSet = propSet;
                        foreach(Property docSummInfoProp in propSet)
                        {
                            this.docSummaryInfoPropertiesList.Add(docSummInfoProp);
                        }
                        break;
                    case "{32853F0F-3444-11D1-9E93-0060B03C1CA6}":
                        this.designTrackingPropSet = propSet;
                        foreach(Property designTrkngProp in propSet)
                        {
                            this.designTrackingPropertiesList.Add(designTrkngProp);
                        }
                        break;
                    case "{D5CDD505-2E9C-101B-9397-08002B2CF9AE}":
                        this.userDefinedPropSet = propSet;
                        foreach(Property userProp in propSet)
                        {
                            this.userDefinedPropertiesList.Add(userProp);
                        }
                        break;
                    default:
                        this.clientPropertySetsList.Add(propSet);
                        foreach(Property clientProp in propSet)
                        {
                            this.clientPropertiesList.Add(clientProp);
                        }
                        break;
                }

                propertySetsList.Add(propSet);
            }
        }
 /// <summary>
 /// Returns a boolean indicating if the document contains custom PropertySets
 /// </summary>
 /// <param name="propertySets">PropertySet object</param>
 /// <returns>Boolean</returns>
 private static bool UserPropertySetsExist(PropertySets propertySets)
 {
     return(propertySets.Count >= NativePropertySetLookup.Count ? true : false);
 }
Example #29
0
        private void InitializeMembers()
        {
            this.propertySets                 = document.PropertySets;
            this.allPropertiesList            = new List <Property>();
            this.propertySetsList             = new List <PropertySet>();
            this.userDefinedPropertiesList    = new List <Property>();
            this.summaryInfoPropertiesList    = new List <Property>();
            this.docSummaryInfoPropertiesList = new List <Property>();
            this.designTrackingPropertiesList = new List <Property>();
            this.clientPropertySetsList       = new List <PropertySet>();
            this.clientPropertiesList         = new List <Property>();

            foreach (PropertySet propSet in this.propertySets)
            {
                foreach (Inventor.Property property in propSet)
                {
                    this.allPropertiesList.Add(property);
                }

                string propertySetInternalName = propSet.InternalName;

                switch (propertySetInternalName)
                {
                case "{F29F85E0-4FF9-1068-AB91-08002B27B3D9}":
                    this.summaryInfoPropSet = propSet;
                    foreach (Property summInfoProp in propSet)
                    {
                        this.summaryInfoPropertiesList.Add(summInfoProp);
                    }
                    break;

                case "{D5CDD502-2E9C-101B-9397-08002B2CF9AE}":
                    this.docSummaryInfoPropSet = propSet;
                    foreach (Property docSummInfoProp in propSet)
                    {
                        this.docSummaryInfoPropertiesList.Add(docSummInfoProp);
                    }
                    break;

                case "{32853F0F-3444-11D1-9E93-0060B03C1CA6}":
                    this.designTrackingPropSet = propSet;
                    foreach (Property designTrkngProp in propSet)
                    {
                        this.designTrackingPropertiesList.Add(designTrkngProp);
                    }
                    break;

                case "{D5CDD505-2E9C-101B-9397-08002B2CF9AE}":
                    this.userDefinedPropSet = propSet;
                    foreach (Property userProp in propSet)
                    {
                        this.userDefinedPropertiesList.Add(userProp);
                    }
                    break;

                default:
                    this.clientPropertySetsList.Add(propSet);
                    foreach (Property clientProp in propSet)
                    {
                        this.clientPropertiesList.Add(clientProp);
                    }
                    break;
                }

                propertySetsList.Add(propSet);
            }
        }
Example #30
0
        /// <summary>
        /// Recursive utility for JointDataSave.
        /// </summary>
        /// <returns>True if all data was saved successfully.</returns>
        private static bool SaveJointData(PropertySets assemblyPropertySets, RigidNode_Base currentNode)
        {
            var allSuccessful = true;

            foreach (var connection in currentNode.Children)
            {
                var joint = connection.Key;
                var child = connection.Value;

                // Name of the property set in inventor
                var setName = "bxd-jointdata-" + child.GetModelID();

                // Create the property set if it doesn't exist
                var propertySet = InventorDocumentIOUtils.GetPropertySet(assemblyPropertySets, setName);

                // Add joint properties to set
                // Save driver information
                var driver = joint.cDriver;
                InventorDocumentIOUtils.SetProperty(propertySet, "has-driver", driver != null);
                InventorDocumentIOUtils.SetProperty(propertySet, "weight", joint.weight);
                if (driver != null)
                {
                    InventorDocumentIOUtils.SetProperty(propertySet, "driver-type", (int)driver.GetDriveType());
                    InventorDocumentIOUtils.SetProperty(propertySet, "motor-type", (int)driver.GetMotorType());
                    InventorDocumentIOUtils.SetProperty(propertySet, "driver-port1", driver.port1);
                    InventorDocumentIOUtils.SetProperty(propertySet, "driver-port2", driver.port2);
                    InventorDocumentIOUtils.SetProperty(propertySet, "driver-isCan", driver.isCan);
                    InventorDocumentIOUtils.SetProperty(propertySet, "driver-lowerLimit", driver.lowerLimit);
                    InventorDocumentIOUtils.SetProperty(propertySet, "driver-upperLimit", driver.upperLimit);
                    InventorDocumentIOUtils.SetProperty(propertySet, "driver-inputGear", driver.InputGear);   // writes the input gear to the .IAM file incase the user wants to reexport their robot later
                    InventorDocumentIOUtils.SetProperty(propertySet, "driver-outputGear", driver.OutputGear); // writes the ouotput gear to the .IAM file incase the user wants to reexport their robot later
                    InventorDocumentIOUtils.SetProperty(propertySet, "driver-hasBrake", driver.hasBrake);

                    // Save other properties stored in meta
                    // Wheel information
                    var wheel = joint.cDriver.GetInfo <WheelDriverMeta>();
                    InventorDocumentIOUtils.SetProperty(propertySet, "has-wheel", wheel != null);

                    if (wheel != null)
                    {
                        InventorDocumentIOUtils.SetProperty(propertySet, "wheel-type", (int)wheel.type);
                        InventorDocumentIOUtils.SetProperty(propertySet, "wheel-isDriveWheel", wheel.isDriveWheel);
                        InventorDocumentIOUtils.SetProperty(propertySet, "wheel-frictionLevel", (int)wheel.GetFrictionLevel());
                    }

                    // Pneumatic information
                    var pneumatic = joint.cDriver.GetInfo <PneumaticDriverMeta>();
                    InventorDocumentIOUtils.SetProperty(propertySet, "has-pneumatic", pneumatic != null);

                    if (pneumatic != null)
                    {
                        InventorDocumentIOUtils.SetProperty(propertySet, "pneumatic-diameter", (double)pneumatic.width);
                        InventorDocumentIOUtils.SetProperty(propertySet, "pneumatic-pressure", (int)pneumatic.pressureEnum);
                    }

                    // Elevator information
                    var elevator = joint.cDriver.GetInfo <ElevatorDriverMeta>();


                    InventorDocumentIOUtils.SetProperty(propertySet, "has-elevator", elevator != null);

                    if (elevator != null)
                    {
                        InventorDocumentIOUtils.SetProperty(propertySet, "elevator-type", (int)elevator.type);
                    }
                }

                for (var i = 0; i < InventorDocumentIOUtils.GetProperty(propertySet, "num-sensors", 0); i++) // delete existing sensors
                {
                    InventorDocumentIOUtils.RemoveProperty(propertySet, "sensorType" + i);
                    InventorDocumentIOUtils.RemoveProperty(propertySet, "sensorPortA" + i);
                    InventorDocumentIOUtils.RemoveProperty(propertySet, "sensorPortConA" + i);
                    InventorDocumentIOUtils.RemoveProperty(propertySet, "sensorPortB" + i);
                    InventorDocumentIOUtils.RemoveProperty(propertySet, "sensorPortConB" + i);
                    InventorDocumentIOUtils.RemoveProperty(propertySet, "sensorConversion" + i);
                }

                InventorDocumentIOUtils.SetProperty(propertySet, "num-sensors", joint.attachedSensors.Count);
                for (var i = 0; i < joint.attachedSensors.Count; i++)
                {
                    InventorDocumentIOUtils.SetProperty(propertySet, "sensorType" + i, (int)joint.attachedSensors[i].type);
                    InventorDocumentIOUtils.SetProperty(propertySet, "sensorPortA" + i, joint.attachedSensors[i].portA);
                    InventorDocumentIOUtils.SetProperty(propertySet, "sensorPortConA" + i, (int)joint.attachedSensors[i].conTypePortA);
                    InventorDocumentIOUtils.SetProperty(propertySet, "sensorPortB" + i, joint.attachedSensors[i].portB);
                    InventorDocumentIOUtils.SetProperty(propertySet, "sensorPortConB" + i, (int)joint.attachedSensors[i].conTypePortB);
                    InventorDocumentIOUtils.SetProperty(propertySet, "sensorConversion" + i, joint.attachedSensors[i].conversionFactor);
                }

                // Recur along this child
                if (!SaveJointData(assemblyPropertySets, child))
                {
                    allSuccessful = false;
                }
            }

            // Save was successful
            return(allSuccessful);
        }
Example #31
0
        static void Main(string[] args)
        {
            DrawProgramInfo();

            Console.Write("Input folder path: (empty for current folder)");
            Path = Console.ReadLine();

            StartWatch();

            if (string.IsNullOrWhiteSpace(Path))
            {
                Path = System.Environment.CurrentDirectory;
            }

            Files = Directory.GetFiles(Path, "*.*", SearchOption.AllDirectories);

            Console.WriteLine($"Number of files: {Files.Length}");

            foreach (var file in Files)
            {
                string line = $"file: {file}:";
                result.Add(line);

                if (!File.Exists(file))
                {
                    err_file_not_found.Add($"File NOT EXIST. ({file}).");
                    continue;
                }

                PropertySets psets = new PropertySets(file, true);
                PropertySet  psi   = null;

                if (psets.Contains(PropertySetIds.UserDefinedProperties))
                {
                    if ((psi = psets[PropertySetIds.UserDefinedProperties]) != null)
                    {
                        ReadProp(file, psi);
                    }
                }
                if (psets.Contains(PropertySetIds.DocumentSummaryInformation))
                {
                    if ((psi = psets[PropertySetIds.DocumentSummaryInformation]) != null)
                    {
                        ReadProp(file, psi);
                    }
                }
                if (psets.Contains(PropertySetIds.ProjectInformation))
                {
                    if ((psi = psets[PropertySetIds.ProjectInformation]) != null)
                    {
                        ReadProp(file, psi);
                    }
                }
                if (psets.Contains(PropertySetIds.SummaryInformation))
                {
                    if ((psi = psets[PropertySetIds.SummaryInformation]) != null)
                    {
                        ReadProp(file, psi);
                    }
                }
                if (psets.Contains(PropertySetIds.ExtendedSummaryInformation))
                {
                    if ((psi = psets[PropertySetIds.ExtendedSummaryInformation]) != null)
                    {
                        ReadProp(file, psi);
                    }
                }

                result.Add("------------------------------------------------------");
                result.Add(string.Empty);
            }

            PauseWatch();

            Console.Write("\nInput folder with links files: ");
            Path = Console.ReadLine();

            UnpauseWatch();

            if (string.IsNullOrWhiteSpace(Path))
            {
                Console.WriteLine("Null path. Continue...");
            }
            else
            {
                ReadDummyFiles(Path);
            }


            DrawHeader(err_too_long_props, "TOO LONG PROPERTIES");
            DrawHeader(err_file_not_found, "FILES NOT FOUND");
            DrawHeader(err_too_long_links, "TOO LONG LINKS");

            TimeSpan time = StopWatch();

            string output = $"{DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss")}_PropsInfo.txt";

            File.AppendAllLines(output, err_too_long_props, Encoding.UTF8);
            File.AppendAllLines(output, err_file_not_found, Encoding.UTF8);
            File.AppendAllLines(output, err_too_long_links, Encoding.UTF8);
            File.AppendAllLines(output, result, Encoding.UTF8);

            Console.WriteLine($"\nLogfile '{output}' was created.");
            Console.WriteLine($"end program (duration: {time.TotalMilliseconds} ms, {time.TotalSeconds} s, {time.TotalMinutes} m)");
            Console.ReadLine();
        }
 public InventorProperties(PropertySets propertySets)
 {
     _propertySets = propertySets;
 }