210 lines
8.0 KiB
C#
210 lines
8.0 KiB
C#
using Autodesk.Revit.UI;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Drawing;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Windows.Media.Imaging;
|
|
using System.Windows.Interop;
|
|
using System.Windows.Forms;
|
|
using Autodesk.Revit.DB;
|
|
|
|
namespace Copy_Zoom
|
|
{
|
|
class App : IExternalApplication
|
|
{
|
|
RibbonItem _button;
|
|
public string _buttonText { get; set; }
|
|
|
|
/// <summary>
|
|
/// Singleton external application class instance.
|
|
/// </summary>
|
|
internal static App _app = null;
|
|
|
|
/// <summary>
|
|
/// Provide access to singleton class instance.
|
|
/// </summary>
|
|
public static App Instance
|
|
{
|
|
get { return _app; }
|
|
}
|
|
|
|
//Revit 실행 시 작동
|
|
public Result OnStartup(UIControlledApplication a)
|
|
{
|
|
//뷰 바꾸는 이벤트 감지
|
|
a.ViewActivated += new EventHandler<Autodesk.Revit.UI.Events.ViewActivatedEventArgs>(OnViewActivated);
|
|
a.ViewActivating += new EventHandler<Autodesk.Revit.UI.Events.ViewActivatingEventArgs>(OnViewActivating);
|
|
|
|
//_app = this;
|
|
|
|
////판넬, 토글 버튼 만들기
|
|
//RibbonPanel panel = a.CreateRibbonPanel("Copy_Zoom");
|
|
|
|
//PushButtonData data = new PushButtonData(
|
|
// "Toggle", "Off", @"C:\test\Copy_Zoom\Copy_Zoom\bin\Debug\Copy_Zoom.dll", "Copy_Zoom.Copy_Zoom_State");
|
|
|
|
//data.AvailabilityClassName = "ToggleButton.Availability";
|
|
|
|
////그림 및 도움말 넣기
|
|
//data.LargeImage = convertFromBitmap(KMBIM2021.Resources.Zoom_Image);
|
|
//data.ToolTip = "뷰 위치를 고정합니다.";
|
|
|
|
//_button = panel.AddItem(data);
|
|
|
|
return Result.Succeeded;
|
|
}
|
|
|
|
/*
|
|
* ViewActivatingEventArgs는 바꾸기 전의 뷰를 가리키고, ViewActivatedEventArgs는 바꾼 뒤의 뷰를 가리킨다.
|
|
* ViewActivatingEventArgs를 사용해 바꾸기 전의 뷰의 좌표를 구해 newZoomCornerList에 저장하고,
|
|
* ViewActivatedEventArgs를 사용해 선택된 다른 뷰에 newZoomCornerList를 붙여 넣는다.
|
|
* 유저가 다른 뷰 선택한 것을 인식하여 계속해서 뷰 정보를 복사해 붙여 넣는다.
|
|
* 이벤트를 사용하기 때문에 토글이 켜져 있으면 뷰가 바뀔때마다 프로그램이 실행되어 이 프로그램이 실행된 뒤에 다른 레빗 기본 명령을 사용할 수 있다.
|
|
*/
|
|
|
|
static IList<UIView> NewActiveViewList = new List<UIView>();
|
|
public IList<XYZ> newZoomCornerList = new List<XYZ>();
|
|
static Autodesk.Revit.DB.View NewcurrentView = null;
|
|
|
|
|
|
// 전환되기 전의 뷰에서 위치 정보를 복사한다.
|
|
public void OnViewActivating(object sender, Autodesk.Revit.UI.Events.ViewActivatingEventArgs args)
|
|
{
|
|
if (KMBIM.Copy_Zoom_State.uidoc == null) return;
|
|
|
|
if (_buttonText == "On")
|
|
{
|
|
//현재 뷰 조사
|
|
NewActiveViewList = KMBIM.Copy_Zoom_State.uidoc.GetOpenUIViews();// 현재 열려 있는 모든 뷰 가져오기
|
|
NewcurrentView = args.CurrentActiveView;
|
|
|
|
newZoomCornerList = NewCopyViewState(NewcurrentView, NewActiveViewList);//현재 뷰 위치 구해서 위치정보 복사
|
|
}
|
|
}
|
|
|
|
// 전환된 후의 뷰에 위에서 복사한 위치 정보를 붙여 넣는다.
|
|
public void OnViewActivated(Object sender, Autodesk.Revit.UI.Events.ViewActivatedEventArgs args)
|
|
{
|
|
if (KMBIM.Copy_Zoom_State.uidoc == null) return;
|
|
|
|
if (_buttonText == "On")
|
|
{
|
|
// 토글 버튼 실행 했을 시의 위치정보와 새롭게 구한 위치 정보가 다르면 새롭게 구한 위치정보를 붙여 넣는다.
|
|
if (newZoomCornerList[0] != KMBIM.Copy_Zoom_State.zoomCornerList[0])
|
|
{
|
|
NewPasteViewState(args.CurrentActiveView, NewActiveViewList, newZoomCornerList);
|
|
}
|
|
|
|
//토글버튼 눌렀을 때의 위치 정보를 가져와야 하기 때문에 전역변수를 사용해서 Copy_Zoom_State에서 정보를 가져와 붙여 넣는다.
|
|
else if (newZoomCornerList[0] == KMBIM.Copy_Zoom_State.zoomCornerList[0])
|
|
{
|
|
KMBIM.Copy_Zoom_State.PasteViewState(KMBIM.Copy_Zoom_State.currentView, KMBIM.Copy_Zoom_State.activeViewList, KMBIM.Copy_Zoom_State.zoomCornerList);
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 토글 버튼 누르고 한번 뷰 바꾼 뒤부터 실행되어 뷰 위치 정보를 가져오는 함수
|
|
/// </summary>
|
|
/// <param name="currentView">현재 뷰</param>
|
|
/// <param name="activeViewList">활성화 되어 있는 뷰 리스트</param>
|
|
/// <returns></returns>
|
|
static public IList<XYZ> NewCopyViewState(Autodesk.Revit.DB.View currentView, IList<UIView> activeViewList)
|
|
{
|
|
UIView currentUIView = null;
|
|
IList<XYZ> newFoundZoomCornerList = new List<XYZ>();
|
|
|
|
//현재 뷰 찾기
|
|
foreach (UIView activeUIView in activeViewList)
|
|
{
|
|
if (activeUIView.ViewId == currentView.Id)
|
|
{
|
|
currentUIView = activeUIView;
|
|
}
|
|
else
|
|
break;
|
|
}
|
|
|
|
if (currentUIView != null)
|
|
{
|
|
//줌 코너 찾기
|
|
newFoundZoomCornerList = currentUIView.GetZoomCorners();
|
|
}
|
|
|
|
return newFoundZoomCornerList;
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 토글 버튼 누르고 한번 뷰 바꾼 뒤부터 실행되어 뷰 위치 정보를 붙여 넣는 함수
|
|
/// </summary>
|
|
/// <param name="currentView">현재 뷰</param>
|
|
/// <param name="activeViewList">활성화 되어 있는 뷰 리스트</param>
|
|
/// <param name="zoomCornerList1">복사한 줌 위치 정보</param>
|
|
static public void NewPasteViewState(Autodesk.Revit.DB.View currentView, IList<UIView> activeViewList, IList<XYZ> zoomCornerList1)
|
|
{
|
|
UIView currentUIView = null;
|
|
//currentView = uiapp.ActiveUIDocument.ActiveView;
|
|
|
|
//현재 뷰 찾기
|
|
if (currentView != null)
|
|
{
|
|
foreach (UIView activeUIView in activeViewList)
|
|
{
|
|
if (activeUIView.ViewId == currentView.Id)
|
|
{
|
|
currentUIView = activeUIView;
|
|
}
|
|
}
|
|
}
|
|
|
|
if (currentUIView != null)
|
|
{
|
|
using (Transaction tr = new Transaction(KMBIM.Copy_Zoom_State.doc))
|
|
{
|
|
tr.Start("start");
|
|
|
|
//zoom 데이터 붙여넣기
|
|
currentUIView.ZoomAndCenterRectangle(zoomCornerList1[0], zoomCornerList1[1]);
|
|
|
|
tr.Commit();
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
private void A_ViewActivated(object sender, Autodesk.Revit.UI.Events.ViewActivatedEventArgs e)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
//Revit 꺼질 때 작동
|
|
public Result OnShutdown(UIControlledApplication a)
|
|
{
|
|
return Result.Succeeded;
|
|
}
|
|
|
|
//토글 버튼 On/Off 교대로 표시되게 하기
|
|
public void Toggle()
|
|
{
|
|
string s = _button.ItemText;
|
|
|
|
_button.ItemText = s.Equals("Off") ? "On" : "Off";
|
|
_buttonText = _button.ItemText;
|
|
}
|
|
|
|
|
|
//토글 버튼에 이미지 넣는 함수
|
|
BitmapSource convertFromBitmap(Bitmap bitmap)
|
|
{
|
|
return Imaging.CreateBitmapSourceFromHBitmap(
|
|
bitmap.GetHbitmap(),
|
|
IntPtr.Zero,
|
|
System.Windows.Int32Rect.Empty,
|
|
BitmapSizeOptions.FromEmptyOptions());
|
|
}
|
|
}
|
|
}
|