private void SetCustomPropertys(ref Inventor.PartDocument PartDocument, string PropertyName, string PropertySetName) { Inventor.PropertySet m_Propertyset = PartDocument.PropertySets["{32853F0F-3444-11D1-9E93-0060B03C1CA6}"]; Inventor.Property m_Property = m_Propertyset[Inventor.PropertiesForDesignTrackingPropertiesEnum.kDescriptionDesignTrackingProperties]; m_Property.Expression = "=<Length>"; //Inventor.PropertiesForDesignTrackingPropertiesEnum.kDescriptionDesignTrackingProperties foreach (Inventor.PropertySet Propertyset in PartDocument.PropertySets) { if (Propertyset.Name == PropertySetName) //"Inventor User Defined Properties" { if (Propertyset.Count != 0) { foreach (Inventor.Property mProperty in Propertyset) { if (mProperty.Name == PropertyName) { //MessageBox.Show(""); } else { //ADD } } } } } } //Single Call
//Single Call multi add private void SetUserParameters(ref Inventor.PartDocument PartDocument, NameValueCollection ParameterNameValues, Inventor.UnitsTypeEnum units) { Inventor.UserParameter m_UserParameter; Collection <string> ParameterNameCach = new Collection <string>(); if (PartDocument.ComponentDefinition.Parameters.UserParameters.Count == 0) //Add from Scratch userPars { foreach (string namedParameter in ParameterNameValues.Keys) { m_UserParameter = PartDocument.ComponentDefinition.Parameters.UserParameters.AddByExpression(namedParameter, ParameterNameValues[namedParameter], units); m_UserParameter.ExposedAsProperty = true; } } else { foreach (Inventor.UserParameter up in PartDocument.ComponentDefinition.Parameters.UserParameters) { ParameterNameCach.Add(up.Name); } foreach (string namedParameter in ParameterNameValues.Keys) { if (!ParameterNameCach.Contains(namedParameter)) { m_UserParameter = PartDocument.ComponentDefinition.Parameters.UserParameters.AddByExpression(namedParameter, ParameterNameValues[namedParameter], units); m_UserParameter.ExposedAsProperty = true; } else { Inventor.UserParameter _UserParameter; _UserParameter = PartDocument.ComponentDefinition.Parameters.UserParameters[namedParameter]; _UserParameter.Expression = ParameterNameValues.Get(namedParameter) + "mm"; _UserParameter.CustomPropertyFormat.ShowTrailingZeros = false; _UserParameter.CustomPropertyFormat.ShowUnitsString = false; _UserParameter.CustomPropertyFormat.Precision = Inventor.CustomPropertyPrecisionEnum.kOneDecimalPlacePrecision; _UserParameter.ExposedAsProperty = true; } } } Inventor.PropertySet m_Propertyset = PartDocument.PropertySets["{32853F0F-3444-11D1-9E93-0060B03C1CA6}"]; Inventor.Property m_Property = m_Propertyset["Description"]; m_Property.Expression = "=<Material> <Length>X<Width>X<Thickness>"; }
private void GetUserDefProperties(string mPath, ref string[] mName, ref string[] mVal) { Inventor.Property oProp = default(Inventor.Property); Inventor.PropertySet oPropSet = default(Inventor.PropertySet); int mArrIndex = default(int); Inventor.ApprenticeServerComponent oApprenticeApp = new Inventor.ApprenticeServerComponent(); Inventor.ApprenticeServerDocument oApprenticeServerDoc = default(Inventor.ApprenticeServerDocument); oApprenticeServerDoc = oApprenticeApp.Open(mPath); if (oApprenticeServerDoc == null) { MessageBox.Show("File không hợp lệ"); return; } foreach (Inventor.PropertySet tempLoopVar_oPropSet in oApprenticeServerDoc.PropertySets) { oPropSet = tempLoopVar_oPropSet; if (oPropSet.DisplayName == "User Defined Properties") { mArrIndex = 0; mName = new string[oPropSet.Count + 1]; mVal = new string[oPropSet.Count + 1]; foreach (Inventor.Property tempLoopVar_oProp in oPropSet) { oProp = tempLoopVar_oProp; if (oProp.Name.ToLower().StartsWith("plot")) { continue; } if (Information.VarType(oProp.Value) != Constants.vbDate) { mName[mArrIndex] = (string)oProp.Name; mVal[mArrIndex] = (string)oProp.Value; mArrIndex++; } } break; } } }