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 ...
随机推荐
- Git常见错误处理
如果输入$ Git remote add origin git@github.com:djqiang(github帐号名)/gitdemo(项目名).git 提示出错信息:fatal: remo ...
- 20165320 2017-2018-2《Java程序设计》课程总结
20165320 2017-2017-2<Java程序设计>课程总结 一.每周作业链接汇总 1.我期待的师生关系 20165320 我期望的师生关系 2.学习基础和C语言基础调查 2016 ...
- Xgboost理解
一.xgboost模型函数形式 xgboost也是GBDT的一种,只不过GBDT在函数空间进行搜索最优F的时候,采用的是梯度下降法也就是一阶泰勒展开:而xgboost采用的是二阶泰勒展开也就是牛顿法, ...
- 分模块开发创建service子模块——(八)
1.右击父工程新建maven子模块
- Java编程的逻辑 (58) - 文本文件和字符流
本系列文章经补充和完善,已修订整理成书<Java编程的逻辑>,由机械工业出版社华章分社出版,于2018年1月上市热销,读者好评如潮!各大网店和书店有售,欢迎购买,京东自营链接:http:/ ...
- PHP并发操作下的加锁
最近做后台统计的工具,统计肯定是一个需要运算好久的数据 容许一个用户在一个时间内进行操作,这个时候就需要用到锁了,将这个操作过程锁起来.在用了cache的时候,cache失效可能导致瞬间的多数并发请求 ...
- 7-10Editing aBook uva11212(迭代加深搜索 IDA*)
题意: 给出n( 2<=n<=9) 个乱序的数组 要求拍成升序 每次 剪切一段加上粘贴一段算一次 拍成1 2 3 4 ...n即可 求排序次数 典型的状态空间搜索问题 ...
- 001 jquery对象与dom对象的转换
1.jQuery对象介绍 2.jQuery对象转换为Dom对象 3.Dom转换为Jquery对象 4.将jquery转换为Dom程序 <!DOCTYPE html> <html> ...
- P1244 青蛙过河
P1244 青蛙过河NOI2000主要思想:数学归纳法 递推 压位高精度 化归 理解能力和找规律的能力题意再述:1.青蛙从上到下必须连续递增或者下面是石墩 而不能是1 12 33 4而且每时每刻都要满 ...
- pip 安装包提速
豆瓣源 pip3 install 第三方库名 -i https://pypi.doubanio.com/simple/ --trusted-host pypi.doubanio.com