首页 > 其他分享 >Revit API创建几何实体Solid并找到与之相交的元素

Revit API创建几何实体Solid并找到与之相交的元素

时间:2023-09-06 15:25:09浏览次数:46  
标签:pt Solid XYZ dBoxLength API new app Revit

几何实体的创建方法之一:
构成封闭底面,指定拉伸方向与拉伸高度。GeometryCreationUtilities

//自创几何实体相交法
[TransactionAttribute(Autodesk.Revit.Attributes.TransactionMode.Manual)]
public class FindIntersectWallsByGeometry : IExternalCommand
{
    public Result Execute(ExternalCommandData commandData, ref string messages, ElementSet elements)
    {

        UIApplication app = commandData.Application;
        Document doc = app.ActiveUIDocument.Document;
        Transaction trans = new Transaction(doc, "ExComm");
        trans.Start();

        //pick a point to draw solid在屏幕上选择一点,找到附近的墙。
        Selection sel = app.ActiveUIDocument.Selection;
        XYZ pt = sel.PickPoint("Please pick a point to get the close walls");

        //XYZ pttemp1 = sel.PickPoint(Autodesk.Revit.UI.Selection.ObjectSnapTypes.None, "Pick leader end...");
        //XYZ pttemp2 = sel.PickPoint(Autodesk.Revit.UI.Selection.ObjectSnapTypes.None, "Pick leader elbow...");

        //
        double dBoxLength = 3;
        //Z值不变,以选择的点为中心,找到矩形四个点。
        XYZ pt1 = new XYZ(pt.X - dBoxLength / 2, pt.Y - dBoxLength / 2, pt.Z);
        XYZ pt2 = new XYZ(pt.X + dBoxLength / 2, pt.Y - dBoxLength / 2, pt.Z);
        XYZ pt3 = new XYZ(pt.X + dBoxLength / 2, pt.Y + dBoxLength / 2, pt.Z);
        XYZ pt4 = new XYZ(pt.X - dBoxLength / 2, pt.Y + dBoxLength / 2, pt.Z);
        //创建四条线。
        Line lineBottom = app.Application.Create.NewLineBound(pt1, pt2);
        Line lineRight = app.Application.Create.NewLineBound(pt2, pt3);
        Line lineTop = app.Application.Create.NewLineBound(pt3, pt4);
        Line lineLeft = app.Application.Create.NewLineBound(pt4, pt1);
        //封闭曲线
        CurveLoop profile = new CurveLoop();
        profile.Append(lineBottom);
        profile.Append(lineRight);
        profile.Append(lineTop);
        profile.Append(lineLeft);

        List<CurveLoop> loops = new List<CurveLoop>();
        loops.Add(profile);
        //创建实体的方法(底面,拉伸方向,拉伸高度)
        XYZ vector = new XYZ(0, 0, 1);
        Solid solid = GeometryCreationUtilities.CreateExtrusionGeometry(loops, vector, 10);

        //相交过滤器
        FilteredElementCollector collector = new FilteredElementCollector(doc);
        ElementIntersectsSolidFilter solidFilter = new ElementIntersectsSolidFilter(solid);

        collector.WherePasses(solidFilter);

        sel.Elements.Clear();
        //Add these interseting element to the selection
        foreach (Element elem in collector)
        {
            sel.Elements.Add(elem);
        }

        trans.Commit();
        return Result.Succeeded;
    }
}

转自博客Revit API创建几何实体Solid并找到与之相交的元素 - 大气象 - 博客园 (cnblogs.com)

 

标签:pt,Solid,XYZ,dBoxLength,API,new,app,Revit
From: https://www.cnblogs.com/shanmu2019/p/17682346.html

相关文章

  • Swagger常见注解@API、@ApiOperation、@ApiParam等
    Swagger2一些常用注解最近遇到了一个使用swagger来生成接口文档的项目,在controller看到了一些没用过的注解(@API、@ApiOperation等),遂记录一下@API使用在类上,表明是swagger资源,@API拥有两个属性:value、tags,源码如下//Iftagsisnotused,thisvaluewillbeusedtoset......
  • 让API开发更高效——Apipost
    作为一款专为API开发设计的工具,Apipost凭借其强大的功能和高效的特点,正逐渐受到越来越多开发者的欢迎。本文将向您详细介绍Apipost的独特优势以及如何让您的API开发更加高效。Apipost适用于所有与API开发相关的从业者,包括但不限于前端工程师、后端工程师、测试工程师和产品经理。无......
  • 让API开发更高效——Apipost
    作为一款专为API开发设计的工具,Apipost凭借其强大的功能和高效的特点,正逐渐受到越来越多开发者的欢迎。本文将向您详细介绍Apipost的独特优势以及如何让您的API开发更加高效。Apipost适用于所有与API开发相关的从业者,包括但不限于前端工程师、后端工程师、测试工程师和产品经理。......
  • 运用手机运营商二要素Api接口,守护您的账户和隐私,让您安心使用!
    随着移动互联网的普及,我们的生活离不开手机,手机成为了我们生活中不可或缺的一部分。但是随着移动支付的普及,手机支付在我们的生活中也变得越来越重要。手机支付是一种方便快捷的支付方式,但是也存在一些安全隐患。如果我们在使用手机支付时不小心泄露了我们的账户和隐私,那么后果不......
  • FastAPI.7
    FastAPI之连接数据库1.databases.pyfromsqlalchemyimportcreate_enginefromsqlalchemy.ormimportsessionmakerfromsqlalchemy.ext.declarativeimportdeclarative_baseSQLALCHEMY_DATABASE_URL='mysql+pymysql://username:password@localhost/fastapi_demo'......
  • FastAPI.6
    FastAPI的Post请求1.接受query参数fromfastapiimportFastAPI,[email protected]('/login')deflogin(username:str=Query(...),password:str=Query(...)):#接受query参数ifusername=='admin'andpassword=='admin':re......
  • 软件开发中的原则 - SOLID
    在软件开发中,前人对软件系统的设计和开发总结了一些原则和模式,不管用什么语言做开发,都将对我们系统设计和开发提供指导意义。本文主要将总结这些常见的原则,和具体阐述意义。开发原则SOILD面向对象的基本原则(solid)是五个,但是在经常被提到的除了这五个之外还有迪米特法则和合......
  • 直播平台开发,WebDriver API模拟首页搜索
    直播平台开发,WebDriverAPI模拟首页搜索在输入框中清除原有的文字内容,并输入指定内容 WebElementinput=driver.findElement(By.id("xxx")); //定位到的元素,id为xxxinput.clear();StringinputString="Selenium";input.sendKeys(inputString); ​单击按钮 WebElem......
  • 直播平台制作,WebDriver API 拖拽页面元素
    直播平台制作,WebDriverAPI拖拽页面元素 importorg.testng.annotations.Test;importorg.openqa.selenium.By;importorg.openqa.selenium.WebDriver;importorg.openqa.selenium.WebElement;importorg.openqa.selenium.chrome.ChromeDriver;importorg.openqa.selenium.int......
  • 干货|API接口测试技巧汇总
    1API接口介绍1.1RPC(远程过程调用)远程过程调用(英语:RemoteProcedureCall,缩写为RPC)是一个计算机通信协议。该协议允许运行于一台计算机的程序调用另一台计算机的子程序,而程序员无需额外地为这个交互作用编程。如果涉及的软件采用面向对象编程,那么远程过程调用亦可称作远程调用......