简体   繁体   English

PostRequestForElementTypePlacement结构墙

[英]PostRequestForElementTypePlacement structural wall

I'm having a problem with the method uidoc.PostRequestForElementTypePlacement() . 我对uidoc.PostRequestForElementTypePlacement()方法有问题。 It seems that the method is always requesting to use the architectural placement instead of the structural one. 似乎该方法总是要求使用体系结构位置而不是结构位置。 Is there any way to call the structural wall/floor placement? 有什么方法可以称呼结构墙/地板位置?

Or is it possible to wait for the user to place with the method en then set the parameter "Structural" to true afterwards? 还是可以等待用户使用方法en放置,然后将参数“ Structural”设置为true? I'm not sure how to do this as the above method does not get executed immediately but instead when the user brings focus back to the Revit view. 我不确定如何执行此操作,因为上述方法不会立即执行,而是在用户将焦点重新带到Revit视图时执行。

Thanks in advance. 提前致谢。

Edit, added minimal code: 编辑,添加了最少的代码:

using System;
using System.Collections.Generic;
using System.Linq;

using Autodesk.Revit.DB;
using Autodesk.Revit.DB.Events;
using Autodesk.Revit.UI;
using Autodesk.Revit.Attributes;

namespace Test2
{
    [TransactionAttribute(TransactionMode.Manual)]
    [RegenerationAttribute(RegenerationOption.Manual)]
    public class Test2 : IExternalCommand
    {
        List<ElementId> addedElementIds = new List<ElementId>();
        UIApplication _uiapp;

        public Result Execute(
            ExternalCommandData commandData,
            ref string message,
            ElementSet elements)
        {
            UIApplication uiApp = commandData.Application;
            Autodesk.Revit.ApplicationServices.Application app = uiApp.Application;
            UIDocument uiDoc = uiApp.ActiveUIDocument;
            Document doc = uiDoc.Document;
            _uiapp = uiApp;

            addedElementIds.Clear();

            WallType wallType = new FilteredElementCollector(doc).OfClass(typeof(WallType)).Cast<WallType>().Last();

            app.DocumentChanged += new EventHandler<DocumentChangedEventArgs>(OnDocumentChanged);

            uiDoc.PostRequestForElementTypePlacement(wallType);

            return Result.Succeeded;
        }

        void OnDocumentChanged(object sender, DocumentChangedEventArgs e)
        {
            addedElementIds.AddRange(e.GetAddedElementIds());

            Autodesk.Revit.ApplicationServices.Application app = _uiapp.Application;
            Document doc = _uiapp.ActiveUIDocument.Document;

            foreach (ElementId id in addedElementIds)
            {
                Element el = doc.GetElement(id);

                el.LookupParameter("Structural").Set(1);
            }

            app.DocumentChanged -= new EventHandler<DocumentChangedEventArgs>(OnDocumentChanged);
        }
    }
}

您可以使用与使用PromptForFamilyInstancePlacement放置族实例所描述的相同的方法,通过DocumentChanged事件来检索新创建的实例。

PostRequestForElementTypePlacement is described as delaying the actual request for placement of the family until "outside of the API". PostRequestForElementTypePlacement被描述为将实际放置族的请求延迟到“ API外部”。 This (based on my experimentation) in a family whose parameters cannot be changed by the same program that placed it, and seems to ignore the event handler ".DocumentChanged" (since the document does not change until after the API is complete). (根据我的实验),该系列的参数不能由放置该参数的同一程序更改,并且似乎忽略了事件处理程序“ .DocumentChanged”(因为直到API完成后文档才更改)。 Note that there is a bug in R2018 (verified by RevitAPIDocs, still there through 2018.3) which prevents "PromptForFamilyInstancePlacement" from being used, since "Esc" is returning a COMPLETE CANCEL to the API -- so there's no way to exit the placement tool without deleting the newly placed element. 请注意,R2018中存在一个错误(已通过RevitAPIDocs验证,直到2018.3为止),由于“ Esc”向API返回了COMPLETE CANCEL,因此阻止了“ PromptForFamilyInstancePlacement”的使用-因此无法退出放置工具而不删除新放置的元素。 So your answer (per Jeremy's answer) is to use "PromptForFamilyInstancePlacement" on pre-2018 code. 因此,您的答案(根据Jeremy的答案)是在2018年前的代码上使用“ PromptForFamilyInstancePlacement”。

(edit) OR BETTER YET, place the "PromptForFamilyInstancePlacement" inside a "try", with a "Catch Exception" -- apparently, this will catch the bogus exception created by the modification of the API. (编辑)或者更好的方法是,将“ PromptForFamilyInstancePlacement”放置在“ try”中,并带有“ Catch Exception”-显然,这将捕获由API修改创建的虚假异常。 This is based on a posting by Jeremy Tamik on another site. 这是基于Jeremy Tamik在另一个网站上发布的内容。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM