// [END add_asset]

        // [START add_asset_set]
        /// <summary>
        /// Creates the asset set.
        /// </summary>
        /// <param name="client">The Google Ads client.</param>
        /// <param name="customerId">The Google Ads customer ID.</param>
        /// <returns>The resource name of the asset set.</returns>
        private string CreateAssetSet(GoogleAdsClient client, long customerId)
        {
            AssetSetServiceClient assetSetService = client.GetService(
                Services.V10.AssetSetService);

            // Creates an AssetSet which will be used to link the dynamic remarketing assets
            // to a campaign.
            AssetSet assetSet = new AssetSet()
            {
                Name = "My dynamic remarketing assets " + ExampleUtilities.GetRandomString(),
                Type = AssetSetType.DynamicEducation
            };

            // Creates an operation to add the link.
            AssetSetOperation operation = new AssetSetOperation()
            {
                Create = assetSet
            };
            // Sends the mutate request.
            MutateAssetSetsResponse response = assetSetService.MutateAssetSets(
                customerId.ToString(), new[] { operation });
            // Prints some information about the response.
            string resourceName = response.Results[0].ResourceName;

            Console.WriteLine($"Created asset set with resource name {resourceName}.");
            return(resourceName);
        }
Exemple #2
0
 void RefreshFetchCoroutines()
 {
     if (App.GoogleIdentity.Profile != null)
     {
         m_AssetSetByType[PolySetType.User].m_RefreshRequested  = true;
         m_AssetSetByType[PolySetType.Liked].m_RefreshRequested = true;
     }
     else
     {
         AssetSet set = m_AssetSetByType[PolySetType.User];
         if (set.m_FetchMetadataCoroutine != null)
         {
             StopCoroutine(set.m_FetchMetadataCoroutine);
             set.m_FetchMetadataCoroutine = null;
         }
         set.m_Models.Clear();
         set = m_AssetSetByType[PolySetType.Liked];
         if (set.m_FetchMetadataCoroutine != null)
         {
             StopCoroutine(set.m_FetchMetadataCoroutine);
             set.m_FetchMetadataCoroutine = null;
         }
         set.m_Models.Clear();
         if (CatalogChanged != null)
         {
             CatalogChanged();
         }
     }
 }
Exemple #3
0
        public static void GetMaterialTexture(Material mtl, AssetSet builtinLibrary, out string diffuseTexture, out string bumpTexture, out double scaleX, out double scaleY,
            out double metallic, out double smoothness)
        {
            diffuseTexture = string.Empty;
            bumpTexture = string.Empty;
            scaleX = 1.0;
            scaleY = 1.0;
            metallic = 0.0;
            smoothness = 0.5;

            var assetElementId = mtl.AppearanceAssetId;
            if (assetElementId == ElementId.InvalidElementId)
                return;

            var objassetElement = mtl.Document.GetElement(assetElementId) as AppearanceAssetElement;
            if (objassetElement == null)
                return;

            var curAsset = objassetElement.GetRenderingAsset();
            if (curAsset.Size == 0)
            {
                curAsset = (from Asset asset in builtinLibrary
                            where asset.Name == curAsset.Name && asset.LibraryName == curAsset.LibraryName
                            select asset).FirstOrDefault();
            }

            if (curAsset != null)
                ReadTextureFromAsset(curAsset, out diffuseTexture, out bumpTexture, out scaleX, out scaleY, out metallic, out smoothness);
        }
        //private void TryLoadAsset(string abName, string assetName, Action<UnityEngine.Object> _beignAction, Action<UnityEngine.Object> _loadingAction, Action<UnityEngine.Object> _overAction, Type loadType)
        //{
        //    AssetSet abset = new AssetSet
        //    {
        //        abName = abName.ToLower(),
        //        assetName = assetName,
        //        returnType = AssetBundleReturnType.Prefab,
        //        loadType = loadType,
        //        OnLoadBeign = _beignAction,
        //        OnLoading = _loadingAction,
        //        OnLoadOver = _overAction
        //    };
        //    AddSetToAssetBundleQueue(abset);
        //}
/// <summary>
/// 查询资源包(加载)
/// </summary>
        private void Load()
        {
            if (assetBundleQueue.Count > 0)
            {
                AssetSet assetSet = assetBundleQueue.Dequeue();
                assetSet.OnLoadBeign();//开始加载动画界面
                if (ABundleDic.ContainsKey(assetSet.abName))
                {
                    Debug.Log("加载到ab包:" + assetSet.abName);
                    AssetBundle assetBundle = ABundleDic[assetSet.abName];
                    if (assetBundle != null)
                    {
                        GameObject obj = assetBundle.LoadAsset <GameObject>(assetSet.assetName);
                        assetSet.OnLoadOver(obj);
                    }
                }
                else
                {
                    Debug.Log("开始加载:" + assetSet.abName);
                    StartCoroutine(LoadABundle(assetSet.abName, () => {
                        AddSetToAssetBundleQueue(assetSet);
                        Load();
                    }));
                }
            }
        }
