一业内朋友让我写个快速创建标高的插件。

//创建标高
[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创建标高,单位转换的更多相关文章

  1. Revit api 创建族并加载到当前项目

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...

  2. Revit API创建标注NewTag

    start ;             )                 {                     eId = item;                 }            ...

  3. Revit API创建墙的保温层修改墙厚度

    start [Transaction(TransactionMode.Manual)] [Regeneration(RegenerationOption.Manual)]  / ;         ; ...

  4. Revit API创建一个拷贝房间内对象布局命令

    本课程演示创建一个拷贝房间内对象布局命令,完整演示步骤和代码.这个命令把选中房间内的对象复制到其它选中的一个或多个房间中,而且保持与源房间一致的相对位置.通过本讲座使听众知道创建一个二次开发程序很简单 ...

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

    几何实体的创建方法之一:构成封闭底面,指定拉伸方向与拉伸高度.GeometryCreationUtilities ;         , pt.Y - dBoxLength / , pt.Z);    ...

  6. Revit API 创建带箭头的标注

      [Transaction(TransactionMode.Manual)] [Regeneration(RegenerationOption.Manual)] public class cmd : ...

  7. Revit api 创建楼梯图元

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...

  8. Revit API创建详图视图

    start //创建详图视图 Transaction ts = new Transaction(doc, "http://greatverve.cnblogs.com"); ts. ...

  9. Revit API单位转换类

    用法:txt.Text=UnitConvertC.CovertFromAPI(param.AsDouble());param.Set(UnitConvertC.CovertToAPI(txt.Text ...

随机推荐

  1. Linux DRM KMS 驱动简介【转】

    转自:https://blog.csdn.net/yangkuanqaz85988/article/details/48689521 Whoops,上次写完<Linux DRM Graphic ...

  2. React-Native 之 TabBarIOS

    前言 学习本系列内容需要具备一定 HTML 开发基础,没有基础的朋友可以先转至 HTML快速入门(一) 学习 本人接触 React Native 时间并不是特别长,所以对其中的内容和性质了解可能会有所 ...

  3. MAC连接安卓手机通过adb指令安装apk

    Android的apk可以通过adb命令来安装.在MAC电脑上,如果想通过命令行的方式给安卓手机安装apk,需要做以下操作: 一句话概括就是:将安卓SDK的adb命令添加到环境变量中,然后通过adb ...

  4. makefile 中 foreach

    四.foreach 函数 foreach函数和别的函数非常的不一样.因为这个函数是用来做循环用的,Makefile中的foreach函数几乎是仿照于Unix标准Shell(/bin/sh)中的for语 ...

  5. nginx 日志切割(也适用于docker)

    =============================================== 2019/4/6_第2次修改                       ccb_warlock 201 ...

  6. POI操作Excel详解,HSSF和XSSF两种方式

    package com.tools.poi.lesson1; import java.io.FileInputStream; import java.io.FileNotFoundException; ...

  7. hdu 2065(泰勒展式)

    比赛的时候遇到这种题,只能怪自己高数学得不好,看着别人秒.... 由4种字母组成,A和C只能出现偶数次. 构造指数级生成函数:(1+x/1!+x^2/2!+x^3/3!……)^2*(1+x^2/2!+ ...

  8. tensorflow-作用域

    变量名字由两部分组成:scope/变量name. name 参数才是对象的唯一标识. 1.tf.name_scope() Graph中保存着一个属性_name_stack(string类型),_nam ...

  9. java判断部署项目使用的服务器类型

    有两种方式 1.项目引入portal-kernel.jar.项目运行时使用 根据返回boolean值判断类型! 2.自己写java类 package webService.ZFGX.service; ...

  10. bzoj 1151: [CTSC2007]动物园zoo

    思路:因为每个人最多只能看到五个动物,我们考虑将其状压,f[ i ][ s ] 表示到了第 i 个位置, i, i + 1, i + 2, i + 3, i + 4这四个动物的状态为s, 此时的最大值 ...