元素结构:

一些基本元素的添加与绘制:

class CreateElement
{
public static void LineAndLineString()
{
Application app = Utilities.ComApp;
Point3d startPnt = app.Point3dZero();
Point3d endPnt = startPnt;
startPnt.X = 10;
LineElement oLine = app.CreateLineElement2(null, ref startPnt, ref endPnt);
oLine.Color = 0; oLine.LineWeight = 2;
app.ActiveModelReference.AddElement(oLine);
Point3d[] pntArray = new Point3d[5];
pntArray[0] = app.Point3dZero();
pntArray[1] = app.Point3dFromXY(1, 2);
pntArray[2] = app.Point3dFromXY(3, ‐2);
pntArray[3] = app.Point3dFromXY(5, 2);
pntArray[4] = app.Point3dFromXY(6, 0);
oLine = app.CreateLineElement1(null, ref pntArray);
oLine.Color = 1; oLine.LineWeight = 2;
app.ActiveModelReference.AddElement(oLine);
}
public static void ShapeAndComplexShape()
{
Application app = Utilities.ComApp;
Point3d[] pntArray = new Point3d[6];
pntArray[0] = app.Point3dFromXY(0, ‐6);
pntArray[1] = app.Point3dFromXY(0, ‐2);
pntArray[2] = app.Point3dFromXY(2, ‐2);
pntArray[3] = app.Point3dFromXY(2, ‐4);
pntArray[4] = app.Point3dFromXY(4, ‐4);
pntArray[5] = app.Point3dFromXY(4, ‐6);
ShapeElement oShape = app.CreateShapeElement1(null, ref pntArray);
oShape.Color = 0; oShape.LineWeight = 2;
app.ActiveModelReference.AddElement(oShape);
ChainableElement[] elmArray = new ChainableElement[2];
for (int i = 0; i
< 6; i++)
pntArray[i].X += 5;
elmArray[0] = app.CreateLineElement1(null, ref pntArray);
pntArray[2].Y = ‐8;
elmArray[1] = app.CreateArcElement3(null, ref pntArray[5], ref pntArray[2],
ref pntArray[0]);
ComplexShapeElement oComplexShape = app.CreateComplexShapeElement1(ref
elmArray);
oComplexShape.Color = 1; oComplexShape.LineWeight = 2;
app.ActiveModelReference.AddElement(oComplexShape);
}
public static void TextAndTextNode()
{
Application app = Utilities.ComApp;
double savedTextHeight = app.ActiveSettings.TextStyle.Height;
double savedTextWidth = app.ActiveSettings.TextStyle.Width;
Font savedFont = app.ActiveSettings.TextStyle.Font;
bool savedAnnotationScaleEnabled = app.ActiveSettings.AnnotationScaleEnabled;
app.ActiveSettings.TextStyle.Height = 0.7;
app.ActiveSettings.TextStyle.Width = 0.6;
app.ActiveSettings.TextStyle.Font =
app.ActiveDesignFile.Fonts.Find(MsdFontType.WindowsTrueType,
"Arial");
app.ActiveSettings.AnnotationScaleEnabled = false;
Point3d origin = app.Point3dFromXY(0, ‐7.5);
Matrix3d rMatrix = app.Matrix3dIdentity();
TextElement oText = app.CreateTextElement1(null, "Text String", ref
origin,
ref rMatrix);
oText.Color = 0;
app.ActiveModelReference.AddElement(oText);
origin = app.Point3dFromXY(2, ‐9);
TextNodeElement oTN = app.CreateTextNodeElement1(null, ref origin, ref
rMatrix);
oTN.AddTextLine("Text Node Line 1");
oTN.AddTextLine("Text Node Line 2");
oTN.Color = 1;
app.ActiveModelReference.AddElement(oTN);
app.ActiveSettings.TextStyle.Height = savedTextHeight;
app.ActiveSettings.TextStyle.Width = savedTextWidth;
app.ActiveSettings.TextStyle.Font = savedFont;
app.ActiveSettings.AnnotationScaleEnabled = savedAnnotationScaleEnabled;
}
public static void CellAndSharedCell()
{
Application app = Utilities.ComApp;
app.AttachCellLibrary("sample2.cel");
Point3d origin = app.Point3dFromXY(1, ‐13);
double xScale = 0.1 * app.ActiveModelReference.UORsPerMasterUnit / 1000.0;
Point3d scale = app.Point3dFromXYZ(xScale, xScale, xScale);
Matrix3d rMatrix = app.Matrix3dIdentity();
CellElement oCell = app.CreateCellElement2("DECID", ref origin, ref
scale,
true, ref rMatrix);
oCell.Color = 0;
app.ActiveModelReference.AddElement(oCell);
SharedCellElement oSC;
xScale = 0.02 * app.ActiveModelReference.UORsPerMasterUnit / 1000.0;
scale = app.Point3dFromXYZ(xScale, xScale, xScale);
for (int x = 4; x <= 8; x += 2)
{
origin = app.Point3dFromXY(x, ‐14);
oSC = app.CreateSharedCellElement2("NORTH", ref origin, ref scale,
true,
ref rMatrix);
oSC.OverridesComponentColor = true; oSC.Color = 1;
app.ActiveModelReference.AddElement(oSC);
}
}
public static void LinearAndAngularDimension()
{
Application app = Utilities.ComApp;
DimensionStyle ds = app.ActiveSettings.DimensionStyle;
ds.OverrideAnnotationScale = true; ds.AnnotationScale = 1;
ds.OverrideTextHeight = true; ds.TextHeight = 0.5;
ds.OverrideTextWidth = true; ds.TextWidth = 0.4;
ds.MinLeader = 0.01;
ds.TerminatorArrowhead = MsdDimTerminatorArrowhead.Filled;
Matrix3d rMatrix = app.Matrix3dIdentity();
Point3d[] pnts = new Point3d[3];
pnts[0] = app.Point3dFromXY(0, ‐17);
pnts[1] = app.Point3dFromXY(3, ‐17);
DimensionElement oDim = app.CreateDimensionElement1(null, ref rMatrix,
MsdDimType.SizeArrow);
oDim.AddReferencePoint(app.ActiveModelReference, ref pnts[0]);
oDim.AddReferencePoint(app.ActiveModelReference, ref pnts[1]);
oDim.Color = 0; oDim.DimHeight = 1;
app.ActiveModelReference.AddElement(oDim);
ds.AnglePrecision = MsdDimValueAnglePrecision.DimValueAnglePrecision1Place;
oDim = app.CreateDimensionElement1(null, ref rMatrix, MsdDimType.AngleSize);
pnts[0] = app.Point3dFromXY(7, ‐13);
pnts[1] = app.Point3dFromXY(5, ‐15);
pnts[2] = app.Point3dFromXY(9, ‐15);
oDim.AddReferencePoint(app.ActiveModelReference, ref pnts[0]);
oDim.AddReferencePoint(app.ActiveModelReference, ref pnts[1]);
oDim.AddReferencePoint(app.ActiveModelReference, ref pnts[2]);
oDim.Color = 1; oDim.DimHeight = 1;
app.ActiveModelReference.AddElement(oDim);
}
public static void CurveAndBsplineCurve()
{
Application app = Utilities.ComApp;
Point3d[] pntArray = new Point3d[5];
pntArray[0] = app.Point3dFromXY(0, ‐19);
pntArray[1] = app.Point3dFromXY(1, ‐17);
pntArray[2] = app.Point3dFromXY(2, ‐19);
pntArray[3] = app.Point3dFromXY(3, ‐17);
pntArray[4] = app.Point3dFromXY(4, ‐19);
CurveElement oCurve = app.CreateCurveElement1(null, ref pntArray);
oCurve.Color = 0; oCurve.LineWeight = 2;
app.ActiveModelReference.AddElement(oCurve);
for (int i = 0; i < 5; i++)
pntArray[i].X += 5;
InterpolationCurve oInterpolationCurve = new InterpolationCurveClass();
oInterpolationCurve.SetFitPoints(pntArray);
BsplineCurveElement oBsplineCurve = app.CreateBsplineCurveElement2(null,
oInterpolationCurve);

oBsplineCurve.Color = 1;

oBsplineCurve.LineWeight = 2;

app.ActiveModelReference.AddElement(oBsplineCurve);

 

}

 

public static void
ConeAndBsplineSurface()

 

{

 

Application app = Utilities.ComApp;

 

Point3d basePt = app.Point3dFromXYZ(2,
‐23, 0);

 

Point3d topPt = app.Point3dFromXYZ(2,
‐20, 0);

 
   
   

Matrix3d rMatrix =
app.Matrix3dFromAxisAndRotationAngle(0, app.Pi()/6);

ConeElement oCone
= app.CreateConeElement1(null, 2, ref basePt, 1, ref topPt,
ref rMatrix);
oCone.Color = 0;
app.ActiveModelReference.AddElement(oCone);
Point3d[] aFitPnts = new Point3d[4];
InterpolationCurve oFitCurve = new InterpolationCurveClass();
BsplineCurve[] aCurves = new BsplineCurve[3];
aFitPnts[0] =
app.Point3dFromXYZ(5.9, ‐21, ‐0.5);
aFitPnts[1] = app.Point3dFromXYZ(6.9, ‐20, 1);
aFitPnts[2] = app.Point3dFromXYZ(7.9, ‐20.3, 1.3);
aFitPnts[3] = app.Point3dFromXYZ(8.9, ‐20.8, 0.3);
oFitCurve.SetFitPoints(ref aFitPnts);
oFitCurve.BesselTangents = true;
aCurves[0] = new BsplineCurveClass();
aCurves[0].FromInterpolationCurve(oFitCurve);
aFitPnts[0] = app.Point3dFromXYZ(6.4, ‐22, 0);
aFitPnts[1] = app.Point3dFromXYZ(7.1, ‐21.2, 0.7);
aFitPnts[2] = app.Point3dFromXYZ(7.7, ‐21, 1);
aFitPnts[3] = app.Point3dFromXYZ(8.4, ‐21.7, ‐0.2);
oFitCurve.SetFitPoints(ref aFitPnts);
oFitCurve.BesselTangents = true;
aCurves[1] = new BsplineCurveClass();
aCurves[1].FromInterpolationCurve(oFitCurve);
aFitPnts[0] = app.Point3dFromXYZ(5.9, ‐23, 0);
aFitPnts[1] = app.Point3dFromXYZ(7.2, ‐23.1, 1.2);
aFitPnts[2] = app.Point3dFromXYZ(7.8, ‐23.3, 0.8);
aFitPnts[3] = app.Point3dFromXYZ(8.7, ‐22.8, 0.2);
oFitCurve.SetFitPoints(ref aFitPnts);
oFitCurve.BesselTangents = true;
aCurves[2] = new BsplineCurveClass();
aCurves[2].FromInterpolationCurve(oFitCurve);
BsplineSurface oBsplineSurface = new BsplineSurfaceClass();
oBsplineSurface.FromCrossSections(ref aCurves, MsdBsplineSurfaceDirection.V,
4, true, true);
BsplineSurfaceElement oSurfaceElm = app.CreateBsplineSurfaceElement1(null,
oBsplineSurface);
oSurfaceElm.Color = 1;
app.ActiveModelReference.AddElement(oSurfaceElm);
}
}
}
4. 打開MyAddins.cs文件修改如下。
4. Open file
MyAddins.cs and modify it as below.
protected override
int Run(string[] commandLine)
{
//string sWinFrameworkPath = RuntimeEnvironment.GetRuntimeDirectory();
//MessageBox.Show("Framework Path =" + sWinFrameworkPath);
CreateElement.LineAndLineString();
CreateElement.ShapeAndComplexShape();
CreateElement.TextAndTextNode();
CreateElement.CellAndSharedCell();
CreateElement.LinearAndAngularDimension();
CreateElement.CurveAndBsplineCurve();
CreateElement.ConeAndBsplineSurface();
return 0;
}

