做Dynamo软件包其实很简单。看完上一篇博客提到的内容基本上就可以做软件包了,但是里面的英文看的略受伤,好在和同事之间总是用英文交流,最近英语能力稳步提升。
好了,做软件包的第一步,引用dll文件:
第二步,写一个简单的类,下面主要是实现IGraphicItem这个接口,具体意思最好自己再翻一番英文资料:
using System;
using System.Collections.Generic;
using Autodesk.DesignScript.Geometry;
using Autodesk.DesignScript.Interfaces;
using Autodesk.DesignScript.Runtime;
namespace MyDynamoTest
{
public class MyTest : IGraphicItem
{
private Point point;
public double Awesome { get { return 42.0; } }
public Point Point { get { return point; } }
internal double InvisibleProperty { get { return 42.0; } }
private MyTest(double x, double y, double z)
{
point = Point.ByCoordinates(x, y, z);
}
public static MyTest Create(double x = 42.0, double y = 42.0, double z = 42.0)
{
if (x < 0)
{
throw new ArgumentException("x");
}
if (y < 0)
{
throw new ArgumentException("y");
}
if (z < 0)
{
throw new ArgumentException("z");
}
return new MyTest(x, y, z);
}
public static MyTest Create([DefaultArgumentAttribute("Point.ByCoordinates(5,5,5);")]Point point)
{
return new MyTest(point.X, point.Y, point.Z);
}
[MultiReturn(new[] { "thing 1", "thing 2" })]
public static Dictionary> MultiReturnExample()
{
return new Dictionary>()
{
{ "thing 1", new List{"apple", "banana", "cat"} },
{ "thing 2", new List{"Tywin", "Cersei", "Hodor"} }
};
}
public override string ToString()
{
return string.Format("HelloDynamoZeroTouch:{0},{1},{2}", point.X, point.Y, point.Z);
}
#region IGraphicItem interface
[IsVisibleInDynamoLibrary(false)]
public void Tessellate(IRenderPackage package, TessellationParameters parameters)
{
package.AddPointVertex(point.X, point.Y, point.Z);
package.AddPointVertexColor(255, 0, 0, 255);
}
#endregion
}
[SupressImportIntoVM]
[IsVisibleInDynamoLibrary(false)]
public class DoesNotImportClass
{
public DoesNotImportClass() { }
}
}
第三步,把生成的MynamoTest.dll文件放在
C:\Users\Administrator\AppData\Roaming\Dynamo\Dynamo Revit\1.3\packages的任意一个包里。
如果位置不对,具体位置你也可以按照下图找到:
接下来,重新启动Dynamo,你就可以看到你自己做的软件包,然后你就可以用了。
对Revit二次开发和Dyanmo编程这块感兴趣请加qq群交流:660319009
个人问题咨询请加qq:254033230,本人见钱眼开,不要轻易打扰!!!