Exemple #5
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();
        }
Exemple #6
0
        public static Color DefaultColor = new Color(127, 127, 127);    //默认灰色

        /// <summary>
        /// 导出三维视图,调用CustomExporter.Export
        /// </summary>
        /// <param name="view3d"></param>
        /// <param name="filename"></param>
        public void ExportView3D(View3D view3d, string filename, AssetSet objlibraryAsset)
        {
            Document         doc      = view3d.Document;
            RvtExportContext context  = new RvtExportContext(doc, filename, objlibraryAsset);
            CustomExporter   exporter = new CustomExporter(doc, context);

            exporter.ShouldStopOnError = false;
            exporter.Export(view3d);
        }
Exemple #7
0
        public async Task <InvokeResult> UpdateAssetSetAsync(AssetSet assetSet, EntityHeader org, EntityHeader user)
        {
            await AuthorizeAsync(assetSet, AuthorizeActions.Update, user, org);

            ValidationCheck(assetSet, Actions.Create);
            await _assetSetRepo.UpdateAssetSetAsync(assetSet);

            return(InvokeResult.Success);
        }
Exemple #8
0
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            if (FilesOption())
            {
                foreach (var file in files)
                {
                    string     codeBase        = Assembly.GetExecutingAssembly().CodeBase;
                    UriBuilder uri             = new UriBuilder(codeBase);
                    string     path            = Uri.UnescapeDataString(uri.Path);
                    var        placeholderFile = Path.GetDirectoryName(path) + @"\placeholderFile.rte";

                    UIApplication uiapp = commandData.Application;
                    UIDocument    uidoc = uiapp.OpenAndActivateDocument(file);
                    Autodesk.Revit.ApplicationServices.Application app = uiapp.Application;
                    Document doc             = uidoc.Document;
                    AssetSet objlibraryAsset = app.get_Assets(AssetType.Appearance);

                    #region///判断是否为空视图,若为空视图,切换为3d视图
                    View3D view = doc.ActiveView as View3D;
                    if (null == view)
                    {
                        IEnumerable <ViewFamilyType> viewFamilyTypes = from elem in new FilteredElementCollector(doc).OfClass(typeof(ViewFamilyType))
                                                                       let type = elem as ViewFamilyType
                                                                                  where type.ViewFamily == ViewFamily.ThreeDimensional
                                                                                  select type;
                        Transaction ts = new Transaction(doc, "Change3D");
                        try
                        {
                            ts.Start();
                            XYZ    direction = new XYZ(-1, 1, -1);
                            View3D view3D    = View3D.CreateIsometric(doc, viewFamilyTypes.First().Id);
                            //View3D view3D = uiDoc.Document.Create.NewView3D(new XYZ(-1, 1, -1));//斜视45度
                            ts.Commit();
                            //切换视图必须在事务结束后,否则会提示错误:
                            //Cannot change the active view of a modifiable document
                            uidoc.ActiveView = view3D;
                        }
                        catch (Exception ex)
                        {
                            TaskDialog.Show("ex", ex.ToString());
                            ts.RollBack();
                        }
                        //Util.ErrorMsg("You must be in a 3D view to export.");
                    }
                    #endregion

                    ExportView3D(doc.ActiveView as View3D, CreatFilePath(doc), objlibraryAsset);

                    //通过占位文件关闭当前文件
                    var docPlaceholder = commandData.Application.OpenAndActivateDocument(placeholderFile);
                    doc.Close(false);
                }
                MessageBox.Show("导出成功!", "通知");
            }
            return(Result.Succeeded);
        }
Exemple #9
0
        public void find_all_scripts_if_just_referring_to_script_files()
        {
            var theSet = new AssetSet();

            theSet.Add("a");
            theSet.Add("b");
            theSet.Add("c");

            theSet.FindScripts(theGraph);

            theSet.AllFileDependencies().Select(x => x.Name).ShouldHaveTheSameElementsAs("a", "b", "c");
        }
