static IList <double> GetColor(Asset asset) { AssetPropertyDoubleArray3d color = asset.FindByName("filterColor") as AssetPropertyDoubleArray3d; if (color != null) { return(color.GetValueAsDoubles()); } return(null); }
private static Tuple <Type, Object> GetTypeAndValue(AssetProperty assetProperty, int level) { Object theValue; Type valueType; //For each AssetProperty, it has different type and value //must deal with it separately try { if (assetProperty is AssetPropertyBoolean) { AssetPropertyBoolean property = assetProperty as AssetPropertyBoolean; valueType = typeof(AssetPropertyBoolean); theValue = property.Value; } else if (assetProperty is AssetPropertyDistance) { AssetPropertyDistance property = assetProperty as AssetPropertyDistance; valueType = typeof(AssetPropertyDistance); theValue = property.Value; } else if (assetProperty is AssetPropertyDouble) { AssetPropertyDouble property = assetProperty as AssetPropertyDouble; valueType = typeof(AssetPropertyDouble); theValue = property.Value; } else if (assetProperty is AssetPropertyDoubleArray2d) { //Default, it is supported by PropertyGrid to display Double [] //Try to convert DoubleArray to Double [] AssetPropertyDoubleArray2d property = assetProperty as AssetPropertyDoubleArray2d; valueType = typeof(AssetPropertyDoubleArray2d); theValue = GetSystemArrayAsString(property.Value); } else if (assetProperty is AssetPropertyDoubleArray3d) { AssetPropertyDoubleArray3d property = assetProperty as AssetPropertyDoubleArray3d; valueType = typeof(AssetPropertyDoubleArray3d); //theValue = GetSystemArrayAsString( property.Value ); // 2017 theValue = Util.DoubleArrayString(property.GetValueAsDoubles()); // 2018 } else if (assetProperty is AssetPropertyDoubleArray4d) { AssetPropertyDoubleArray4d property = assetProperty as AssetPropertyDoubleArray4d; valueType = typeof(AssetPropertyDoubleArray4d); //theValue = GetSystemArrayAsString( property.Value ); // 2017 theValue = Util.DoubleArrayString(property.GetValueAsDoubles()); // 2018 } else if (assetProperty is AssetPropertyDoubleMatrix44) { AssetPropertyDoubleMatrix44 property = assetProperty as AssetPropertyDoubleMatrix44; valueType = typeof(AssetPropertyDoubleMatrix44); theValue = GetSystemArrayAsString(property.Value); } else if (assetProperty is AssetPropertyEnum) { AssetPropertyEnum property = assetProperty as AssetPropertyEnum; valueType = typeof(AssetPropertyEnum); theValue = property.Value; } else if (assetProperty is AssetPropertyFloat) { AssetPropertyFloat property = assetProperty as AssetPropertyFloat; valueType = typeof(AssetPropertyFloat); theValue = property.Value; } else if (assetProperty is AssetPropertyInteger) { AssetPropertyInteger property = assetProperty as AssetPropertyInteger; valueType = typeof(AssetPropertyInteger); theValue = property.Value; } else if (assetProperty is AssetPropertyReference) { AssetPropertyReference property = assetProperty as AssetPropertyReference; valueType = typeof(AssetPropertyReference); theValue = "REFERENCE"; //property.Type; } else if (assetProperty is AssetPropertyString) { AssetPropertyString property = assetProperty as AssetPropertyString; valueType = typeof(AssetPropertyString); theValue = property.Value; } else if (assetProperty is AssetPropertyTime) { AssetPropertyTime property = assetProperty as AssetPropertyTime; valueType = typeof(AssetPropertyTime); theValue = property.Value; } else { valueType = typeof(String); theValue = "Unprocessed asset type: " + assetProperty.GetType().Name; } if (assetProperty.NumberOfConnectedProperties > 0) { String result = ""; result = theValue.ToString(); TaskDialog.Show("Connected properties found", assetProperty.Name + ": " + assetProperty.NumberOfConnectedProperties); IList <AssetProperty> properties = assetProperty.GetAllConnectedProperties(); foreach (AssetProperty property in properties) { if (property is Asset) { // Nested? Asset asset = property as Asset; int size = asset.Size; for (int i = 0; i < size; i++) { //AssetProperty subproperty = asset[i]; // 2018 AssetProperty subproperty = asset.Get(i); // 2019 Tuple <Type, Object> valueAndType = GetTypeAndValue(subproperty, level + 1); String indent = ""; if (level > 0) { for (int iLevel = 1; iLevel <= level; iLevel++) { indent += " "; } } result += "\n " + indent + "- connected: name: " + subproperty.Name + " | type: " + valueAndType.Item1.Name + " | value: " + valueAndType.Item2.ToString(); } } } theValue = result; } } catch { return(null); } return(new Tuple <Type, Object>(valueType, theValue)); }
/// <summary> /// Gets the current value of the property on a component. /// </summary> /// <param name="component">The component with the property for which to retrieve the value.</param> /// <returns>The value of a property for a given component.</returns> public override object GetValue(object component) { //For each AssetProperty, it has different type and value //must deal with it separately try { if (m_assetProperty is AssetPropertyBoolean) { AssetPropertyBoolean property = m_assetProperty as AssetPropertyBoolean; m_valueType = typeof(Boolean); m_value = property.Value; } else if (m_assetProperty is AssetPropertyDistance) { AssetPropertyDistance property = m_assetProperty as AssetPropertyDistance; m_valueType = typeof(Double); m_value = property.Value; } else if (m_assetProperty is AssetPropertyDouble) { AssetPropertyDouble property = m_assetProperty as AssetPropertyDouble; m_valueType = typeof(Double); m_value = property.Value; } else if (m_assetProperty is AssetPropertyDoubleArray2d) { //Default, it is supported by PropertyGrid to display Double [] //Try to convert DoubleArray to Double [] AssetPropertyDoubleArray2d property = m_assetProperty as AssetPropertyDoubleArray2d; m_valueType = typeof(Double[]); m_value = GetSystemArray(property.Value); } else if (m_assetProperty is AssetPropertyDoubleArray3d) { AssetPropertyDoubleArray3d property = m_assetProperty as AssetPropertyDoubleArray3d; m_valueType = typeof(Double[]); m_value = GetSystemArray(property.Value); } else if (m_assetProperty is AssetPropertyDoubleArray4d) { AssetPropertyDoubleArray4d property = m_assetProperty as AssetPropertyDoubleArray4d; m_valueType = typeof(Double[]); m_value = GetSystemArray(property.Value); } else if (m_assetProperty is AssetPropertyDoubleMatrix44) { AssetPropertyDoubleMatrix44 property = m_assetProperty as AssetPropertyDoubleMatrix44; m_valueType = typeof(Double[]); m_value = GetSystemArray(property.Value); } else if (m_assetProperty is AssetPropertyEnum) { AssetPropertyEnum property = m_assetProperty as AssetPropertyEnum; m_valueType = typeof(int); m_value = property.Value; } else if (m_assetProperty is AssetPropertyFloat) { AssetPropertyFloat property = m_assetProperty as AssetPropertyFloat; m_valueType = typeof(float); m_value = property.Value; } else if (m_assetProperty is AssetPropertyInteger) { AssetPropertyInteger property = m_assetProperty as AssetPropertyInteger; m_valueType = typeof(int); m_value = property.Value; } else if (m_assetProperty is AssetPropertyReference) { AssetPropertyReference property = m_assetProperty as AssetPropertyReference; m_valueType = typeof(String); m_value = property.Type; } else if (m_assetProperty is AssetPropertyString) { AssetPropertyString property = m_assetProperty as AssetPropertyString; m_valueType = typeof(String); m_value = property.Value; } else if (m_assetProperty is AssetPropertyTime) { AssetPropertyTime property = m_assetProperty as AssetPropertyTime; m_valueType = typeof(DateTime); m_value = property.Value; } else { return(null); } } catch { return(null); } return(m_value); }
private void LogMaterial(AssetProperty asset, StringBuilder log, string t = null) { if (asset == null) { return; } log.Append(t + "Asset.Type:" + asset.Type.ToString() + "::" + asset.Name + "="); switch (asset.Type) { case AssetPropertyType.APT_Asset: Asset a = asset as Asset; log.Append("Asset,Size:" + a.Size + "\n"); for (int i = 0; i < a.Size; i++) { LogMaterial(a[i], log, t + "\t"); } break; case AssetPropertyType.APT_Boolean: AssetPropertyBoolean ab = asset as AssetPropertyBoolean; log.Append(ab.Value + "\n"); break; case AssetPropertyType.APT_Distance: AssetPropertyDistance ad = asset as AssetPropertyDistance; log.Append(ad.Value + "\n"); break; case AssetPropertyType.APT_Double: AssetPropertyDouble ado = asset as AssetPropertyDouble; log.Append(ado.Value + "\n"); break; case AssetPropertyType.APT_Double44: break; case AssetPropertyType.APT_DoubleArray2d: AssetPropertyDoubleArray2d ado2 = asset as AssetPropertyDoubleArray2d; log.Append(ado2.Value.get_Item(0) + "," + ado2.Value.get_Item(1) + "\n"); break; case AssetPropertyType.APT_DoubleArray3d: AssetPropertyDoubleArray3d ado3 = asset as AssetPropertyDoubleArray3d; log.Append(ado3.Value.get_Item(0) + "," + ado3.Value.get_Item(1) + "," + ado3.Value.get_Item(2) + "\n"); break; case AssetPropertyType.APT_DoubleArray4d: AssetPropertyDoubleArray4d ado4 = asset as AssetPropertyDoubleArray4d; log.Append(ado4.Value.get_Item(0) + "," + ado4.Value.get_Item(1) + "," + ado4.Value.get_Item(2) + "," + ado4.Value.get_Item(3) + "\n"); break; case AssetPropertyType.APT_Enum: AssetPropertyEnum ae = asset as AssetPropertyEnum; log.Append(ae.Value + "\n"); break; case AssetPropertyType.APT_Float: AssetPropertyFloat af = asset as AssetPropertyFloat; log.Append(af.Value + "\n"); break; case AssetPropertyType.APT_FloatArray: IList <float> lf = (asset as AssetPropertyFloatArray).GetValue(); foreach (float f in lf) { log.Append(f + ","); } log.Append("\n"); break; case AssetPropertyType.APT_Int64: AssetPropertyInt64 ai6 = asset as AssetPropertyInt64; log.Append(ai6.Value + "\n"); break; case AssetPropertyType.APT_Integer: AssetPropertyInteger ai = asset as AssetPropertyInteger; log.Append(ai.Value + "\n"); break; case AssetPropertyType.APT_List: break; case AssetPropertyType.APT_Properties: AssetProperties ap = asset as AssetProperties; log.Append("AssetProperties,Count:" + ap.Size + "\n"); for (int i = 0; i < ap.Size; i++) { LogMaterial(ap[i], log, t + "\t"); } break; case AssetPropertyType.APT_Reference: break; case AssetPropertyType.APT_String: AssetPropertyString _as = asset as AssetPropertyString; log.Append(_as.Value + "\n"); break; case AssetPropertyType.APT_Time: AssetPropertyTime at = asset as AssetPropertyTime; log.Append(at.Value + "\n"); break; case AssetPropertyType.APT_UInt64: AssetPropertyUInt64 aiu6 = asset as AssetPropertyUInt64; log.Append(aiu6.Value + "\n"); break; case AssetPropertyType.APT_Unknown: log.Append("\n"); break; default: log.Append("\n"); break; } foreach (Asset _a in asset.GetAllConnectedProperties()) { log.Append(t + "GetAllConnectedProperties:\n"); LogMaterial(_a, log, t + "\t"); } }
private void AddFaceMaterial(Material materialElement, UIDocument doc) { //string s = geomFace.MaterialElement.Name; //ElementId elementId = e.Id; //MaterialSet materials = e.Materials; //ElementId materialId = geomFace.MaterialElement.Id; //Material materialElement = doc.Document.get_Element(materialId) as Material; Asset m_asset = materialElement.RenderAppearance; double[] d_featureBase = { 1.0, 1.0, 1.0, 0.0, 0.0, 0.0, 1.0, 1.0, 1.0, 1.0, 1.0, 0.0, 0.0, 0.0 }; //shininess d_featureBase[cShininess] = (double)materialElement.Shininess / 128; d_featureBase[cTransparency] = 1.0 - (double)materialElement.Transparency / 100; d_featureBase[cAmbientR] = (double)materialElement.Color.Red / 255; d_featureBase[cAmbientR + 1] = (double)materialElement.Color.Green / 255; d_featureBase[cAmbientR + 2] = (double)materialElement.Color.Blue / 255; d_featureBase[cSpecularR] = (double)d_featureBase[cAmbientR] * materialElement.Smoothness / 100; d_featureBase[cSpecularR + 1] = (double)d_featureBase[cAmbientR + 1] * materialElement.Smoothness / 100; d_featureBase[cSpecularR + 2] = (double)d_featureBase[cAmbientR + 2] * materialElement.Smoothness / 100; Lid_FeatureMaterial.Add((double)Liu_FeatureIndex.Count + 1); cl_ElementData clED_Values; if (Dic_MaterialElementData.TryGetValue(materialElement.Name, out clED_Values)) { for (int inex = 0; inex < 3; inex++) { if (null != clED_Values) { d_featureBase[cDiffuseR + inex] = clED_Values.Diffuse[inex]; } } } else { clED_Values = new cl_ElementData(); double[] ap = { 0.0, 0.0, 0.0 }; clED_Values.Diffuse = ap; for (int index = 0; index < m_asset.Size; index++) { AssetProperty m_assetProperty = m_asset[index]; if (null != m_assetProperty) { Type m_valueType; Object m_value; try { if (m_assetProperty is AssetPropertyDoubleArray4d) { AssetPropertyDoubleArray4d property = m_assetProperty as AssetPropertyDoubleArray4d; //m_valueType = typeof(Double[]); //m_value = GetSystemArray(property.Value); masonrycmu_color if (m_assetProperty.Name == "generic_diffuse" || m_assetProperty.Name == "masonrycmu_color" || m_assetProperty.Name == "water_tint_color" || m_assetProperty.Name == "ceramic_color" || m_assetProperty.Name == "glazing_transmittance_map" || m_assetProperty.Name == "concrete_color" || m_assetProperty.Name == "plasticvinyl_color" || m_assetProperty.Name == "hardwood_tint_color" || m_assetProperty.Name == "metal_color" || m_assetProperty.Name == "solidglass_transmittance_custom_color" || m_assetProperty.Name == "wallpaint_color") { double[] values = new double[property.Value.Size]; int inro = 0; foreach (Double value in property.Value) { values[inro++] = value; } d_featureBase[cDiffuseR] = (double)d_featureBase[cAmbientR] * values[0]; d_featureBase[cDiffuseR + 1] = (double)d_featureBase[cAmbientR + 1] * values[1]; d_featureBase[cDiffuseR + 2] = (double)d_featureBase[cAmbientR + 2] * values[2]; for (int inex = 0; inex < 3; inex++) { //d_featureBase[cDiffuseR + inex] = values[inex]; clED_Values.Diffuse[inex] = d_featureBase[cDiffuseR + inex]; } } } else if (m_assetProperty is AssetPropertyDoubleArray2d) { //Default, it is supported by PropertyGrid to display Double [] //Try to convert DoubleArray to Double [] AssetPropertyDoubleArray2d property = m_assetProperty as AssetPropertyDoubleArray2d; m_valueType = typeof(Double[]); m_value = GetSystemArray(property.Value); } else if (m_assetProperty is AssetPropertyDoubleArray3d) { AssetPropertyDoubleArray3d property = m_assetProperty as AssetPropertyDoubleArray3d; m_valueType = typeof(Double[]); m_value = GetSystemArray(property.Value); } else if (m_assetProperty is AssetPropertyDoubleMatrix44) { AssetPropertyDoubleMatrix44 property = m_assetProperty as AssetPropertyDoubleMatrix44; m_valueType = typeof(Double[]); m_value = GetSystemArray(property.Value); } else { //AssetPropertyTime property = m_assetProperty as AssetPropertyTime; //m_valueType = typeof(DateTime); //m_value = property.Value; } } catch { } } //FOR } Dic_MaterialElementData.Add(materialElement.Name, clED_Values); } for (int i_i = 0; i_i < d_featureBase.Length; i_i++) { Lid_FeatureMaterial.Add(d_featureBase[i_i]); } }