Revit API - c# -如何把焦点放在一个精确的视图



当我点击窗口中的按钮时,我试图将焦点放在计划视图上。要做到这一点,我的点击方法使用另一个方法:SelectCoordinatesEvent(代码如下)。在这个方法中,我将决定专注于一个平面视图,就在调用我的PickPointXYZ()方法之前,该方法用于在Revit上获取一个区域的坐标。

你知道怎么做吗?我很清楚,我是Revit API的初学者。

非常感谢。雨果

public List<XYZ> PickPointXYZ(UIApplication uiapp)
{
XYZ pointXYZ;
List<XYZ> pointsXYZ = new List<XYZ>();
Selection sel = uiapp.ActiveUIDocument.Selection;
ObjectSnapTypes snapTypes = ObjectSnapTypes.Endpoints;
int nbOfSelectedPoints=0;
// I want to put the focus on the view at this moment, juste before the while loop that ask the user to select points on Revit.
//I precise that all my plane view have an Active Workplane set
while (true)

{
try
{
pointXYZ = sel.PickPoint(snapTypes, "Selectionnez les points formant le coutour de la zone de stockage."+"rn"+ "Une fois la sélection terminée, appuyez sur Echap.");
pointsXYZ.Add(pointXYZ);
nbOfSelectedPoints++;
}
catch(Autodesk.Revit.Exceptions.OperationCanceledException e)
{
if (nbOfSelectedPoints < 3)

{
TaskDialog.Show("Erreur - Nombre de points selectionnés", "Vous avez selectionné moins de 3 points."+"rn"+"Veuillez supprimer la zone et recommencer la saisie.", TaskDialogCommonButtons.Close) ;
}
break;
}
catch (Autodesk.Revit.Exceptions.InvalidOperationException e)
{

TaskDialog.Show("Erreur - Vue selectionnée", "Vous avez selectionné une vue qui ne possède pas de Plan de Construction."+"rn"+"Veuillez supprimer la zone et recommencer la saisie dans une vue adaptée.", TaskDialogCommonButtons.Close);
break;
}
catch(Exception e)
{
throw e;

}
}
return pointsXYZ;
}

[System.Runtime.InteropServices.DllImport("user32.dll")]
public static extern int SetForegroundWindow(int hwnd);


窗体提前(uiapp.MainWindowHandle.ToInt32 ());



[System.Runtime.InteropServices.DllImport("user32.dll")]
public static extern int SetForegroundWindow(int hwnd);
public List<XYZ> PickPointXYZ(UIApplication uiapp)
{
SetForegroundWindow(uiapp.MainWindowHandle.ToInt32());
XYZ pointXYZ;
List<XYZ> pointsXYZ = new List<XYZ>();
Selection sel = uiapp.ActiveUIDocument.Selection;
ObjectSnapTypes snapTypes = ObjectSnapTypes.Endpoints;
int nbOfSelectedPoints=0;
// I want to put the focus on the view at this moment, juste before the while loop that ask the user to select points on Revit.
//I precise that all my plane view have an Active Workplane set
while (true)

{
try
{
pointXYZ = sel.PickPoint(snapTypes, "Selectionnez les points formant le coutour de la zone de stockage."+"rn"+ "Une fois la sélection terminée, appuyez sur Echap.");
pointsXYZ.Add(pointXYZ);
nbOfSelectedPoints++;
}
catch(Autodesk.Revit.Exceptions.OperationCanceledException e)
{
if (nbOfSelectedPoints < 3)

{
TaskDialog.Show("Erreur - Nombre de points selectionnés", "Vous avez selectionné moins de 3 points."+"rn"+"Veuillez supprimer la zone et recommencer la saisie.", TaskDialogCommonButtons.Close) ;
}
break;
}
catch (Autodesk.Revit.Exceptions.InvalidOperationException e)
{

TaskDialog.Show("Erreur - Vue selectionnée", "Vous avez selectionné une vue qui ne possède pas de Plan de Construction."+"rn"+"Veuillez supprimer la zone et recommencer la saisie dans une vue adaptée.", TaskDialogCommonButtons.Close);
break;
}
catch(Exception e)
{
throw e;

}
}
return pointsXYZ;
}

听起来这段代码可能是从按钮单击处理程序执行的。如果是这样,你应该使用Revit的IExternalEventHandler来代替。

https://knowledge.autodesk.com/support/revit-products/learn-explore/caas/CloudHelp/cloudhelp/2014/ENU/Revit/files/GUID-0A0D656E-5C44-49E8-A891-6C29F88E35C0-htm.html

最新更新