Exemple #10
0
        /// <summary>
        /// 加载外观元素到文档中
        /// </summary>
        /// <param name="revitApp"></param>
        public static void loadAppearance(Autodesk.Revit.ApplicationServices.Application revitApp, Document doc, Material mat)
        {
            AssetSet theAssets = revitApp.get_Assets(AssetType.Appearance);

            foreach (Asset theAsset in theAssets)
            {
                // AppearanceAssetElement assetElem = AppearanceAssetElement.Create(doc, "haipi", theAsset);

                // FilteredElementCollector cotr = new FilteredElementCollector(doc);
                //     IEnumerable<AppearanceAssetElement> allApperar = cotr.OfClass(typeof(AppearanceAssetElement)).Cast<AppearanceAssetElement>();
                // mat.AppearanceAssetId = allApperar.First<AppearanceAssetElement>().Id;
            }
        }
Exemple #11
0
        public void find_all_scripts_if_the_set_refers_to_another_set()
        {
            theGraph.AddToSet("1", "A");
            theGraph.AddToSet("1", "B");
            theGraph.AddToSet("1", "C");

            var theSet = new AssetSet();

            theSet.Add("1");

            theGraph.AssetSetFor("1").FindScripts(theGraph);
            theSet.FindScripts(theGraph);

            theSet.AllFileDependencies().Select(x => x.Name).ShouldHaveTheSameElementsAs("A", "B", "C");
        }
Exemple #12
0
        public void find_all_scripts_from_a_mix_of_files_and_sets()
        {
            theGraph.AddToSet("1", "A");
            theGraph.AddToSet("1", "B");
            theGraph.AddToSet("1", "C");

            var theSet = new AssetSet();

            theSet.Add("1");
            theSet.Add("D");

            theGraph.AssetSetFor("1").FindScripts(theGraph);
            theSet.FindScripts(theGraph);

            theSet.AllFileDependencies().Select(x => x.Name).ShouldHaveTheSameElementsAs("A", "B", "C", "D");
        }
Exemple #13
0
        public void should_be_after_bouncing_through_a_set()
        {
            var s1 = new FileDependency("1");
            var s2 = new FileDependency("2");
            var s3 = new FileDependency("3");

            var set = new AssetSet();

            set.Add(s1);

            s2.AddDependency(set);
            s3.AddDependency(s2);

            s3.MustBeAfter(s1).ShouldBeTrue();
            s3.MustBeAfter(s2).ShouldBeTrue();
        }
Exemple #14
0
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            UIApplication uiapp = commandData.Application;
            UIDocument    uidoc = commandData.Application.ActiveUIDocument;

            Autodesk.Revit.ApplicationServices.Application app = uiapp.Application;
            Document doc = uidoc.Document;

            AssetSet objlibraryAsset = app.get_Assets(AssetType.Appearance);

            ///判断是否为空视图
            View3D view = doc.ActiveView as View3D;

            if (null == view)
            {
                Util.ErrorMsg("You must be in a 3D view to export.");
            }
            try
            {
                FolderBrowserDialog dialog = new FolderBrowserDialog();
                dialog.Description = "请选择文件保存路径";
                if (dialog.ShowDialog() == DialogResult.OK)
                {
                    foldPath = dialog.SelectedPath;
                }
                string filename = doc.PathName;
                if (0 == filename.Length)
                {
                    filename = doc.Title;
                }
                filename = Path.GetFileNameWithoutExtension(filename) + ".obj";
                string subPath = foldPath + "\\" + Path.GetFileNameWithoutExtension(filename);
                if (!Directory.Exists(subPath))
                {
                    Directory.CreateDirectory(subPath);
                }
                filename = Path.Combine(subPath + "\\" + filename);

                ExportView3D(doc.ActiveView as View3D, filename, objlibraryAsset);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
            return(Result.Succeeded);
        }
Exemple #15
0
        public void find_all_scripts_2_deep_child_sets_with_files()
        {
            theGraph.AddToSet("1", "A");
            theGraph.AddToSet("1", "B");
            theGraph.AddToSet("1", "2");
            theGraph.AddToSet("2", "C");
            theGraph.AddToSet("2", "D");

            var theSet = new AssetSet();

            theSet.Add("1");
            theSet.Add("E");

            theGraph.AssetSetFor("1").FindScripts(theGraph);
            theGraph.AssetSetFor("2").FindScripts(theGraph);
            theSet.FindScripts(theGraph);

            theSet.AllFileDependencies().Select(x => x.Name).ShouldHaveTheSameElementsAs("A", "B", "C", "D", "E");
        }