窗口停靠:

画如下图形:

使用样条线可以实现revit历练类似放样融合的功能。

可以调用mdl的接口:

还有一些事件映射,现在暂时用不到。

bently addin 二次开发学习的更多相关文章

  1. Civil 3D API二次开发学习指南

    Civil 3D构建于AutoCAD 和 Map 3D之上,在学习Civil 3D API二次开发之前,您至少需要了解AutoCAD API的二次开发,你可以参考AutoCAD .NET API二次开 ...

  2. spss C# 二次开发 学习笔记(三)——Spss .Net 开发

    Spss .Net 二次开发的学习过程暂停了一段时间,今天开始重启. 之前脑残的不得了,本想从网上下载一个Spss的安装包,然后安装学习.于是百度搜索Spss,在百度搜索框的列表中看到Spss17.S ...

  3. spss C# 二次开发 学习笔记(一)——配置数据源

    由于项目的需要,使用Spss进行数据统计分析. Spss对于数据统计分析的功能有多强主要是客户关注的事情,我所主要关注的是,Spss的二次开发有多复杂. 学习的基本思路是: (1)首先了解统计基本知识 ...

  4. EcShop二次开发学习方法和Ecshop二次开发必备基础

    ecshop二次开发学习方法 近年来,随着互联网的发展,电子商务也跟着一起成长,B2B,C2C,B2C的电子商务模式也不断的成熟.这时催生出了众多电子商务相关的php开源产品.B2C方面有Ecshop ...

  5. spss C# 二次开发 学习笔记(六)——Spss统计结果的输出

    Spss的二次开发可以很简单,实例化一个对象,然后启用服务,接着提交命令,最后停止服务. 其中重点为提交命令,针对各种统计功能需求,以及被统计分析的数据内容等,命令的内容可以很复杂,但也可以简单的为一 ...

  6. spss C# 二次开发 学习笔记(五)——Spss系统集成模式

    Spss官方不支持Server2008R2等Server系列,但做Spss的二次开发,调用Spss的Web系统,一般部署在Server系列上,例如Server2008R2. 起初,在Server上安装 ...

  7. spss C# 二次开发 学习笔记(四)——Spss授权

    Spss的授权方式有两种,单机版和网络版. Spss的激活,在联网的情况下,通过20位的激活码激活,在未联网的情况下,Spss根据机器获取一个类似4-XXXX的锁定码,然后由激活码和锁定码算出一个授权 ...

  8. Autodesk View and Data API二次开发学习指南

    什么是View and Data API? 使用View and Data API,你可以轻松的在网页上显示大型三维模型或者二维图纸而不需要安装任何插件.通过View and Data API,你可以 ...

  9. .NET CAD二次开发学习第一天

    基于浩辰CAD2019 需求: 开发线转圆简单命令.命令过程:1) 请选择图中直线(要求支持一次选多个):2) 弹出对话框,输入圆的图层名和半径3) 点对话框中确定按钮,结束命令.命令执行效果:所选每 ...

