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 ...
随机推荐
- 拓展中国剩余定理(exCRT)摘要
清除一个误区 虽然中国剩余定理和拓展中国剩余定理只差两个字,但他俩的解法相差十万八千里,所以会不会CRT无所谓 用途 求类似$$\begin{cases}x \equiv b_{1}\pmod{a_{ ...
- python 搭建http服务器和ftp服务器
默认安装版本为pytho2.7 http服务器搭建: 进入要开放访问的目录下,执行命令:python -m SimpleHTTPServer 9000 显示上述表示安装成功,且http服务的端口为:9 ...
- poj2679
题意:给出一个有向图,每条边有两个属性:一个长度一个费用.费用可能是负数.长度一定是非负的.给出一个起点和一个终点,现要求,从起点走到终点,且从每个点走出时选择的那条边必须是以该点作为起点的边中费用最 ...
- jQuery-介绍
一:什么是jQuery jQuery 是一个 JavaScript 库. 二:安装 http://jquery.com/download/ http://jquery.cuishifeng.cn/ j ...
- 目标检测--Selective Search for Object Recognition(IJCV, 2013)
Selective Search for Object Recognition 作者: J. R. R. Uijlings, K. E. A. van de Sande, T. Gevers, A. ...
- springMVC:将controller中数据传递到jsp页面
1> 将方法的返回值该为ModelAndView在返回时,将数据存储在ModelAndView对象中如: newModelAndView("/WEBINF/jsp/showData.j ...
- hdu 5427(排序水题)
排序 年轻的排前面 名字中可能有空格 Sample Input21FancyCoder 19962FancyCoder 1996xyz111 1997 Sample OutputFancyCoderx ...
- android studio 3.0之后版本自定义文件名生成apk文件
修改app模块的build.gradle 在android闭包中添加以下代码 //指定打包后应用名称 android.applicationVariants.all { variant -> v ...
- centos7配置svn钩子hooks脚本自动同步代码到项目目录
由于项目需要,svn提交后的代码希望再测试服务器上测试,每次提交后还要手动去svn update一次 十分麻烦,配置好svn钩子以后就省去了这些麻烦. 进入svn版本库目录找到hooks目录找到文件p ...
- 【LOJ】#2081. 「JSOI2016」反质数序列
题解 我居然都没反应过来二分图内选集合两两不能有边是最大独立集了 我退役吧 显然连边只能在奇数和偶数之间,然后二分图求最大独立集是节点数-最大匹配数 啊当然还有对于1的话只能留一个1 代码 #incl ...