Exemple #16
0
        public void should_not_return_duplicates()
        {
            theGraph.AddToSet("1", "A");
            theGraph.AddToSet("1", "B");
            theGraph.AddToSet("1", "2");
            theGraph.AddToSet("2", "C");
            theGraph.AddToSet("2", "D");

            var theSet = new AssetSet();

            theSet.Add("1");
            theSet.Add("2");
            theSet.Add("E");

            theGraph.AssetSetFor("1").FindScripts(theGraph);
            theGraph.AssetSetFor("2").FindScripts(theGraph);
            theSet.FindScripts(theGraph);

            theSet.AllFileDependencies().Select(x => x.Name).ShouldHaveTheSameElementsAs("A", "B", "C", "D", "E");
        }
Exemple #17
0
        private void ReadMaterialAppearanceProp()
        {
            var      message   = new StringBuilder();
            Document doc       = this.ActiveUIDocument.Document;
            var      app       = this.ActiveUIDocument.Document.Application;
            var      materials = new FilteredElementCollector(doc).OfClass(typeof(Material)).ToList();

            foreach (Material material in materials)
            {
                try
                {
                    var    appearanceId   = material.AppearanceAssetId;
                    var    appearanceElem = doc.GetElement(appearanceId) as AppearanceAssetElement;
                    Asset  theAsset       = appearanceElem.GetRenderingAsset();
                    string libraryName    = theAsset.LibraryName;
                    string title          = theAsset.Title;

                    // The predefined asset can be empty. at this time, get the system appearance asset instead.
                    if (theAsset.Size == 0)
                    {
                        AssetSet systemAppearanceAssets = doc.Application.get_Assets(AssetType.Appearance);
                        foreach (Asset systemAsset in systemAppearanceAssets)
                        {
                            if (theAsset.LibraryName == systemAsset.LibraryName &&
                                theAsset.Name == systemAsset.Name)
                            {
                                message.AppendLine(systemAsset.FindByName("generic_diffusion").ToString());
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    message.AppendLine(material.Name.ToString() + " - " + ex.Message);
                }
            }

            TaskDialog.Show("Read material Properties", message.ToString());
        }
 /// <summary>
 /// 将assetSet对象加入队列
 /// </summary>
 /// <param name="assetSet"></param>
 private void AddSetToAssetBundleQueue(AssetSet assetSet)
 {
     assetBundleQueue.Enqueue(assetSet);
 }
Exemple #19
0
 public RvtExportContext(Document doc, string filename, AssetSet objlibraryAsset)
 {
     this._doc             = doc;
     this._filename        = filename;
     this._objlibraryAsset = objlibraryAsset;
 }
Exemple #20
0
        public bool Export(AssetSet appearanceAssetSet, View3D view, ExportSetting setting, out Exception ex)
        {
            ex = new Exception();

            try
            {
                ConvertEntity converter = new ConvertEntity();
                converter.ExportSetting = setting;
                if (setting.SystemSetting.IsExportRebar)
                {
                    converter.Rebars = Tools.GetRebaresInDocument(view.Document);
                }
                else
                {
                    ElementColorOverride colorOverride = new ElementColorOverride();
                    if (!setting.SystemSetting.IsOriginMaterial && !view.Document.IsFamilyDocument)
                    {
                        colorOverride.ArrangeElemlentColor(view.Document, view);
                    }

                    RevitEnvironmentSetting envSetting = new RevitEnvironmentSetting(view.Document);
                    if (setting.SystemSetting.IsModifyUnit)
                    {
                        envSetting.ReadOriginUnitsAndSetNew();
                    }

                    ModelExportContext context = new ModelExportContext(view.Document);
                    context.ExportSetting = setting;
                    context.BuiltInMaterialLibraryAsset = appearanceAssetSet;
                    context.IsPackageEntityToBlock      = true;
                    context.ExtraMaterial            = colorOverride.GetMaterials();
                    context.ExtraElementColorSetting = colorOverride.GetElementColorSetting();
                    context.IsOptimisePipeEntity     = true;
                    CustomExporter exporter = new CustomExporter(view.Document, context);

                    //exporter.IncludeFaces = false;

                    exporter.ShouldStopOnError = false;
                    exporter.Export(view);

                    if (setting.SystemSetting.IsModifyUnit)
                    {
                        envSetting.RecoverOriginUnits();
                    }

                    converter.Materials  = context.Materials;
                    converter.ModelBlock = context.ModelSpaceBlock;
                    converter.DictBlocks = context.DictBlocks;
                    converter.Levels     = Tools.GetLevelsFromDocument(view.Document);
                    if (setting.SystemSetting.IsExportGrid)
                    {
                        converter.Grids = Tools.GetGridFromDocument(view.Document);
                    }
                }

                converter.WndParent = new WindowHandle(Process.GetCurrentProcess().MainWindowHandle);
                converter.BeginConvert();
            }
            catch (Exception e)
            {
                ex = e;
                return(false);
            }

            return(true);
        }