随机推荐

  1. Android艺术——性能优化问题

    这次分析方向,我们主要包括:布局优化.绘制优化.内存泄漏优化.响应速度优化.ListView优化.Bitmap优化.线程优化. 布局优化:尽量的减少布局的层级,这意味着Android绘制时的工作量会变 ...

  2. Linux(Ubuntu)使用日记------部署JavaWeb项目到服务器

    0.前言 本博文内容是建立在你可以通过SSH连接到远程服务器的基础上的,如果你还没有用SSH连接到远程服务器,请参考此文(腾讯云服务器): http://www.cnblogs.com/hwtblog ...

  3. jmeter 安装

    3.1 windows10环境下测试工具jmeter安装与配置 3.1.1下载安装java 浏览器中打开链接:http://down-www.7down.net/pcdown/soft/xiazai/ ...

  4. randperm

    randperm是matlab函数,功能是随机打乱一个数字序列. 函数功能:随机打乱一个数字序列. 语法格式: y = randperm(n) y是把1到n这些数随机打乱得到的一个数字序列. 程序示例 ...

  5. NABCD--团队项目1

    N: 1.学校中有很多学生是外省的,然后不知道附近有什么地方周末可以去玩. 2.学校中学生有很多用不到的东西但是联系不到合适的买家. A: 我们可以做一个软件,通过学号注册登陆软件,这样可以防止有人去 ...

  6. 关系型数据库 VS 非关系型数据库

    一.关系型数据库? 1.概念 关系型数据库是指采用了关系模型来组织数据的数据库.简单来说,关系模式就是二维表格模型. 主要代表:SQL Server,Oracle,Mysql,PostgreSQL. ...

  7. JS 基础知识点

    最近发现一个好东西,掘金小册,觉得里面的东西挺不错的,准备仔细阅读一下,提升下自己. 记录一下,随便加深点儿印象,主要内容源自于小册. 原始类型 原始类型也成为基本数据类型 boolean null ...

  8. Celery

    在程序的运行过程中,我们经常会碰到一些耗时耗资源的操作,为了避免它们阻塞主程序的运行,我们经常会采用多线程或异步任务.比如,在 Web 开发中,对新用户的注册,我们通常会给他发一封激活邮件,而发邮件是 ...

  9. ubuntu mirror

    # apt-mirror configuration file ## The default configuration options (uncomment and change to overri ...

  10. dgraph解决社交关系中的正反向查找

    dgraph解决社交关系中的正反向查找 本篇介绍的是, 社交关系中的关注者与被关注者在dgraph中如何实现查找. 对dgraph的基本操作不太清楚的可以看看我之前写的博客 dgraph实现基本操作 ...