Exemple #1
0
        //KeyBoardHook KeyBoarHook;
        //void Unhook()
        //{
        //    if (KeyBoarHook != null)
        //    {
        //        KeyBoarHook.UnHook();
        //        KeyBoarHook.OnKeyDownEvent -= KeyBoarHook_OnKeyDownEvent;
        //        GC.Collect();//增加GC防止窗体关闭后,钩子未被卸载.
        //    }
        //}

        //void Hook()
        //{
        //    KeyBoarHook = new KeyBoardHook();
        //    KeyBoarHook.SetHook();
        //    KeyBoarHook.OnKeyDownEvent += KeyBoarHook_OnKeyDownEvent;
        //}

        ///// <summary>
        ///// 钩子事件,监听ESC关闭窗体
        ///// </summary>
        ///// <param name="sender"></param>
        ///// <param name="e"></param>
        ///// <returns></returns>
        //int KeyBoarHook_OnKeyDownEvent(object sender, System.Windows.Forms.KeyEventArgs e)
        //{
        //    if (ViewModel != null && ViewModel.IsIdling && e.KeyData == System.Windows.Forms.Keys.Escape)
        //    {
        //        ViewModel.Close();
        //        return 1;
        //    }
        //    return 0;
        //}
        #endregion

        #region Mouse
        /// <summary>
        ///  Try Catch 流程模板
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="func"></param>
        /// <param name="onError"></param>
        /// <returns></returns>
        public static bool DelegateMouseHook(Action action)
        {
            using (PmSoft.Common.RevitClass.PickObjectsMouseHook MouseHook = new PmSoft.Common.RevitClass.PickObjectsMouseHook())
            {
                MouseHook.InstallHook(PmSoft.Common.RevitClass.PickObjectsMouseHook.OKModeENUM.Objects);
                try
                {
                    action();
                    MouseHook.UninstallHook();
                    return(true);
                }
                catch (Exception ex)
                {
                    MouseHook.UninstallHook();
                    return(false);
                }
            }
        }
Exemple #2
0
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            //try
            //{
            //    StringBuilder sb = new StringBuilder();
            //    UIDocument uidoc = commandData.Application.ActiveUIDocument;
            //    Selection selection = uidoc.Selection;
            //    var elementIds = selection.GetElementIds();
            //    foreach (var elementId in elementIds)
            //    {
            //        var element =uidoc.Document.GetElement(elementId);
            //        sb.AppendLine($"{element.Name}");
            //    }
            //    TaskDialog.Show("vl selected elements", sb.ToString());
            //}
            //catch (Exception ex)
            //{
            //    message = ex.Message;
            //    return Result.Failed;
            //}
            //return Result.Succeeded;



            PmSoft.Common.RevitClass.PickObjectsMouseHook mouseHook = new PmSoft.Common.RevitClass.PickObjectsMouseHook();
            try
            {
                mouseHook.InstallHook();
                //1TODO 过滤选梁
                var selectedId = commandData.Application.ActiveUIDocument.Selection.PickObject(ObjectType.Element, new BeamFramingFilter()).ElementId.IntegerValue;
                TaskDialog.Show("1", selectedId.ToString());
            }
            catch
            {
                mouseHook.UninstallHook();
            }
            mouseHook.UninstallHook();
            return(Result.Succeeded);
        }
Exemple #3
0
        public override void Execute()
        {
            var viewType = (CSAViewType)Enum.Parse(typeof(CSAViewType), ViewType.ToString());

            switch (viewType)
            {
            case CSAViewType.Idle:
                View = new CompoundStructureAnnotationWindow(this);
                IntPtr rvtPtr = Autodesk.Windows.ComponentManager.ApplicationWindow;
                WindowInteropHelper helper = new WindowInteropHelper(View);
                helper.Owner = rvtPtr;
                View.ShowDialog();
                break;

            case CSAViewType.Select:
                if (View.IsActive)
                {
                    View.Close();
                }
                using (PmSoft.Common.RevitClass.PickObjectsMouseHook MouseHook = new PmSoft.Common.RevitClass.PickObjectsMouseHook())
                {
                    MouseHook.InstallHook(PmSoft.Common.RevitClass.PickObjectsMouseHook.OKModeENUM.Objects);
                    try
                    {
                        Model.TargetId = UIDocument.Selection.PickObject(ObjectType.Element
                                                                         , new VLClassesFilter(false, typeof(Wall), typeof(Floor), typeof(ExtrusionRoof), typeof(FootPrintRoof))).ElementId;
                        MouseHook.UninstallHook();
                        ViewType = (int)CSAViewType.Generate;
                    }
                    catch (Exception ex)
                    {
                        MouseHook.UninstallHook();
                        ViewType = (int)CSAViewType.Idle;
                    }
                }
                break;

            case CSAViewType.Generate:
                var doc = UIDocument.Document;
                if (VLTransactionHelper.DelegateTransaction(doc, "生成结构标注", () =>
                {
                    var element = doc.GetElement(Model.TargetId);
                    var Collection = CSAContext.GetCollection(doc);
                    //避免重复生成 由于一个对象可能在不同的视图中进行标注设置 所以还是需要重复生成的
                    var existedModel = Collection.Data.FirstOrDefault(c => c.TargetId.IntegerValue == Model.TargetId.IntegerValue);
                    if (existedModel != null)
                    {
                        Collection.Data.Remove(existedModel);
                        CSAContext.Creator.Clear(doc, existedModel);
                    }
                    var fontScale = 1 / VLConstraintsForCSA.OrientFontSizeScale * Model.CurrentFontSizeScale;
                    Model.LineWidth = UnitHelper.ConvertToFoot(Model.CSALocationType.GetLineWidth() * fontScale, VLUnitType.millimeter);
                    CSAContext.Creator.Generate(doc, Model, element);
                    Collection.Data.Add(Model);
                    Collection.Save(doc);
                    return(true);
                }))
                {
                    ViewType = (int)CSAViewType.Select;
                }
                else
                {
                    ViewType = (int)CSAViewType.Idle;
                }
                break;

            case CSAViewType.Close:
                View.Close();
                break;

            case CSAViewType.Closing:
            default:
                break;
            }
        }