154 lines
5.8 KiB
C#
154 lines
5.8 KiB
C#
using Autodesk.Revit.UI;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using Autodesk.Revit.DB;
|
|
using Autodesk.Revit.UI.Selection;
|
|
using System.Threading.Tasks;
|
|
using KDCS.Utils;
|
|
using System.Collections;
|
|
using System.Windows.Forms;
|
|
using Autodesk.Revit.DB.Plumbing;
|
|
using Autodesk.Revit.DB.Mechanical;
|
|
using System.Xml.Linq;
|
|
using Autodesk.Revit.UI.Events;
|
|
using System.IO;
|
|
using KMBIM.Revit.Tools;
|
|
|
|
/// <summary>
|
|
/// Copy view's location and paste on another view that user selected.
|
|
/// Made By 이주호(Lee Juho), DCS Company, South Korea
|
|
/// 2021.06.15 ~ 2021.06.24
|
|
/// </summary>
|
|
|
|
namespace KMBIM
|
|
{
|
|
[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)]
|
|
|
|
/*
|
|
* 토글 버튼 실행 했을 때에는 일단 실행 버튼을 눌렀을 때의 도면 위치 정보를 가져와야 다른 곳에 복사할 수 있기 때문에
|
|
* 현재 뷰 정보를 복사한 뒤, 뷰를 바꾸면 붙여 넣는다.
|
|
* 그 다음부터는 현재 뷰 정보를 다시 복사해서 뷰 바꿀 시에 붙여 넣는다.
|
|
* 이를 토글 버튼이 꺼질 때 까지 계속 반복한다.
|
|
* 제일 첫번째 줄에 해당하는 단계가 여기에 쓰여있고 나머지는 Application에 있음
|
|
*/
|
|
|
|
public class Copy_Zoom_State : IExternalCommand
|
|
{
|
|
static public UIApplication uiapp = null;
|
|
static public UIDocument uidoc = null;
|
|
static public Autodesk.Revit.ApplicationServices.Application app = null;
|
|
static public Document doc = null;
|
|
static public IList<XYZ> zoomCornerList = new List<XYZ>();
|
|
static public IList<UIView> activeViewList = new List<UIView>();
|
|
static public Autodesk.Revit.DB.View currentView = null;
|
|
|
|
public Result Execute(ExternalCommandData commandData, ref string message, Autodesk.Revit.DB.ElementSet elements)
|
|
{
|
|
try
|
|
{
|
|
if (!WorkMain.GetInstance().IsValid) return Autodesk.Revit.UI.Result.Succeeded;
|
|
// Verify active document
|
|
if (null == commandData.Application.ActiveUIDocument.Document)
|
|
{
|
|
message = "현재 활성화된 뷰가 없습니다.";
|
|
return Result.Failed;
|
|
}
|
|
|
|
uiapp = commandData.Application;
|
|
uidoc = uiapp.ActiveUIDocument;
|
|
app = uiapp.Application;
|
|
doc = uidoc.Document;
|
|
|
|
//토글 버튼 만들고 토글 될 때 마다 명령 실행
|
|
App.Instance.Toggle();
|
|
string buttonText = App.Instance._buttonText;
|
|
|
|
if (buttonText == "On")//버튼 텍스트가 On이 되면 명령 실행
|
|
{
|
|
activeViewList = uidoc.GetOpenUIViews();// 현재 열려 있는 모든 뷰 가져오기
|
|
currentView = uiapp.ActiveUIDocument.ActiveView;// 현재 활성화 되어 있는 뷰 가져오기
|
|
|
|
//뷰 복사
|
|
OriginalCopyViewState(currentView, activeViewList);
|
|
}
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
|
|
}
|
|
|
|
return Result.Succeeded;
|
|
}
|
|
|
|
|
|
#region Method
|
|
/// <summary>
|
|
/// 현재 뷰의 위치 정보를 얻는 함수. Toggle button을 On하면 실행된다.
|
|
/// </summary>
|
|
/// <param name="currentView">현재 뷰</param>
|
|
/// <param name="activeViewList">활성화 되어 있는 뷰 리스트</param>
|
|
static public void OriginalCopyViewState(Autodesk.Revit.DB.View currentView, IList<UIView> activeViewList)
|
|
{
|
|
UIView currentUIView = null;
|
|
|
|
//현재 뷰 찾기
|
|
foreach (UIView activeUIView in activeViewList)
|
|
{
|
|
if (activeUIView.ViewId == currentView.Id)// 활성화 되어 있는 뷰와 현재 뷰를 비교해서 Id가 같으면 현재 뷰가 활성화 되어 있는 뷰로 지정
|
|
{
|
|
currentUIView = activeUIView;
|
|
}
|
|
else
|
|
break;
|
|
}
|
|
|
|
if (currentUIView != null)
|
|
{
|
|
//줌 코너 찾기
|
|
zoomCornerList = currentUIView.GetZoomCorners();
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 복사한 뷰 위치 정보를 다른 뷰에 붙여 넣어주는 함수.
|
|
/// </summary>
|
|
/// <param name="currentView">현재 뷰</param>
|
|
/// <param name="activeViewList">활성화 되어 있는 뷰 리스트</param>
|
|
/// <param name="zoomCornerList1">뷰 위치 정보</param>
|
|
static public void PasteViewState(Autodesk.Revit.DB.View currentView, IList<UIView> activeViewList, IList<XYZ> zoomCornerList1)
|
|
{
|
|
UIView currentUIView = null;
|
|
|
|
//현재 뷰 찾기
|
|
if (currentView != null)
|
|
{
|
|
foreach (UIView activeUIView in activeViewList)
|
|
{
|
|
if (activeUIView.ViewId == currentView.Id)
|
|
{
|
|
currentUIView = activeUIView;
|
|
}
|
|
}
|
|
|
|
|
|
if (currentUIView != null)
|
|
{
|
|
using (Transaction tr = new Transaction(doc))
|
|
{
|
|
tr.Start("start");
|
|
|
|
//zoom 데이터 붙여넣기
|
|
currentUIView.ZoomAndCenterRectangle(zoomCornerList[0], zoomCornerList[1]);
|
|
|
|
tr.Commit();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
#endregion
|
|
}
|
|
} |