예제 #1
0
        public void ListAllAssets(UIApplication uiapp)
        {
            AssetSet assets = uiapp.Application.get_Assets(AssetType.Appearance);

            TaskDialog dlg = new TaskDialog("Assets");

            String assetLabel = "";

            foreach (Asset asset in assets)
            {
                String libraryName = asset.LibraryName;

                //AssetPropertyString uiname = asset["UIName"] as AssetPropertyString; // 2018
                AssetPropertyString uiname = asset.FindByName("UIName") as AssetPropertyString; // 2019

                //AssetPropertyString baseSchema = asset["BaseSchema"] as AssetPropertyString; // 2018
                AssetPropertyString baseSchema = asset.FindByName("BaseSchema") as AssetPropertyString; // 2019

                assetLabel += libraryName + " | " + uiname.Value + " | " + baseSchema.Value;
                assetLabel += "\n";
            }

            dlg.MainInstruction = assetLabel;

            dlg.Show();
        }
        //bool UseTemperature(Asset asset)

        static string GetIesFile(Asset asset)
        {
            AssetPropertyString iesFile = asset.FindByName("lightProfileFileName") as AssetPropertyString;

            if (iesFile != null)
            {
                return(iesFile.Value);
            }

            return("");
        }
        static string GetIesCacheData(Asset asset)
        {
            AssetPropertyString iesFile = asset.FindByName("lightProfileCacheData") as AssetPropertyString;

            if (iesFile != null)
            {
                byte[] data = Encoding.Unicode.GetBytes(iesFile.Value);
                return(Encoding.ASCII.GetString(data));
            }

            return("");
        }
예제 #4
0
        void ChangeRenderingTexturePath(Document doc)
        {
            // As there is only one material in the sample
            // project, we can use FilteredElementCollector
            // and grab the first result

            Material mat = new FilteredElementCollector(doc).OfClass(typeof(Material)).FirstElement() as Material;

            // Fixed path for new texture
            // Texture included in sample files

            string texturePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "new_texture.png");

            using (Transaction t = new Transaction(doc))
            {
                t.Start("Changing material texture path");

                using (AppearanceAssetEditScope editScope = new AppearanceAssetEditScope(doc))
                {
                    Asset editableAsset = editScope.Start(mat.AppearanceAssetId);

                    // Getting the correct AssetProperty

                    AssetProperty assetProperty = editableAsset["generic_diffuse"];


                    Asset connectedAsset = assetProperty.GetConnectedProperty(0) as Asset;

                    // Getting the right connected Asset

                    if (connectedAsset.Name == "UnifiedBitmapSchema")
                    {
                        AssetPropertyString path = connectedAsset.FindByName(UnifiedBitmap.UnifiedbitmapBitmap) as AssetPropertyString;

                        if (path.IsValidValue(texturePath))
                        {
                            path.Value = texturePath;
                        }
                    }
                    editScope.Commit(true);
                }
                TaskDialog.Show("Material texture path", "Material texture path changed to:\n" + texturePath);

                t.Commit();
                t.Dispose();
            }
        }
