当前位置:网站首页>Revit secondary development - link file collision detection
Revit secondary development - link file collision detection
2022-07-07 22:22:00 【Hey, hey, hey, hey, hey】
The function is probably to detect the elements in the project ( Include components in linked files ) Conflict or not
General train of thought :
1、 First get all the converted components in the linked file solid, Transformed solid You can directly detect the elements in the project
2、 Get all edges of the element to be compared 、 Noodles 、solid
3、 If the element has edges : With edges and solid Make a test , If it is not detected, the face and edge need to be detected ; If the element has no edges : Test with face and face
----------------------------------------------------------------------
Filter linked file internals
//key: Link to the file id value: Internals id
Dictionary<ElementId,List<ElementId>> m_dicLinkIns;
// Filter linked files
FilteredElementCollector fecLinks = new FilteredElementCollector(doc);
List<Element> lstElem = fecLinks.ofClass(typeof(RevitLinkInstance)).ToElements().ToList();
// Filter internals
foreach(Element elem in lstElem)
{
RevitLinkInstance rvtLinkIns = elem as RevitLinkInstance;
if(rvtLinkIns == null) continue;
// Get the linked file document
Document linkDoc = rvtLinkIns.GetLinkDocument();
if(linkDoc == null) continue;
FilteredElementCollector fecLinkElems = new FilteredElementCollector;
ElementClassFilter insFilter = new ElementClassFilter (typeof(FamilyInstance));
ElementClassFilter hostFilter = new ElementClassFilter (typeof(HostObject));
LogicalOrFilter filter = new LogicalOrFilter (insFilter,hostFilter);
List<ElementId> lstEids = fecLinkElems.WherePasses(filter).ToElementIds().ToList();
m_dicLinkIns.Add(rvtLinkIns.id,lstEids);
}
Link the components in the file solid convert , And get the face 、 edge
List<SolidModel> m_lstModels;
private void TransformSolid(Document doc,Element elem)
{
ElementId linkId = null;
RevitLinkInstance rvtLinkIns = null;
if(elem.Document.IsLinked)
{// If it is a component of a linked document , You need to find the corresponding link file
foreach(Elementid eid in m_dicLinkIns.Keys)
{
if(m_dicLinkIns[eid].Contains(elem.Id))
{
rvtLinkIns = doc.GetElement(eid) as RevitLinkInstance;
break;
}
}
}
List<Solid> lstSolids = GetSolids(elem);
foreach(Solid solid in lstSolids)
{
Solid tempSolid = solid;
if(rvtLinkIns != null)// Generate a converted solid
tempSolid = SolidUtils.CreateTransformed(solid,rvtLinkIns.GetTransform());
m_lstModels.lstSolids.Add(tempSolid);
foreach(Face face in tempSolid.Faces)
{// Get face
m_lstModels.lstFaces.Add(face);
}
foreach(Edge edge in tempSolid.Edges)
{// Get edge
Curve curve = edge.AsCurve();
m_lstModels.lstEdges.Add(curve);
}
}
}
If you don't know how to get elements Solid, You can check online , You can also look at another article that I wrote . At the bottom of the link
Collision detection , Two cases
1. Entities have edges , Use entities and edges to measure , If it is not detected, use the face and edge to measure ;
foreach(Curve curve in rightModel.lstEdges)
{
foreach(Solid solid in leftModel.lstSolids)
{
SolidCurveIntersectionoPtions opt = new SolidCurveIntersectionoPtions();
//solid Check with the edge
SolidCurveIntersection result = solid.IntersectWithCurve(curve,opt);
if(result.SegmentCount > 0)
{
// The collision
}
else
{
foreach(Face face in solid.Faces)
{
IntersectionResultArray array = null;
//solid Check the face and edge of
SetComparisonResult result2 = face.Intersect(curve,out array);
if(array != null && result2 != SetComparisonResult.Disjoint)
{
// The collision
}
}
}
}
}
2. Entities have no edges , Test with face to face
foreach(Face rface in rightModel.lstFaces)
{
foreach(Face lface in leftModel.lstFaces)
{
Curve curve = null;
FaceIntersectionFaceResult result = lface.Intersect(rface, out curve);
if(result == FaceIntersectionFaceResult.Intersecting)
{
// The collision
}
}
}SolidModel class
public class SolidModel
{
// Elements id
public ElementId id {get;set;}
// Element entities
public List<Solid> lstSolids {get;set;}
// Element edge
public List<Curve> lstEdges {get;set;}
// Element face
public List<Face> lstFaces {get;set;}
public SolidModel()
{
lstSolids =new List<Solid>();
lstEdges =new List<Curve>();
lstFaces =new List<Face>();
}
}-------------------------------------------
Code for a reference , Can't run directly .
边栏推荐
- The free styling service of Dyson's official direct store is now open for appointment. Pioneer Technology interprets the styling concept of hair care and helps consumers unlock diversified and shiny s
- MIT6.S081-Lab9 FS [2021Fall]
- 如何实现横版游戏中角色的移动控制
- Oracle advanced (VI) Oracle expdp/impdp details
- Jerry's configuration of TWS cross pairing [article]
- How to realize the movement control of characters in horizontal game
- Kirin Xin'an operating system derivative solution | storage multipath management system, effectively improving the reliability of data transmission
- Tsconfig of typescript TS basics JSON configuration options
- 嵌入式开发:如何为项目选择合适的RTOS?
- Have you ever been confused? Once a test / development programmer, ignorant gadget C bird upgrade
猜你喜欢

How does win11 unblock the keyboard? Method of unlocking keyboard in win11

Reptile combat (VII): pictures of the king of reptiles' heroes

Redis - basic use (key, string, list, set, Zset, hash, geo, bitmap, hyperloglog, transaction)

How to choose the appropriate automated testing tools?

Where is the big data open source project, one-stop fully automated full life cycle operation and maintenance steward Chengying (background)?

Build your own website (18)

海外代理推荐

NVR硬盤錄像機通過國標GB28181協議接入EasyCVR,設備通道信息不顯示是什麼原因?
![[开源] .Net ORM 访问 Firebird 数据库](/img/a2/4eff4f0af53bf3b9839a73019a212f.png)
[开源] .Net ORM 访问 Firebird 数据库

PDF文档签名指南
随机推荐
How does win11 time display the day of the week? How does win11 display the day of the week today?
How to choose the appropriate automated testing tools?
反爬通杀神器
Vs custom template - take the custom class template as an example
Song list 11111
[open source] Net ORM accessing Firebird database
Cv2.resize function reports an error: error: (-215:assertion failed) func= 0 in function ‘cv::hal::resize‘
三元表达式、各生成式、匿名函数
PKPM 2020软件安装包下载及安装教程
Matplotlib快速入门
Interview question 01.02 Determine whether it is character rearrangement - auxiliary array algorithm
648. Word replacement
OpenGL job - texture
Jerry's about TWS pairing mode configuration [chapter]
强化学习-学习笔记9 | Multi-Step-TD-Target
如何实现横版游戏中角色的移动控制
[azure microservice service fabric] start the performance monitor in the SF node and set the method of capturing the process
Ternary expressions, generative expressions, anonymous functions
[open source] Net ORM accessing Firebird database
Lingyun going to sea | saihe & Huawei cloud: jointly help the sustainable development of cross-border e-commerce industry