Revit API创建标高,单位转换
一业内朋友让我写个快速创建标高的插件。
//创建标高
[TransactionAttribute(Autodesk.Revit.Attributes.TransactionMode.Manual)]
public class cmdDrawLevel : IExternalCommand
{
public Result Execute(ExternalCommandData commandData, ref string messages, ElementSet elements)
{
UIApplication app = commandData.Application;
Document doc = app.ActiveUIDocument.Document;
Selection sel = app.ActiveUIDocument.Selection;
try
{
Transaction ts = new Transaction(doc, "revit");
ts.Start();
//起始,间距,数量,前缀
double dStart = RevitTools.Unit.CovertToAPI(double.Parse(XmlTools.levelStart), DisplayUnitType.DUT_METERS);
double dDis = RevitTools.Unit.CovertToAPI(double.Parse(XmlTools.levelDis), DisplayUnitType.DUT_METERS);
int iNum = int.Parse(XmlTools.levelNum);
//创建起始标高
Level levelStart = doc.Create.NewLevel(dStart);
levelStart.Name = XmlTools.levelPre + ;
//
for (int i = ; i <= iNum; i++)
{
Level level = doc.Create.NewLevel(dStart + i * dDis);
level.Name = XmlTools.levelPre + (i + );
} ts.Commit();
}
catch (Exception ex)
{
TaskDialog.Show("error", "请检查是否命名重复。");
} return Result.Succeeded;
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text; namespace RevitCodes
{
class XmlTools
{
public static string levelStart = "";
public static string levelDis = "";
public static string levelNum = "";
public static string levelPre = "F";
}
}
//
// (C) Copyright 2003-2010 by Autodesk, Inc.
//
// Permission to use, copy, modify, and distribute this software in
// object code form for any purpose and without fee is hereby granted,
// provided that the above copyright notice appears in all copies and
// that both that copyright notice and the limited warranty and
// restricted rights notice below appear in all supporting
// documentation.
//
// AUTODESK PROVIDES THIS PROGRAM "AS IS" AND WITH ALL FAULTS.
// AUTODESK SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTY OF
// MERCHANTABILITY OR FITNESS FOR A PARTICULAR USE. AUTODESK, INC.
// DOES NOT WARRANT THAT THE OPERATION OF THE PROGRAM WILL BE
// UNINTERRUPTED OR ERROR FREE.
//
// Use, duplication, or disclosure by the U.S. Government is subject to
// restrictions set forth in FAR 52.227-19 (Commercial Computer
// Software - Restricted Rights) and DFAR 252.227-7013(c)(1)(ii)
// (Rights in Technical Data and Computer Software), as applicable.
// using System;
using System.Collections.Generic;
using System.Text;
using Autodesk.Revit.DB;
using System.Configuration;
using System.Reflection; namespace RevitTools
{
/// <summary>
/// Provides static functions to convert unit
/// </summary>
static class Unit
{
#region Methods
/// <summary>
/// Convert the value get from RevitAPI to the value indicated by DisplayUnitType
/// </summary>
/// <param name="to">DisplayUnitType indicates unit of target value</param>
/// <param name="value">value get from RevitAPI</param>
/// <returns>Target value</returns>
public static double CovertFromAPI(DisplayUnitType to, double value)
{
return value *= ImperialDutRatio(to);
} /// <summary>
/// Convert a value indicated by DisplayUnitType to the value used by RevitAPI
/// </summary>
/// <param name="value">Value to be converted</param>
/// <param name="from">DisplayUnitType indicates the unit of the value to be converted</param>
/// <returns>Target value</returns>
public static double CovertToAPI(double value, DisplayUnitType from )
{
return value /= ImperialDutRatio(from);
} /// <summary>
/// Get ratio between value in RevitAPI and value to display indicated by DisplayUnitType
/// </summary>
/// <param name="dut">DisplayUnitType indicates display unit type</param>
/// <returns>Ratio </returns>
private static double ImperialDutRatio(DisplayUnitType dut)
{
switch (dut)
{
case DisplayUnitType.DUT_DECIMAL_FEET: return ;
case DisplayUnitType.DUT_FEET_FRACTIONAL_INCHES: return ;
case DisplayUnitType.DUT_DECIMAL_INCHES: return ;
case DisplayUnitType.DUT_FRACTIONAL_INCHES: return ;
case DisplayUnitType.DUT_METERS: return 0.3048;
case DisplayUnitType.DUT_CENTIMETERS: return 30.48;
case DisplayUnitType.DUT_MILLIMETERS: return 304.8;
case DisplayUnitType.DUT_METERS_CENTIMETERS: return 0.3048;
default: return ;
}
}
#endregion
}
}
url:http://greatverve.cnblogs.com/p/revit-api-create-level.html
Revit API创建标高,单位转换的更多相关文章
- Revit api 创建族并加载到当前项目
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...
- Revit API创建标注NewTag
start ; ) { eId = item; } ...
- Revit API创建墙的保温层修改墙厚度
start [Transaction(TransactionMode.Manual)] [Regeneration(RegenerationOption.Manual)] / ; ; ...
- Revit API创建一个拷贝房间内对象布局命令
本课程演示创建一个拷贝房间内对象布局命令,完整演示步骤和代码.这个命令把选中房间内的对象复制到其它选中的一个或多个房间中,而且保持与源房间一致的相对位置.通过本讲座使听众知道创建一个二次开发程序很简单 ...
- Revit API创建几何实体Solid并找到与之相交的元素
几何实体的创建方法之一:构成封闭底面,指定拉伸方向与拉伸高度.GeometryCreationUtilities ; , pt.Y - dBoxLength / , pt.Z); ...
- Revit API 创建带箭头的标注
[Transaction(TransactionMode.Manual)] [Regeneration(RegenerationOption.Manual)] public class cmd : ...
- Revit api 创建楼梯图元
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...
- Revit API创建详图视图
start //创建详图视图 Transaction ts = new Transaction(doc, "http://greatverve.cnblogs.com"); ts. ...
- Revit API单位转换类
用法:txt.Text=UnitConvertC.CovertFromAPI(param.AsDouble());param.Set(UnitConvertC.CovertToAPI(txt.Text ...
随机推荐
- SANS社区帐号邮件激活问题
注册时,密码需要数字,大写字母,小写字母,符号10位以上才能注册成功 吐槽:谁来爆破一下这种强度的密码,哈哈. 在我的文章中,有 计算机取证 分类,里面的一篇文章 Virtual Worksta ...
- 【mongoDB】 分享系列
mongoDB 作为一个非关系性数据库(功能很像关系型数据库) MongoDB 之一 MongoDB是什么 MongoDB 之二 增-删-改-查 MongoDB 之三 数据类型 MongoDB 之四 ...
- 运动规划——PT and PVT 模式
最近项目成员在做机器人上层开发时,经常说到PT模式和PVT模式.一直没搞懂这两种模式的实际差别.上网检索进行学习...... ref link:https://blog.csdn.net/m0_376 ...
- 003_cd pushd popd三个命令的区别
一. It depends. In zsh you can configure cd to push the old directory on the directory stack automati ...
- Restful对于URL的简化
REST是英文representational state transfer(表象性状态转变)或者表述性状态转移,它是web服务的一种架构风格.使用HTTP,URI,XML,JSON,HTML等广泛流 ...
- Linux系统运维笔记(五),CentOS 6.4安装java程序
Linux系统运维笔记(五),CentOS 6.4安装java程序 用eclipse编译通的java程序,现需要实施到服务器.实施步骤: 一,导出程序成jar包. 1,在主类编辑界面点右健,选 ru ...
- 启动DELPHI2010出现 EditorLineEnds.ttr 错误的解决方法
在网上找到了很多方法.其实解决这个问题的方法, 最简单的就是把 EditorLineEnds.ttr 改名为 EditorLineEnds.ttf 然后,安装它, 安装完成后就OK了.
- 2018年东北农业大学春季校赛 C-wyh的商机
一天,你们wyh学长和你们zhl学长玩一个游戏,这个游戏规则是这样的 给你n个城市,保证这n个城市之间都只有一条道路可以到达. 有一件物品,在所有城市中都是一样的,但是由于各个城市的经济发展不同,导致 ...
- Going Home
题意:n个人,进n个房子,每走一格花费1美元,每个房子只能进一人,求所有人进房子的最小花费. 就是推箱子 箱子最短行走距离 这题无法用bfs做 ! 用最小花费最大流 通过EK,Dinic,ISAP ...
- 搭建微信小程序基本的https与wss环境
年底了写一篇小程序环境搭建的文章, 主要是怎么搭建一个线上环境以及怎么不改动原有http Api的情况 1.准备工作 域名一个 免费证书(推荐: 腾讯云.阿里云.便宜ssl 都是免费的 配置好后先将证 ...