12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091 |
- /* ==============================================================================
- * 功能描述:同步幕墙的本地名称、本地编码到幕墙嵌板中?
- * 创 建 者:Garrett
- * 创建日期:2018/7/11 14:34:26
- * ==============================================================================*/
- using System;
- using System.Collections.Generic;
- using System.Collections.ObjectModel;
- using System.Linq;
- using Autodesk.Revit.DB;
- using Saga.PlugIn.ModelCheck;
- using SAGA.DotNetUtils.Extend;
- using SAGA.DotNetUtils.Others;
- using SAGA.RevitUtils.Extends;
- namespace Saga.PlugIn.Other
- {
- /// <summary>
- /// CheckEquipInSpace
- /// </summary>
- public class CopyParameterValue
- {
- public static string AllStr = "All";
- private ObservableCollection<PropertyItem> m_parameterDic;
- private string m_copyFamilyRange;
- public bool SetCopyParameterDic(ObservableCollection<PropertyItem> dic, string copyRange)
- {
- m_parameterDic = dic;
- m_copyFamilyRange = copyRange;
- return (dic.Any()&&!string.IsNullOrWhiteSpace(m_copyFamilyRange));
- }
- public string Execute(Document doc)
- {
- try
- {
- OperateFloor(doc);
- doc.Save();
- }
- catch (Exception e)
- {
- MessageShowBase.Show(e);
- }
- return null;
- }
- private void OperateFloor(Document doc)
- {
- using (Transaction trans = new Transaction(doc, "复制属性"))
- {
- try
- {
- trans.Start();
- var elements = doc.GetFamilyInstances();
- var codes = GetCodes();
- foreach (Element element in elements)
- {
- var code = element.GetFamilyCode();
- if (codes.Contains(AllStr) || code.Contains(code))
- foreach (var pair in m_parameterDic)
- {
- string origin = pair.Name;
- string target = pair.Value;
- if (origin.IsNotNullEmpty() && target.IsNotNullEmpty())
- {
- element.SetParameterValue(target, element.GetParameterString(origin));
- }
- }
- }
- trans.Commit();
- }
- catch (Exception e)
- {
- Console.WriteLine(e);
- }
- }
- }
- private string[] GetCodes()
- {
- var codes = m_copyFamilyRange?.Split(';', ';');
- return codes;
- }
- }
- }
|