예제 #5
0
        /// <summary>
        /// 更改外观
        /// </summary>
        /// <param name="material"></param>
        /// <param name="bumpmapImageFilepath"></param>
        public static void ChangeRenderingTexturePath(Material mat, Document doc, string texturePath, double x, double y)
        {
            using (AppearanceAssetEditScope editScope = new AppearanceAssetEditScope(doc))
            {
                Asset editableAsset = editScope.Start(mat.AppearanceAssetId);

#if VERSION2018
                AssetProperty assetProperty = editableAsset["generic_diffuse"];
#else
                // VERSION2019
                AssetProperty assetProperty = editableAsset.FindByName("generic_diffuse");
#endif
                Asset connectedAsset = assetProperty.GetConnectedProperty(0) as Asset;

                /*if (connectedAsset == null)
                 * {
                 *
                 *  // Add a new default connected asset
                 *  assetProperty.AddConnectedAsset("UnifiedBitmap");
                 *  connectedAsset = assetProperty.GetSingleConnectedAsset();
                 * }*/
                if (connectedAsset.Name == "UnifiedBitmapSchema")
                {
                    // TaskDialog.Show("Tip", "成功");
                    AssetPropertyString path = connectedAsset.FindByName(UnifiedBitmap.UnifiedbitmapBitmap) as AssetPropertyString;

                    AssetPropertyBoolean scalelock = connectedAsset.FindByName(UnifiedBitmap.TextureScaleLock) as AssetPropertyBoolean;
                    scalelock.Value = false;
                    AssetPropertyDistance sizeY = connectedAsset.FindByName(UnifiedBitmap.TextureRealWorldScaleY) as AssetPropertyDistance;
                    sizeY.Value = y;
                    AssetPropertyDistance sizeX = connectedAsset.FindByName(UnifiedBitmap.TextureRealWorldScaleX) as AssetPropertyDistance;
                    sizeX.Value = x;
                    if (path.IsValidValue(texturePath))
                    {
                        path.Value = texturePath;
                    }
                    else
                    {
                        throw new Exception("找不到文件:" + texturePath);
                        //TaskDialog.Show("Tip", "文件路径错误");
                    }
                }

                editScope.Commit(true);
            }
        }
        // 定义修改贴图路径的方法
        public string ChangeRenderingTexturePath(Document doc, Material mat, string newPath)
        {
            try
            {
                using (Transaction t = new Transaction(doc))
                {
                    t.Start("更改贴图位置");

                    using (AppearanceAssetEditScope editScope = new AppearanceAssetEditScope(doc))
                    {
                        Asset editableAsset = editScope.Start(mat.AppearanceAssetId);
                        // Getting the correct AssetProperty
                        AssetProperty assetProperty = editableAsset.FindByName("generic_diffuse");
                        if (assetProperty is null)
                        {
                            assetProperty = editableAsset.FindByName("masonrycmu_color");
                        }

                        Asset connectedAsset = assetProperty.GetConnectedProperty(0) as Asset;
                        // getting the right connected Asset
                        if (connectedAsset.Name == "UnifiedBitmapSchema")
                        {
                            AssetPropertyString path = connectedAsset.FindByName(UnifiedBitmap.UnifiedbitmapBitmap) as AssetPropertyString;
                            if (path.IsValidValue(newPath))
                            {
                                path.Value = newPath;
                            }
                        }
                        editScope.Commit(true);
                    }
                    t.Commit();
                    t.Dispose();
                }
                return(mat.Name);
            }
            catch (Exception)
            {
                TaskDialog.Show("错误提示!!!", "材质【" + mat.Name + "】的贴图更改失败,请手动更改材质贴图");
                return(null);
            }
        }
 // 定义获取材质路径的方法
 public void GetRenderingTexturePath(Document doc, Material mat, List <Material> changePathMaterial, List <string> oldPath)
 {
     if (Convert.ToString(mat.AppearanceAssetId) != "-1")  // 如果材质没有AppearanceAssetId就跳过
     {
         Asset matAsset = (doc.GetElement(mat.AppearanceAssetId) as AppearanceAssetElement).GetRenderingAsset();
         if (matAsset.Size != 0)
         {
             for (int i = 0; i < matAsset.Size; i++)
             {
                 if (matAsset[i].Name == "generic_diffuse" || matAsset[i].Name == "masonrycmu_color")
                 {
                     Asset diffuseAsset = matAsset[i].GetSingleConnectedAsset();
                     if (diffuseAsset is null)
                     {
                         continue;
                     }
                     else
                     {
                         for (int j = 0; j < diffuseAsset.Size; j++)
                         {
                             if (diffuseAsset[j].Name == "unifiedbitmap_Bitmap")
                             {
                                 AssetPropertyString path = diffuseAsset[j] as AssetPropertyString;
                                 string bitMapPath        = path.Value;
                                 if (bitMapPath.StartsWith(@"C:\") | bitMapPath.StartsWith(@"D:\")
                                     | bitMapPath.StartsWith(@"E:\") | bitMapPath.StartsWith(@"F:\")
                                     | bitMapPath.StartsWith(@"G:\") | bitMapPath.StartsWith(@"H:\"))
                                 {
                                     changePathMaterial.Add(mat);
                                     oldPath.Add(path.Value);
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
 }
            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));
            }
예제 #9
0
        public static List <TextureBundle> GetTextureBundles(Document doc, out List <string> paths)
        {
            if (_bundleCache.ContainsKey(doc.PathName))
            {
                paths = _texturePathCache[doc.PathName];
                return(_bundleCache[doc.PathName]);
            }
            _texturePathCache.Add(doc.PathName, new List <string>());

            // Find materials
            FilteredElementCollector fec = new FilteredElementCollector(doc).OfClass(typeof(Material));

            // Convert materials to bundles
            List <TextureBundle> bundles = new List <TextureBundle>();

            foreach (var m in fec.Cast <Material>())
            {
                try
                {
                    var bundle = new TextureBundle(m);

                    ElementId appearanceAssetId = m.AppearanceAssetId;
                    AppearanceAssetElement appearanceAssetElem
                        = doc.GetElement(appearanceAssetId)
                          as AppearanceAssetElement;

                    if (appearanceAssetElem == null)
                    {
                        continue;
                    }

                    Asset asset = appearanceAssetElem
                                  .GetRenderingAsset();

                    if (asset == null)
                    {
                        continue;
                    }

                    for (int assetIdx = 0; assetIdx < asset.Size; assetIdx++)
                    {
                        AssetProperty aProperty = asset[assetIdx];
                        if (aProperty.NumberOfConnectedProperties < 1)
                        {
                            continue;
                        }

                        Asset connectedAsset = aProperty
                                               .GetConnectedProperty(0) as Asset;

                        // See if there is a path associated.
#if REVIT2018 || REVIT2019 || REVIT2020
                        // This line is 2018.1 & up because of the
                        // property reference to UnifiedBitmap
                        // .UnifiedbitmapBitmap.  In earlier versions,
                        // you can still reference the string name
                        // instead: "unifiedbitmap_Bitmap"
                        AssetPropertyString path = connectedAsset[
                            UnifiedBitmap.UnifiedbitmapBitmap]
                                                   as AssetPropertyString;
#else
                        AssetPropertyString path =
                            connectedAsset["unifiedbitmap_Bitmap"] as AssetPropertyString;
#endif
                        // If there is no asset path, nothing to pursue (Empty field)
                        if (path == null || String.IsNullOrEmpty(path.Value))
                        {
                            continue;
                        }

                        // See what kind of texture it is.
                        if (TryGetTextureTypeFromAssetName(connectedAsset.Name, out var t))
                        {
                            // This will be a relative path to the
                            // built -in materials folder, addiitonal
                            // render appearance folder, or an
                            // absolute path.
                            string assetName = Path.GetFileNameWithoutExtension(path.Value);

                            // Ensure that we have a valid texture path.
                            if (RevitTextures.ContainsKey(assetName))
                            {
                                bundle.TexturePaths.Add(t, new SafenedFilename(RevitTextures[assetName]));
                            }
                            else
                            {
                                //Logger.LogError(
                                //    $"Found asset outisde of Revit material lib: {path.Value}. Could not add to export"
                                //    );
                            }
                        }
                    }

                    // Return the bundle we created.
                    bundles.Add(bundle);
                }
                catch (Exception e)
                {
                    //Logger.LogException("Error in bundle creation: ", e);
                }
            }

            var bundleList = bundles.Where(b => b != null).ToList();
            _bundleCache.Add(doc.PathName, bundleList);
            paths = _texturePathCache[doc.PathName];

            return(bundleList);
        }
 /// <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);
 }
예제 #11
0
        private XMapping ReadTexture(AssetProperty asset)
        {
            switch (asset.Type)
            {
            case AssetPropertyType.APT_DoubleArray4d:
                TextureType t = TextureType.None;
                switch (asset.Name)
                {
                case "generic_diffuse":
                case "ceramic_color":
                    t = TextureType.Diffuse;
                    break;

                case "generic_bump_map":
                case "ceramic_bump_map":
                    t = TextureType.Normal;
                    break;
                }
                if (t != TextureType.None)
                {
                    IList <AssetProperty> la = asset.GetAllConnectedProperties();
                    if (la.Count > 0)
                    {
                        Asset    a = la[0] as Asset;
                        XMapping m = new XMapping();
                        m.Type = t;
                        XVec2 s = new XVec2();
                        XVec2 o = new XVec2();
                        for (int i = 0; i < a.Size; i++)
                        {
                            AssetProperty _a = a[i];
                            switch (_a.Name)
                            {
                            case "unifiedbitmap_Bitmap":
                                AssetPropertyString aps = _a as AssetPropertyString;
                                string p = aps.Value.Split('|')[0];
                                if (!p.Contains(":"))
                                {
                                    if (p.Contains("/") || p.Contains("\\"))
                                    {
                                        p = Path.Combine(localMap, p);
                                    }
                                    else
                                    {
                                        p = Path.Combine(localMap, localMap1, p);
                                    }
                                }
                                if (texLink.ContainsKey(p))
                                {
                                    m.ID = texLink[p];
                                }
                                else
                                {
                                    if (File.Exists(p))
                                    {
                                        using (FileStream fs = new FileStream(p, FileMode.Open, FileAccess.Read))
                                        {
                                            XTexture tex = new XTexture();
                                            tex.Name = fs.Name;
                                            tex.Data = new byte[fs.Length];
                                            fs.Read(tex.Data, 0, (int)fs.Length);
                                            m.ID = XData.Textures.Count;
                                            texLink.Add(p, m.ID);
                                            XData.Textures.Add(tex);
                                        }
                                    }
                                    else
                                    {
                                        return(null);
                                    }
                                }
                                break;

                            case "texture_RealWorldScaleX":
                                AssetPropertyDistance asx = _a as AssetPropertyDistance;
                                s.x = 1 / (float)UnitUtils.Convert(asx.Value, asx.DisplayUnitType, DisplayUnitType.DUT_DECIMAL_FEET);
                                break;

                            case "texture_RealWorldScaleY":
                                AssetPropertyDistance asy = _a as AssetPropertyDistance;
                                s.y = 1 / (float)UnitUtils.Convert(asy.Value, asy.DisplayUnitType, DisplayUnitType.DUT_DECIMAL_FEET);
                                break;

                            case "texture_RealWorldOffsetX":
                                AssetPropertyDistance aox = _a as AssetPropertyDistance;
                                o.x = s.x * (float)UnitUtils.Convert(aox.Value, aox.DisplayUnitType, DisplayUnitType.DUT_DECIMAL_FEET);
                                break;

                            case "texture_RealWorldOffsetY":
                                AssetPropertyDistance aoy = _a as AssetPropertyDistance;
                                o.y = s.y * (float)UnitUtils.Convert(aoy.Value, aoy.DisplayUnitType, DisplayUnitType.DUT_DECIMAL_FEET);
                                break;
                            }
                        }
                        m.Scale  = s;
                        m.Offset = o;
                        return(m);
                    }
                }
                break;
            }
            return(null);
        }
예제 #12
0
        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");
            }
        }
예제 #13
0
        public void ReadAssetProperty(AssetProperty prop, StreamWriter objWriter)
        {
            switch (prop.Type)
            {
                // Retrieve the value from simple type property is easy.
                // for example, retrieve bool property value.
#if _Revit2018
            case AssetPropertyType.Integer:
#else
            case AssetPropertyType.APT_Integer:
#endif
                var AssetPropertyInt = prop as AssetPropertyInteger;
                objWriter.WriteLine(_priexFix + AssetPropertyInt.Name + "= " + AssetPropertyInt.Value);
                break;

#if _Revit2018
            case AssetPropertyType.Distance:
#else
            case AssetPropertyType.APT_Distance:
#endif
                var AssetPropertyDistance = prop as AssetPropertyDistance;
                objWriter.WriteLine(_priexFix + AssetPropertyDistance.Name + "= " + AssetPropertyDistance.Value);
                break;

#if _Revit2018
            case AssetPropertyType.Float:
#else
            case AssetPropertyType.APT_Float:
#endif
                var assFlot = prop as AssetPropertyFloat;
                objWriter.WriteLine(_priexFix + assFlot.Name + "= " + assFlot.Value);
                break;

#if _Revit2018
            case AssetPropertyType.Double1:
#else
            case AssetPropertyType.APT_Double:
#endif
                var AssetPropertyDouble = prop as AssetPropertyDouble;
                objWriter.WriteLine(_priexFix + AssetPropertyDouble.Name + "= " + AssetPropertyDouble.Value);
                break;

#if _Revit2018
            case AssetPropertyType.Double2:
#else
            case AssetPropertyType.APT_DoubleArray2d:
#endif
                var    AssetPropertyDoubleArray2d = prop as AssetPropertyDoubleArray2d;
                string msg = AssetPropertyDoubleArray2d.Value.Cast <double>().Aggregate(string.Empty, (current, v) => current + (v + ", "));
                objWriter.WriteLine(_priexFix + AssetPropertyDoubleArray2d.Name + "= " + msg);
                break;

#if _Revit2018
            case AssetPropertyType.Double3:
                var arr3d = prop as AssetPropertyDoubleArray3d;
                msg = arr3d.GetValueAsDoubles().Cast <double>().Aggregate(string.Empty, (current, v) => current + (v + ", "));
#else
            case AssetPropertyType.APT_DoubleArray3d:
                var arr3d = prop as AssetPropertyDoubleArray3d;
                msg = arr3d.Value.Cast <double>().Aggregate(string.Empty, (current, v) => current + (v + ", "));
#endif
                objWriter.WriteLine(_priexFix + arr3d.Name + "= " + msg);
                break;

#if _Revit2018
            case AssetPropertyType.Double4:
                var arr4d = prop as AssetPropertyDoubleArray4d;
                msg = arr4d.GetValueAsDoubles().Cast <double>().Aggregate(string.Empty, (current, v) => current + (v + ", "));
#else
            case AssetPropertyType.APT_DoubleArray4d:
                var arr4d = prop as AssetPropertyDoubleArray4d;
                msg = arr4d.Value.Cast <double>().Aggregate(string.Empty, (current, v) => current + (v + ", "));
#endif
                objWriter.WriteLine(_priexFix + arr4d.Name + "= " + msg);
                break;

#if _Revit2018
            case AssetPropertyType.String:
#else
            case AssetPropertyType.APT_String:
#endif
                AssetPropertyString val = prop as AssetPropertyString;
                objWriter.WriteLine(_priexFix + val.Name + "= " + val.Value);
                break;

#if _Revit2018
            case AssetPropertyType.Boolean:
#else
            case AssetPropertyType.APT_Boolean:
#endif
                AssetPropertyBoolean boolProp = prop as AssetPropertyBoolean;
                objWriter.WriteLine(_priexFix + boolProp.Name + "= " + boolProp.Value);
                break;

                // When you retrieve the value from the data array property,
                // you may need to get which value the property stands for.
                // for example, the APT_Double44 may be a transform data.
#if _Revit2018
            case AssetPropertyType.Double44:
#else
            case AssetPropertyType.APT_Double44:
#endif
                AssetPropertyDoubleArray4d transformProp = prop as AssetPropertyDoubleArray4d;
                objWriter.WriteLine(_priexFix + transformProp.Name + "= " + transformProp.Value);
                break;

                // The APT_List contains a list of sub asset properties with same type.
#if _Revit2018
            case AssetPropertyType.List:
#else
            case AssetPropertyType.APT_List:
#endif
                AssetPropertyList     propList = prop as AssetPropertyList;
                IList <AssetProperty> subProps = propList.GetValue();
                if (subProps.Count == 0)
                {
                    break;
                }
                objWriter.WriteLine(_priexFix + propList.Name + " as propList");

                _priexFix += "\t";
                foreach (var ap in subProps)
                {
                    ReadAssetProperty(ap, objWriter);
                }
                _priexFix = _priexFix.Substring(0, _priexFix.Length - 1);

                break;

#if _Revit2018
            case AssetPropertyType.Asset:
#else
            case AssetPropertyType.APT_Asset:
#endif
                Asset propAsset = prop as Asset;
                objWriter.WriteLine(_priexFix + propAsset.Name + " as Asset");
                ReadAsset(propAsset, objWriter);
                break;

#if _Revit2018
            case AssetPropertyType.Enumeration:
#else
            case AssetPropertyType.APT_Enum:
#endif
                var propEnum = prop as AssetPropertyEnum;
                objWriter.WriteLine(_priexFix + propEnum.Name + "= " + propEnum.Value);
                break;

#if _Revit2018
            case AssetPropertyType.Reference:
#else
            case AssetPropertyType.APT_Reference:
#endif
                var propRef = prop as AssetPropertyReference;
                objWriter.WriteLine(_priexFix + prop.Name + " as propReference");
                break;

            default:
                objWriter.WriteLine(_priexFix + "居然有啥都不是类型的" + prop.Type);
                break;
            }

            // Get the connected properties.
            // please notice that the information of many texture stores here.
            if (prop.NumberOfConnectedProperties == 0)
            {
                return;
            }

            objWriter.WriteLine(_priexFix + "Connected Property: ");
            _priexFix += "\t";
            foreach (AssetProperty connectedProp in prop.GetAllConnectedProperties())
            {
                // Note: Usually, the connected property is an Asset.
                ReadAssetProperty(connectedProp, objWriter);
            }
            _priexFix = _priexFix.Substring(0, _priexFix.Length - 1);
        }
예제 #14
0
        /// <summary>
        /// 读取Asset中的各种属性
        /// </summary>
        /// <param name="prop"></param>
        /// <param name="ttrgb"></param>
        public void ReadAssetProperty(AssetProperty prop, string ttrgb)
        {
            switch (prop.Type)
            {
                 
#if R2016
            case AssetPropertyType.APT_Integer:
#elif R2018
            case AssetPropertyType.Integer:
#endif
                var AssetPropertyInt = prop as AssetPropertyInteger;
                break;

#if R2016
            case AssetPropertyType.APT_Distance:
#elif R2018
            case AssetPropertyType.Distance:
#endif
                var AssetPropertyDistance = prop as AssetPropertyDistance;
                break;

#if R2016
            case AssetPropertyType.APT_Double:
#elif R2018
            case AssetPropertyType.Double1:
#endif
                var AssetPropertyDouble = prop as AssetPropertyDouble;
                break;

#if R2016
            case AssetPropertyType.APT_DoubleArray2d:
#elif R2018
            case AssetPropertyType.Double2:
#endif
                var AssetPropertyDoubleArray2d = prop as AssetPropertyDoubleArray2d;
                break;

#if R2016
            case AssetPropertyType.APT_DoubleArray4d:
#elif R2018
            case AssetPropertyType.Double4:
#endif
                var AssetPropertyDoubleArray4d = prop as AssetPropertyDoubleArray4d;
                break;

#if R2016
            case AssetPropertyType.APT_String:
#elif R2018
            case AssetPropertyType.String:
#endif
                AssetPropertyString val = prop as AssetPropertyString;
                if (val.Name == "unifiedbitmap_Bitmap" && val.Value != "")
                {
                    map.Add(ttrgb);
                    map.Add(val.Value.Trim().Replace("\\", ""));
                }

                break;

#if R2016
            case AssetPropertyType.APT_Boolean:
#elif R2018
            case AssetPropertyType.Boolean:
#endif
                AssetPropertyBoolean boolProp = prop as AssetPropertyBoolean;
                break;

#if R2016
            case AssetPropertyType.APT_Double44:
#elif R2018
            case AssetPropertyType.Double44:
#endif
                AssetPropertyDoubleArray4d transformProp = prop as AssetPropertyDoubleArray4d;
#if R2016
                DoubleArray tranformValue = transformProp.Value;
#elif R2018
                DoubleArray tranformValue = (DoubleArray)transformProp.GetValueAsDoubles();
#endif
                break;

                //APT_Lis包含了一系列的子属性值
#if R2016
            case AssetPropertyType.APT_List:
#elif R2018
            case AssetPropertyType.List:
#endif
                AssetPropertyList     propList = prop as AssetPropertyList;
                IList <AssetProperty> subProps = propList.GetValue();
                if (subProps.Count == 0)
                {
                    break;
                }
                switch (subProps[0].Type)
                {
#if R2016
                case AssetPropertyType.APT_Integer:
#elif R2018
                case AssetPropertyType.Integer:
#endif
                    foreach (AssetProperty subProp in subProps)
                    {
                        AssetPropertyInteger intProp = subProp as AssetPropertyInteger;
                        int intValue = intProp.Value;
                    }
                    break;

#if R2016
                case AssetPropertyType.APT_String:
#elif R2018
                case AssetPropertyType.String:
#endif

                    foreach (AssetProperty subProp in subProps)
                    {
                        AssetPropertyString intProp = subProp as AssetPropertyString;
                        string intValue             = intProp.Value;
                        if (intProp.Name == "unifiedbitmap_Bitmap" && intProp.Value != "")
                        {
                            map.Add(ttrgb);
                            map.Add(intProp.Value.Trim().Replace("\\", ""));
                        }
                    }
                    break;
                }
                break;

#if R2016
            case AssetPropertyType.APT_Asset:
#elif R2018
            case AssetPropertyType.Asset:
#endif
                Asset propAsset = prop as Asset;
                for (int i = 0; i < propAsset.Size; i++)
                {
                    ReadAssetProperty(propAsset[i], ttrgb);
                }
                break;

#if R2016
            case AssetPropertyType.APT_Reference:
#elif R2018
            case AssetPropertyType.Reference:
#endif
                break;

            default:
                break;
            }

                        //遍历连接属性,一般位图信息存储在这里  
                        if (prop.NumberOfConnectedProperties == 0)
            {
                return;
            }
            foreach (AssetProperty connectedProp in prop.GetAllConnectedProperties())
            {
                ReadAssetProperty(connectedProp, ttrgb);
            }
        }
예제 #15
0
        public void ReadAssetProperty(AssetProperty prop, StreamWriter objWriter)
        {
            switch (prop.Type)
            {
                // Retrieve the value from simple type property is easy.  
                // for example, retrieve bool property value.  
#if R2016
            case AssetPropertyType.APT_Integer:
#elif R2018
            case AssetPropertyType.Integer:
#endif
                var AssetPropertyInt = prop as AssetPropertyInteger;
                objWriter.WriteLine(AssetPropertyInt.Name + "= " + AssetPropertyInt.Value.ToString() + ";" + AssetPropertyInt.IsReadOnly.ToString());
                break;

#if R2016
            case AssetPropertyType.APT_Distance:
#elif R2018
            case AssetPropertyType.Distance:
#endif
                var AssetPropertyDistance = prop as AssetPropertyDistance;
                objWriter.WriteLine(AssetPropertyDistance.Name + "= " + AssetPropertyDistance.Value + ";" + AssetPropertyDistance.IsReadOnly.ToString());
                break;

#if R2016
            case AssetPropertyType.APT_Double:
#elif R2018
            case AssetPropertyType.Double1:
#endif
                var AssetPropertyDouble = prop as AssetPropertyDouble;
                objWriter.WriteLine(AssetPropertyDouble.Name + "= " + AssetPropertyDouble.Value.ToString() + ";" + AssetPropertyDouble.IsReadOnly.ToString());
                break;

#if R2016
            case AssetPropertyType.APT_DoubleArray2d:
#elif R2018
            case AssetPropertyType.Double2:
#endif
                var AssetPropertyDoubleArray2d = prop as AssetPropertyDoubleArray2d;
                objWriter.WriteLine(AssetPropertyDoubleArray2d.Name + "= " + AssetPropertyDoubleArray2d.Value.ToString() + ";" + AssetPropertyDoubleArray2d.IsReadOnly.ToString());
                break;

#if R2016
            case AssetPropertyType.APT_DoubleArray4d:
#elif R2018
            case AssetPropertyType.Double4:
#endif
                var AssetPropertyDoubleArray4d = prop as AssetPropertyDoubleArray4d;
                objWriter.WriteLine(AssetPropertyDoubleArray4d.Name + "= " + AssetPropertyDoubleArray4d.Value.ToString() + ";" + AssetPropertyDoubleArray4d.IsReadOnly.ToString());
                break;

#if R2016
            case AssetPropertyType.APT_String:
#elif R2018
            case AssetPropertyType.String:
#endif
                AssetPropertyString val = prop as AssetPropertyString;
                objWriter.WriteLine(val.Name + "= " + val.Value + ";" + val.IsReadOnly.ToString());
                break;

#if R2016
            case AssetPropertyType.APT_Boolean:
#elif R2018
            case AssetPropertyType.Boolean:
#endif
                AssetPropertyBoolean boolProp = prop as AssetPropertyBoolean;
                objWriter.WriteLine(boolProp.Name + "= " + boolProp.Value.ToString() + ";" + boolProp.IsReadOnly.ToString());
                break;

                // When you retrieve the value from the data array property,  
                // you may need to get which value the property stands for.  
                // for example, the APT_Double44 may be a transform data.
#if R2016
            case AssetPropertyType.APT_Double44:
#elif R2018
            case AssetPropertyType.Double44:
#endif
                AssetPropertyDoubleArray4d transformProp = prop as AssetPropertyDoubleArray4d;
                DoubleArray tranformValue = transformProp.Value;
                objWriter.WriteLine(transformProp.Name + "= " + transformProp.Value.ToString() + ";" + tranformValue.IsReadOnly.ToString());
                break;

                // The APT_List contains a list of sub asset properties with same type.
#if R2016
            case AssetPropertyType.APT_List:
#elif R2018
            case AssetPropertyType.List:
#endif
                AssetPropertyList     propList = prop as AssetPropertyList;
                IList <AssetProperty> subProps = propList.GetValue();
                if (subProps.Count == 0)
                {
                    break;
                }
                switch (subProps[0].Type)
                {
#if R2016
                case AssetPropertyType.APT_Integer:
#elif R2018
                case AssetPropertyType.Integer:
#endif
                    foreach (AssetProperty subProp in subProps)
                    {
                        AssetPropertyInteger intProp = subProp as AssetPropertyInteger;
                        int intValue = intProp.Value;
                        objWriter.WriteLine(intProp.Name + "= " + intProp.Value.ToString() + ";" + intProp.IsReadOnly.ToString());
                    }
                    break;

#if R2016
                case AssetPropertyType.APT_String:
#elif R2018
                case AssetPropertyType.String:
#endif
                    foreach (AssetProperty subProp in subProps)
                    {
                        AssetPropertyString intProp = subProp as AssetPropertyString;
                        string intValue             = intProp.Value;
                        objWriter.WriteLine(intProp.Name + "= " + intProp.Value.ToString() + ";" + intProp.IsReadOnly.ToString());
                    }
                    break;
                }
                break;

#if R2016
            case AssetPropertyType.APT_Asset:
#elif R2018
            case AssetPropertyType.Asset:
#endif
                Asset propAsset = prop as Asset;
                for (int i = 0; i < propAsset.Size; i++)
                {
                    ReadAssetProperty(propAsset[i], objWriter);
                }
                break;

#if R2016
            case AssetPropertyType.APT_Reference:
#elif R2018
            case AssetPropertyType.Reference:
#endif
                break;

            default:
                objWriter.WriteLine("居然有啥都不是类型的" + prop.Type.ToString());
                break;
            }
                        // Get the connected properties.  
                        // please notice that the information of many texture stores here.  
                        if (prop.NumberOfConnectedProperties == 0)
            {
                return;
            }
            foreach (AssetProperty connectedProp in prop.GetAllConnectedProperties())
            {
                ReadAssetProperty(connectedProp, objWriter);
            }
        }
        void FindTextureBitmapPaths(Document doc)
        {
            // Find materials
            FilteredElementCollector fec
                = new FilteredElementCollector(doc);

            fec.OfClass(typeof(Material));

            IEnumerable <Material> targetMaterials
                = fec.Cast <Material>().Where <Material>(mtl =>
                                                         targetMaterialNames.Contains(mtl.Name));

            foreach (Material material in targetMaterials)
            {
                // Get appearance asset for read
                ElementId appearanceAssetId = material
                                              .AppearanceAssetId;

                AppearanceAssetElement appearanceAssetElem
                    = doc.GetElement(appearanceAssetId)
                      as AppearanceAssetElement;

                Asset asset = appearanceAssetElem
                              .GetRenderingAsset();

                // Walk through all first level assets to find
                // connected Bitmap properties.  Note: it is
                // possible to have multilevel connected
                // properties with Bitmaps in the leaf nodes.
                // So this would need to be recursive.

                int size = asset.Size;
                for (int assetIdx = 0; assetIdx < size; assetIdx++)
                {
                    //AssetProperty aProperty = asset[assetIdx]; // 2018
                    AssetProperty aProperty = asset.Get(assetIdx); // 2019

                    if (aProperty.NumberOfConnectedProperties < 1)
                    {
                        continue;
                    }

                    // Find first connected property.
                    // Should work for all current (2018) schemas.
                    // Safer code would loop through all connected
                    // properties based on the number provided.

                    Asset connectedAsset = aProperty
                                           .GetConnectedProperty(0) as Asset;

                    // We are only checking for bitmap connected assets.

                    if (connectedAsset.Name == "UnifiedBitmapSchema")
                    {
                        // This line is 2018.1 & up because of the
                        // property reference to UnifiedBitmap
                        // .UnifiedbitmapBitmap.  In earlier versions,
                        // you can still reference the string name
                        // instead: "unifiedbitmap_Bitmap"

                        //AssetPropertyString path = connectedAsset[ // 2018
                        //  UnifiedBitmap.UnifiedbitmapBitmap]
                        //    as AssetPropertyString;

                        AssetPropertyString path = connectedAsset // 2019
                                                   .FindByName(UnifiedBitmap.UnifiedbitmapBitmap)
                                                   as AssetPropertyString;

                        // This will be a relative path to the
                        // built -in materials folder, addiitonal
                        // render appearance folder, or an
                        // absolute path.

                        TaskDialog.Show("Connected bitmap",
                                        String.Format("{0} from {2}: {1}",
                                                      aProperty.Name, path.Value,
                                                      connectedAsset.LibraryName));
                    }
                }
            }
        }
예제 #17
0
        IList <string> GetAssetPropValueFromMaterial(AppearanceAssetElement currentAppearance, IList <string> targetList)
        {
            IList <string> valuesToReturn = new List <string>();

            if (currentAppearance != null)
            {
                Asset thisAsset = currentAppearance.GetRenderingAsset();
                if (thisAsset != null)
                {
                    for (int i = 0; i < thisAsset.Size; i++)
                    {
                        AssetProperty currentProp = thisAsset[i];

                        if (currentProp != null)
                        {
                            AssetPropertyString currentPropString = currentProp as AssetPropertyString;
                            if (currentPropString != null)
                            {
                                if (currentPropString.Value != null && currentPropString.Value != "")
                                {
                                    CheckStringAValidTexturePathCorrectItAndAddToList(currentPropString.Value, targetList);
                                }
                            }
                        }

                        IList <AssetProperty> allProp = currentProp.GetAllConnectedProperties();

                        if (allProp != null && allProp.Count > 0)
                        {
                            foreach (AssetProperty currentConnectedProp in allProp)
                            {
#if R2016 || R2017
                                if (currentConnectedProp.Type == AssetPropertyType.APT_Asset)
                                {
                                    Asset currentConnectedAsset = currentConnectedProp as Asset;
                                    if (currentConnectedAsset != null)
                                    {
                                        for (int j = 0; j < currentConnectedAsset.Size; j++)
                                        {
                                            AssetProperty currentConnectedAssetProp = currentConnectedAsset[j];
                                            if (currentConnectedAssetProp != null)
                                            {
                                                AssetPropertyString currentConnectedAssetPropString = currentConnectedAssetProp as AssetPropertyString;
                                                if (currentConnectedAssetPropString != null)
                                                {
                                                    if (currentConnectedAssetPropString.Value != null && currentConnectedAssetPropString.Value != "")
                                                    {
                                                        CheckStringAValidTexturePathCorrectItAndAddToList(currentConnectedAssetPropString.Value, targetList);
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
#else
                                if (currentConnectedProp.Type == AssetPropertyType.Asset)
                                {
                                    Asset currentConnectedAsset = currentConnectedProp as Asset;
                                    if (currentConnectedAsset != null)
                                    {
                                        for (int j = 0; j < currentConnectedAsset.Size; j++)
                                        {
                                            AssetProperty currentConnectedAssetProp = currentConnectedAsset[j];
                                            if (currentConnectedAssetProp != null)
                                            {
                                                AssetPropertyString currentConnectedAssetPropString = currentConnectedAssetProp as AssetPropertyString;
                                                if (currentConnectedAssetPropString != null)
                                                {
                                                    if (currentConnectedAssetPropString.Value != null && currentConnectedAssetPropString.Value != "")
                                                    {
                                                        CheckStringAValidTexturePathCorrectItAndAddToList(currentConnectedAssetPropString.Value, targetList);
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
#endif
                            }
                        }
                    }
                }
            }
            return(valuesToReturn);
        }
예제 #18
0
        //  public void OnDaylightPortal(DaylightPortalNode node)
        //{
        // Like RPCs, Daylight Portals too have their assets available only.
        // THere is no other public API for them currently available.


        //   return;
        //}

        public void OnMaterial(MaterialNode node)
        {
            materialNode = node;
            MessageBuffer mb = new MessageBuffer();

            mb.add(node.MaterialId.IntegerValue);
            mb.add(node.NodeName);
            mb.add(node.Color);
            mb.add((byte)(((100 - (node.Transparency)) / 100.0) * 255));
            Asset asset;

            if (node.HasOverriddenAppearance)
            {
                asset = node.GetAppearanceOverride();
            }
            else
            {
                asset = node.GetAppearance();
            }
            String          textureName = "";
            AssetProperties properties  = asset as AssetProperties;

            for (int index = 0; index < asset.Size; index++)
            {
                if (properties[index].Type == AssetPropertyType.Reference)
                {
                    AssetPropertyReference e = properties[index] as AssetPropertyReference;
                    if (e != null)
                    {
                        AssetProperty p = e.GetConnectedProperty(0);
                        if (p.Type == AssetPropertyType.Asset)
                        {
                            Asset a = p as Asset;
                            if (a != null)
                            {
                                Boolean         foundValidTexture = false;
                                AssetProperties prop = a as AssetProperties;
                                for (int ind = 0; ind < a.Size; ind++)
                                {
                                    if (prop[ind].Name == "unifiedbitmap_Bitmap")
                                    {
                                        AssetPropertyString ps = prop[ind] as AssetPropertyString;
                                        if (ps.Value != "")
                                        {
                                            textureName       = ps.Value;
                                            foundValidTexture = true;
                                        }
                                    }
                                    if (prop[ind].Name == "texture_URepeat")
                                    {
                                        AssetPropertyBoolean ps = prop[ind] as AssetPropertyBoolean;
                                        if (foundValidTexture)
                                        {
                                        }
                                        //textureName = ps.Value;
                                    }
                                    if (prop[ind].Name == "texture_VRepeat")
                                    {
                                        AssetPropertyBoolean ps = prop[ind] as AssetPropertyBoolean;
                                        if (foundValidTexture)
                                        {
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            mb.add(textureName);
            OpenCOVERPlugin.COVER.Instance.sendMessage(mb.buf, OpenCOVERPlugin.COVER.MessageTypes.NewMaterial);

            return;
        }