当前位置:网站首页>This is a small case of secondary development of phase I Revit (automatic layout of supports and hangers)
This is a small case of secondary development of phase I Revit (automatic layout of supports and hangers)
2022-04-21 12:51:00 【A seat in Wolong City, Tsing Yi】
Report to you , I watched the world cup some time ago, so I don't want to update
Let's give you a small case , To apologize , I can't help it if I'm not happy !
Okay , This is a serious dividing line !
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Data;
using Autodesk.Revit;
using Autodesk.Revit.UI;
using Autodesk.Revit.UI.Selection;
using Autodesk.Revit.DB;
using Autodesk.Revit.DB.Architecture;
using Autodesk.Revit.DB.Mechanical;
using Autodesk.Revit.DB.Plumbing;
using Autodesk.Revit.DB.Electrical;
using Autodesk.Revit.ApplicationServices;
using System.Data.SqlClient;
using Autodesk.Revit.Creation;
using Autodesk.Revit.DB.Structure;// I didn't remember to copy before
namespace zpx123
{
[Autodesk.Revit.Attributes.Transaction(Autodesk.Revit.Attributes.TransactionMode.Manual)]
[Autodesk.Revit.Attributes.Regeneration(Autodesk.Revit.Attributes.RegenerationOption.Manual)]
[Autodesk.Revit.Attributes.Journaling(Autodesk.Revit.Attributes.JournalingMode.NoCommandData)]
public class Class1 : IExternalCommand
{
public Autodesk.Revit.UI.Result Execute(ExternalCommandData commandData, ref string message, Autodesk.Revit.DB.ElementSet elements)
{
// Create application objects
Autodesk.Revit.ApplicationServices.Application app = commandData.Application.Application;
// Create document object
Autodesk.Revit.DB.Document doc = commandData.Application.ActiveUIDocument.Document;
// Create application objects
Autodesk.Revit.UI.UIApplication uiapp = commandData.Application;
// Create document object
Autodesk.Revit.UI.UIDocument uiDoc = uiapp.ActiveUIDocument;
// Start business
Transaction ts = new Transaction(doc, " Support and hanger arrangement ");
ts.Start();
Above, this is the template , I don't know if you remember
Here's the serious code !
In previous issues, I talked about many articles about creating examples , Let's apply it this time , Is it troublesome to make supports and hangers manually at ordinary times ? Now let's make a small program to let him automatically cloth the supports and hangers !
- Select the distance to arrange the supports and hangers
2. Select the pipe for which the supports and hangers are to be arranged
Let's add a form first , Rough design the form , That's about it !
Add code to the form :
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace zpx123
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
public void textBox1_TextChanged(object sender, EventArgs e)
{
string str = textBox1.Text;
}
private void button1_Click(object sender, EventArgs e)
{
this.DialogResult = DialogResult.OK;
}
public string Number
{
get { return textBox1.Text; }// Get the value returned in the text box
}
private void Form1_Load(object sender, EventArgs e)
{
}
}
}
Serious code :
double number = 0;
int number1 = 0;
zpx123.Form1 form = new zpx123.Form1();
form.ShowDialog();
if (form.DialogResult == DialogResult.OK)
{
string str = form.Number;
// In order to prevent users from making mistakes , I'm used to kicking
try
{
number1 = Convert.ToInt32(str);
number = number1/304.8;
}
catch
{
MessageBox.Show(" Please enter the correct number ");
}
}
// Through the above, you can get the value entered by the user
ElementId id = null;
FilteredElementCollector faa = new FilteredElementCollector(doc);
faa.OfClass(typeof(FamilyInstance));// Collect family types
foreach (FamilyInstance fa in faa)
{
if (fa.GetParameters(" Families and types ")[0].AsValueString().Contains(" Supports and hangers "))
{
id = fa.Symbol.Id;
}
}
FamilySymbol fas = doc.GetElement(id) as FamilySymbol;
Selection ree = uiDoc.Selection;
Reference re = ree.PickObject(ObjectType.Element);
Element elem = doc.GetElement(re);
Pipe pipe = elem as Pipe;
LocationCurve curve = pipe.Location as LocationCurve;
XYZ start = curve.Curve.GetEndPoint(0);// Get the starting point of the pipe
XYZ end = curve.Curve.GetEndPoint(1);// Get the end point of the pipe
double a = start.X ;
double b = start.Y ;
double zz = start.Z ;
double c = end.X ;
double d = end.Y ;
// The above is to obtain the starting point and end point of the pipeline xyz Value
double xy = start.DistanceTo(end) ;// Ask for distance
int gs = (int)((xy / number));// Please put several supports and hangers
double y = (number * (d - b)) / Math.Sqrt((c - a) * (c - a) + (d - b) * (d - b)) ;
double x = (number * (c - a)) / Math.Sqrt((c - a) * (c - a) + (d - b) * (d - b)) ;
// The above is the mathematical formula
List<FamilyInstanceCreationData> listt = new List<FamilyInstanceCreationData>();
// A collection used to store a series of pipe coordinates
for (double j = 0; j < gs; j ++)
{
double A = a + x;
double B = b + y;
listt.Add(new FamilyInstanceCreationData(new XYZ(A, B, zz), fas, StructuralType.NonStructural));// Put the coordinates in the set
a = A;
b = B;
}
doc.Create.NewFamilyInstances2(listt);// Create supports and hangers
ts.Commit();
return Result.Succeeded;
}
}
}
( The code is a little long , I tried , Screenshots can't cut all the code in , It can only be divided into a few pictures )
Effect display :
Click finish , Select pipe .
Because the supports and hangers are in one direction , Therefore, in order to achieve the perfect realization, we also need to rotate the supports and hangers , I'll leave this to your clever babies ! How to rotate will be updated in a later issue ! Coming soon ( I'm not sure when to update )....
版权声明
本文为[A seat in Wolong City, Tsing Yi]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204211247475396.html
边栏推荐
- 【uvm】 多模块env结构
- 网易云---手机验证码登录
- Discussion on content and cost of elastic Architecture - Digital Architecture Design (3)
- Binary tree traversal series 01 - recursive traversal and recursive order
- Shell编程学习(二)变量、运算
- Is the securities account opened by caibang safe? Or is it safer to open in securities companies?
- Eight common probability distribution formulas and visualization
- redis数据持久化
- Flowable activiti7 countersign
- 斐波那契数列
猜你喜欢
随机推荐
The soul of the frame - Reflection
2022年监理工程师合同管理练习题及答案
通过列表修改字符串的坑
Validation数据校验注解
selenium的滑块验证码的模拟登录(猪八戒网站)
Flowable activiti7 countersign
【无标题】
Algorithem_Populating Next Right Pointers in Each Node
2022语言与智能技术竞赛再升级,推出NLP四大前沿任务
一个人怎么拍自媒体视频,三农领域的运营技巧
基于同态加密的PSI开源库-1
Randomforest, a package for random forest modeling in R language
IPEmotion采集J1939协议信号
(建议精读)this指北
53w字!阿里首推系统性能优化指南太香了,堪称性能优化最优解
redis-击穿、穿透、雪崩
Shell编程学习(二)变量、运算
搭建服务注册与发现中心
[source code analysis] encoding in style: a stylegan encoder for image to image translation
Controlling the release and introduction of rip routing based on Routing









