150 lines
6.0 KiB
C#
150 lines
6.0 KiB
C#
using Autodesk.Revit.DB;
|
|
using Autodesk.Revit.UI;
|
|
using Autodesk.Revit.UI.Selection;
|
|
using KDCS.Utils;
|
|
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Windows.Forms;
|
|
|
|
namespace KMBIM.Revit.Tools.Cmd.Parameter
|
|
{
|
|
[Autodesk.Revit.Attributes.Transaction(Autodesk.Revit.Attributes.TransactionMode.Manual)]
|
|
[Autodesk.Revit.Attributes.Regeneration(Autodesk.Revit.Attributes.RegenerationOption.Manual)]
|
|
[Autodesk.Revit.Attributes.Journaling(Autodesk.Revit.Attributes.JournalingMode.NoCommandData)]
|
|
public class PasteParameterCommand : IExternalCommand
|
|
{
|
|
private UIApplication uiapp = null;
|
|
private UIDocument uidoc = null;
|
|
private Autodesk.Revit.ApplicationServices.Application app = null;
|
|
private Document doc = null;
|
|
|
|
|
|
|
|
public Autodesk.Revit.UI.Result Execute(ExternalCommandData commandData, ref string message, Autodesk.Revit.DB.ElementSet elements)
|
|
{
|
|
if (!WorkMain.GetInstance().IsValid) return Autodesk.Revit.UI.Result.Succeeded;
|
|
Element eSrc = null;
|
|
// Verify active document
|
|
if (null == commandData.Application.ActiveUIDocument.Document)
|
|
{
|
|
message = "현재 활성화된 뷰가 없습니다."; // 현재 활성화된 뷰가 없습니다.
|
|
return Autodesk.Revit.UI.Result.Failed;
|
|
}
|
|
|
|
|
|
uiapp = commandData.Application;
|
|
uidoc = uiapp.ActiveUIDocument;
|
|
app = uiapp.Application;
|
|
doc = uidoc.Document;
|
|
|
|
|
|
|
|
var wm = WorkMain.GetInstance();
|
|
eSrc = wm.CopiedParametersElement;
|
|
try
|
|
{
|
|
if (eSrc == null)// 파라미터를 복사한 경우에만 처리
|
|
{
|
|
MessageBox.Show("이 명령을 실행하기 전에 매개변수를 복사해야 합니다.");
|
|
return Autodesk.Revit.UI.Result.Failed;
|
|
}
|
|
|
|
if (eSrc.IsValidObject != true) // 복사한 파라미터의 소유자(패밀리요소)가 삭제되어 유효하지 않는 경우
|
|
{
|
|
|
|
MessageBox.Show("복사한 파라미터의 소유자(패밀리요소)가 더이상 유효하지 않습니다.");
|
|
return Autodesk.Revit.UI.Result.Failed;
|
|
}
|
|
|
|
var ListElementParameter = wm.CopiedParameters; // 복사한 파라미터
|
|
|
|
|
|
// 복사 대상 요소 선택
|
|
string msg = "매개변수 값을 붙여넣을 패밀리를 선택하십시오.";
|
|
Element eTarget = null;
|
|
while ((eTarget = SelectSingleElement(uidoc, msg)) != null)
|
|
{
|
|
if (eTarget == null) return Autodesk.Revit.UI.Result.Succeeded;
|
|
|
|
if (eTarget == eSrc) continue;
|
|
|
|
using (Transaction tx = new Transaction(doc))
|
|
{
|
|
tx.Start("update-parameter-value");
|
|
Hashtable htTargetParameters = new Hashtable();
|
|
|
|
|
|
var parameters = eTarget.GetOrderedParameters().ToList(); // 복사 대상 파라미터
|
|
htTargetParameters.Clear();
|
|
foreach (var p in parameters)
|
|
{
|
|
string strGroup = Autodesk.Revit.DB.LabelUtils.GetLabelFor(p.Definition.ParameterGroup);
|
|
string strGropAndParameterName = strGroup + "/" + p.Definition.Name;
|
|
if (htTargetParameters.Contains(strGropAndParameterName) == false)
|
|
{
|
|
htTargetParameters.Add(strGropAndParameterName, p);
|
|
}
|
|
}
|
|
|
|
// 기준 요소의 파라미터 값을 대상 요소의 파라미터에 복사한다.
|
|
foreach (Autodesk.Revit.DB.Parameter p in ListElementParameter) // 기준 요소 파라미터
|
|
{
|
|
string strGroup = Autodesk.Revit.DB.LabelUtils.GetLabelFor(p.Definition.ParameterGroup);
|
|
string strGropAndParameterName = strGroup + "/" + p.Definition.Name;
|
|
object oParam = htTargetParameters[strGropAndParameterName];
|
|
if (oParam != null)
|
|
{
|
|
Autodesk.Revit.DB.Parameter curParam = oParam as Autodesk.Revit.DB.Parameter;
|
|
if (curParam.IsReadOnly == false)
|
|
{
|
|
Util.SetParameterValue(curParam, Util.GetParameterValue(p));
|
|
}
|
|
|
|
}//end-if
|
|
}//end-foreach
|
|
tx.Commit();
|
|
}//end-using
|
|
|
|
|
|
}//end-while
|
|
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
message = ex.ToString();
|
|
return Autodesk.Revit.UI.Result.Failed;
|
|
}
|
|
|
|
return Autodesk.Revit.UI.Result.Succeeded;
|
|
}
|
|
|
|
|
|
#region Element Selection
|
|
public static Element SelectSingleElement(UIDocument uidoc, string description)
|
|
{
|
|
if (ViewType.Internal == uidoc.ActiveView.ViewType)
|
|
{
|
|
string msg = "현재 보기에서 요소를 선택할 수 없습니다.";
|
|
TaskDialog.Show("Error", msg + uidoc.ActiveView.Name);
|
|
return null;
|
|
}
|
|
|
|
|
|
try
|
|
{
|
|
Reference r = uidoc.Selection.PickObject(ObjectType.Element, description);
|
|
return uidoc.Document.GetElement(r);
|
|
}
|
|
catch (Autodesk.Revit.Exceptions.OperationCanceledException)
|
|
{
|
|
return null;
|
|
}
|
|
}
|
|
#endregion
|
|
}
|
|
}
|