当前位置:网站首页>Revit secondary development - cut view

Revit secondary development - cut view

2022-07-07 22:22:00 Hey, hey, hey, hey, hey

demand : Draw the section line manually , After drawing, switch to the section view just drawn .

( Provincial users then click to go to the view , Only the first automatic jump , If you adjust the sectioning box, it will no longer jump automatically )ps: There are really all kinds of needs , I'm basically speechless. .

be used DocumentChange Events and external events .

1、 stay DocumentChange Event to listen whether to create a finished cut plane ,

2、 Record the view after creation ID Use external events to convert to the section view just created .

 

External events

public class ViewHandler : IExternalEventHandler
{
    public void Execute(UIApplication app)
    {
        if(Command.gbv_viewSectionid == null) return;
        Document doc = app.ActiveUIDocument.Document;
        ViewSection vs = doc.GetElement(Command.gbv_viewSectionid) as ViewSection;
        app.ActiveUIDocument.ActiveView = vs;
    }
    public string GetName()
    {
        return "view";
    }
}

 

command

class Command
{
    public static ElementId gbv_viewSectionId=null;
    private ExternalEvent viewEvevt=null;
    private bool m_IsCreatedSection = false;
    public Result Execute(ExternalCommandData command)
    {
        UIDocument uiDoc = command.Application.ActiveUIDocument;
        Document doc = uiDoc.Document;
        View view = doc.ActiveView;
        if(view == ViewTye.ThreeD)return Result.Cancelled;
        ViewHandler handler = new ViewHandler();
        viewEvent = ExternalEvent.Create(handler);
        RevitCommandId commandId = RevitCommandId.LookupPostableCommandId(PostableCommand.Section);
        command.Application.PostCommand(commandId);
        command.Application.Application.DocumentChange+=Application_DocumentChange;
        m_IsCreatedSection=true;
    }
    
    privte void Application_DocumentChange(object sender, DocumentChangeEventArgs e)
    {
        if(IsCreatedSection)
        {
            IsCreatedSection = false;
            Document doc = e.GetDocument();
            list<ElementId> lstEid = e.GetAddElementIds().ToList();
            foreach(ElementId eid in lstEid)
            {
                ViewSection vs = doc.GetElement(eid) as ViewSection;
                if(vs != null)
                {
                    gbv_viewSectionid = eid;
                    if(viewEvent != null)
                        viewEvent.Raise();
                    break;
                }
            }
        }
    }
}

 

原网站

版权声明
本文为[Hey, hey, hey, hey, hey]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202130606207159.html