Unable to get the 2D geometry of familyinstnace

Unable to get the 2D geometry of familyinstnace

ritesh.solankeSKPPH
Enthusiast Enthusiast
1,126 Views
6 Replies
Message 1 of 7

Unable to get the 2D geometry of familyinstnace

ritesh.solankeSKPPH
Enthusiast
Enthusiast

Hello,

 

I am using the Revit SDK 2017 to read the 2D sheet data with following peace of code, here in case of element type as Autodesk.Revit.DB.Mesh I am getting whole 3D data of mesh. As I am parsing using the document as 3D view active. Can you help me to get the exact 2D geometry from this 3d view. 

 

foreach (GeometryObject geomObj in geomElem)
			{
			//	IList<XYZ> vertexArrList = new List<XYZ>();
				if (geomObj is Solid)
				{
					Solid soliObj = geomObj as Solid;
					if (soliObj != null)
					{
					//	Wall solidWall = soliObj as Wall;
						double zVal = 0.0;
						bool isZvalSet = false;
						{
							foreach (Edge geomEdge in soliObj.Edges)
							{
								IList<XYZ> arrList = geomEdge.Tessellate();
								
								foreach (XYZ array in arrList)
								{
									if (false == isZvalSet)
									{
										zVal = array.Z;
										isZvalSet = true;
									}
									if ((zVal == arrList[0].Z) && (zVal == arrList[1].Z))
										oVertexArrList.Add(array);
								}
							}
						}
					}
				}
				else if (geomObj is Line)
				{
					Line lineObjforInst = geomObj as Line;
					if (lineObjforInst != null)
						oVertexArrList = lineObjforInst.Tessellate();
				}
				else if (geomObj is Arc)
				{
					Arc arcObjforInst = geomObj as Arc;
					if (arcObjforInst != null)
						oVertexArrList = arcObjforInst.Tessellate();
				}
				else if (geomObj is NurbSpline)
				{
					NurbSpline numbSpline = geomObj as NurbSpline;
					if (numbSpline != null)
						oVertexArrList = numbSpline.Tessellate();
				}
				else if (geomObj is Ellipse)
				{
					Ellipse ellipseObjforInst = geomObj as Ellipse;
					if (ellipseObjforInst != null)
						oVertexArrList = ellipseObjforInst.Tessellate();
				}
				else if (geomObj is Autodesk.Revit.DB.Mesh)
				{
					Autodesk.Revit.DB.Mesh revitMesh = geomObj as Autodesk.Revit.DB.Mesh;
					if (revitMesh != null)
						oVertexArrList = revitMesh.Vertices;
				}
				else
				{
					GeometryInstance geoInst = geomObj as GeometryInstance;
					if (geoInst != null)
					{
						GeometryElement geoElemofInst = geoInst.GetSymbolGeometry();
						ProcessGeomElement(geoElemofInst, ref sbFileContent, ref oVertexArrList);
					}
				}
0 Likes
1,127 Views
6 Replies
Replies (6)
Message 2 of 7

jeremytammik
Autodesk
Autodesk

The exact 2D geometry can be tricky to obtain.

 

Maybe it is even impossible, since 'exact' may depend on different factors.

  

One way to get exact 2D geometry from a 3D view is to project it.

  

I do so in my room editor to retrieve 2D projected geometry for family instances:

 

https://github.com/jeremytammik/RoomEditorApp

 

I use a very convoluted approach which is probably not optimal for your needs, but very interesting in itself.

 

https://thebuildingcoder.typepad.com/blog/about-the-author.html#5.21

 

Cheers,

 

Jeremy

 



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

0 Likes
Message 3 of 7

ritesh.solankeSKPPH
Enthusiast
Enthusiast

Thanks 

0 Likes
Message 4 of 7

ritesh.solankeSKPPH
Enthusiast
Enthusiast

Hello Jeremy,

 

can you explain how to "One way to get exact 2D geometry from a 3D view is to project it." project the 3D as I am struggling to to get 2D geometry for  Solid geometry.

 

Thanks,

Ritesh

0 Likes
Message 5 of 7

ritesh.solankeSKPPH
Enthusiast
Enthusiast

Hello,

 

How to get the 2D geometry from the Autodesk.Revit.DB.Mesh, as we get the triangulated mesh data.

 

Thanks,

Ritesh

0 Likes
Message 6 of 7

jeremytammik
Autodesk
Autodesk

A 3D mesh has no 2D geometry.

 

It is all 3D.

 

The one and only was to obtain 2D data from 3D is to use a projection:

 

https://en.wikipedia.org/wiki/3D_projection

 

The simplest project in most cases is to simply remove the Z coordinate data.

 

Cheers,

 

Jeremy

 



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

0 Likes
Message 7 of 7

ritesh.solankeSKPPH
Enthusiast
Enthusiast

Yes we are currently doing by removing Z, but it overlaps the edges as there are many edges for triangulated Mesh. In other solution of projection how to project the Mesh data on planer face, as such i don't found any method in Mesh class, here is one method Mesh get_Transformed(Transform transform);  can we use it ?

0 Likes