<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Create Solid from CAD polylines in Revit API Forum</title>
    <link>https://forums.autodesk.com/t5/revit-api-forum/create-solid-from-cad-polylines/m-p/11236433#M18500</link>
    <description>&lt;P&gt;You will virtually never be able to close a Hermite spline from a set of polyline points, the end tangents of the spline need to be compatible. What you'll end up with also wouldn't be representative of the polyline i.e. the acute changes of direction would be significantly smoothed out. If you try to close it by making the first point the last then it may even become self intersecting.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You should break your polyline profile into a number of splines within your CurveLoop. Perhaps considering the significance of angle formed between n and n-1 against n and n+1 in terms of deciding if the polyline should be split at that point.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I can't understand what you are doing with the shape builder.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Do you have an example to share of the DWG you are inputting?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 15 Jun 2022 11:30:18 GMT</pubDate>
    <dc:creator>RPTHOMAS108</dc:creator>
    <dc:date>2022-06-15T11:30:18Z</dc:date>
    <item>
      <title>Create Solid from CAD polylines</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/create-solid-from-cad-polylines/m-p/11235472#M18498</link>
      <description>&lt;P&gt;I've been working on a macros that creates a solid from a CAD file:&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;UIDocument uidoc = this.ActiveUIDocument;
			Document doc = uidoc.Document;
			StringBuilder stb = new StringBuilder();
			
			Element dwg=doc.GetElement(uidoc.Selection.PickObject(ObjectType.Element));
			
			Options opt= new Options();
			opt.ComputeReferences = true;
			opt.IncludeNonVisibleObjects=false;
			opt.View = doc.ActiveView;
			GeometryElement geo = dwg.get_Geometry(opt);

			//Tuple&amp;lt;int,List&amp;lt;XYZ&amp;gt;&amp;gt; myTuple = new Tuple&amp;lt;int, List&amp;lt;XYZ&amp;gt;()&amp;gt;() ;
			List&amp;lt;Tuple&amp;lt;int,IList&amp;lt;XYZ&amp;gt;&amp;gt;&amp;gt; myTuple = new List&amp;lt;Tuple&amp;lt;int, IList&amp;lt;XYZ&amp;gt;&amp;gt;&amp;gt;();
			
			foreach (GeometryObject g in geo) {
				if (g as GeometryInstance != null) {
					GeometryInstance geoInst=g as GeometryInstance;
					foreach (GeometryObject obj in geoInst.GetInstanceGeometry()) {
						if (obj as PolyLine != null) {
							PolyLine pln=obj as PolyLine;
							IList&amp;lt;XYZ&amp;gt; coordinates= pln.GetCoordinates();
							myTuple.Add(new Tuple&amp;lt;int,IList&amp;lt;XYZ&amp;gt;&amp;gt; ( pln.Id,coordinates) );
						}
					} 
				}
			}
			myTuple= myTuple.OrderBy(X=&amp;gt;X.Item1).ToList();
			
			SolidOptions solidOpt = new SolidOptions(ElementId.InvalidElementId,ElementId.InvalidElementId);
			Transaction tr = new Transaction(doc,"solid");
			tr.Start();	
			
//			for (int i = 0; i &amp;lt; myTuple.Count -1 ; i++) {
//				
//				if (HermiteSpline.Create(myTuple[i].Item2,false).IsClosed == true &amp;amp;&amp;amp; HermiteSpline.Create(myTuple[i+1].Item2,false).IsClosed == true) {
////					stb.AppendLine("closed");
////					CurveLoop cl1 = new CurveLoop();
////					cl1.Append(HermiteSpline.Create(myTuple[i].Item2,false));
////					
////					CurveLoop cl2 = new CurveLoop();
////					cl2.Append(HermiteSpline.Create(myTuple[i+1].Item2,false));
////					
////					Solid loft = GeometryCreationUtilities.CreateBlendGeometry(cl1,cl2,null); 
//					
//					
//				}
//				CurveLoop cl1 = new CurveLoop();
//				cl1.Append(HermiteSpline.Create(myTuple[i].Item2,false));
//				
//				CurveLoop cl2 = new CurveLoop();
//				cl2.Append(HermiteSpline.Create(myTuple[i+1].Item2,false));
//				
//				Solid loft = GeometryCreationUtilities.CreateBlendGeometry(cl1,cl2,null); 
//			}
			
			for (int i = 0; i &amp;lt; myTuple.Count -1; i++) {
				List&amp;lt;CurveLoop&amp;gt; profile = new List&amp;lt;CurveLoop&amp;gt;();
				CurveLoop cl1=new CurveLoop();
				CurveLoop cl2=new CurveLoop();
				cl1.Append(HermiteSpline.Create(myTuple[i].Item2,false));
				cl2.Append(HermiteSpline.Create(myTuple[i+1].Item2,false));
				profile.Add(cl1);
				profile.Add(cl2);
				Solid loft = GeometryCreationUtilities.CreateLoftGeometry(profile,solidOpt);
				
			}&lt;/LI-CODE&gt;&lt;P&gt;Sometimes it Keeps telling me there are opened curves which in turns is not true as when I picked the bend top and bottom face, I see a closed boundary.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="miguelgutierrezD74CZ_1-1655252811363.jpeg" style="width: 600px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/1079886i8EC33DF75DA5487E/image-size/medium?v=v2&amp;amp;px=400" role="button" title="miguelgutierrezD74CZ_1-1655252811363.jpeg" alt="miguelgutierrezD74CZ_1-1655252811363.jpeg" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Other times it just fails. I've been struggling using createBlendSolid and Loft solid. Even direct shape form:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="miguelgutierrezD74CZ_2-1655252822886.png" style="width: 600px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/1079887i6D3619F7526F7FB1/image-size/medium?v=v2&amp;amp;px=400" role="button" title="miguelgutierrezD74CZ_2-1655252822886.png" alt="miguelgutierrezD74CZ_2-1655252822886.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;			UIDocument uidoc = this.ActiveUIDocument;
			Document doc = uidoc.Document;
			StringBuilder stb = new StringBuilder();
			
			Element dwg=doc.GetElement(uidoc.Selection.PickObject(ObjectType.Element));
			Options opt= new Options();
			opt.ComputeReferences = true;
			opt.IncludeNonVisibleObjects=false;
			opt.View = doc.ActiveView;
			GeometryElement geo = dwg.get_Geometry(opt);
			int count=0;
			Dictionary&amp;lt;int,IList&amp;lt;XYZ&amp;gt;&amp;gt; dictionary = new Dictionary&amp;lt;int, IList&amp;lt;XYZ&amp;gt;&amp;gt;();
			
			foreach (GeometryObject g in geo) {
				if (g as GeometryInstance != null) {
					
					GeometryInstance geoInst=g as GeometryInstance;
					foreach (GeometryObject obj in geoInst.GetInstanceGeometry()) {
						if (obj as PolyLine != null) {
							PolyLine pln=obj as PolyLine;
							IList&amp;lt;XYZ&amp;gt; coordinates= pln.GetCoordinates();
							dictionary.Add(count, coordinates);
							count += 1;

						}
						
					} 
					
				}
				
			}

			
			Transaction tr = new Transaction(doc,"solid - afry");
			tr.Start();
			IList&amp;lt;Element&amp;gt; materials = new FilteredElementCollector(doc).OfClass(typeof(Material)).ToElements().ToList();
			Material mat = null;
			foreach (Material mate in materials) {
				if (mate.Name == "Concrete, Cast In Situ") {
					mat=mate;
				}
			}
			TessellatedShapeBuilder builder= new TessellatedShapeBuilder();
			builder.OpenConnectedFaceSet(true);
			
			foreach (KeyValuePair&amp;lt;int,IList&amp;lt;XYZ&amp;gt;&amp;gt; pair in dictionary) {
				//stb.AppendLine(pair.Key.ToString());
				IList&amp;lt;XYZ&amp;gt; outerLoopVertices = new List&amp;lt;XYZ&amp;gt;();
				for (int i = 0; i &amp;lt; pair.Value.Count - 2; i++) {
					outerLoopVertices.Add(pair.Value[i]);
					outerLoopVertices.Add(pair.Value[i+1]);
					outerLoopVertices.Add(pair.Value[i+2]);
				}
//				TessellatedFace tesseFace= new TessellatedFace(pair.Value,mat.Id);
//				if (builder.DoesFaceHaveEnoughLoopsAndVertices(tesseFace)) {
//					builder.AddFace(tesseFace);
//					//stb.AppendLine(tesseFace.ToString());
//					//stb.AppendLine(tesseFace.GetBoundaryLoops().ToString());
//				}
				TessellatedFace tesseFace= new TessellatedFace(outerLoopVertices,mat.Id);
				if (builder.DoesFaceHaveEnoughLoopsAndVertices(tesseFace)) {
					builder.AddFace(tesseFace);
				}
			}
			
			builder.CloseConnectedFaceSet();
			
			builder.Target = TessellatedShapeBuilderTarget.Solid;
			builder.Fallback=TessellatedShapeBuilderFallback.Abort;
			
			builder.Build();
			
			TessellatedShapeBuilderResult result = builder.GetBuildResult();
			
			ElementId categoryId= new ElementId(BuiltInCategory.OST_GenericModel);
			DirectShape ds=DirectShape.CreateElement(doc,categoryId);
			ds.SetShape(result.GetGeometricalObjects());
			ds.Name="Presa";

			tr.Commit();&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What we expect:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="miguelgutierrezD74CZ_0-1655251889613.png" style="width: 600px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/1079885i974D26034A0CBACD/image-size/medium?v=v2&amp;amp;px=400" role="button" title="miguelgutierrezD74CZ_0-1655251889613.png" alt="miguelgutierrezD74CZ_0-1655251889613.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;We have a bunch of DWG data and it takes a lot to manually creating blend components. Any suggestions on how to improve my code or find the issue of this matter?&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="miguelgutierrezD74CZ_3-1655252948847.png" style="width: 600px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/1079888iF5BCF81C2327C982/image-size/medium?v=v2&amp;amp;px=400" role="button" title="miguelgutierrezD74CZ_3-1655252948847.png" alt="miguelgutierrezD74CZ_3-1655252948847.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Best regards, Miguel G&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 15 Jun 2022 00:30:27 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/create-solid-from-cad-polylines/m-p/11235472#M18498</guid>
      <dc:creator>miguel.gutierrezD74CZ</dc:creator>
      <dc:date>2022-06-15T00:30:27Z</dc:date>
    </item>
    <item>
      <title>Re: Create Solid from CAD polylines</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/create-solid-from-cad-polylines/m-p/11235778#M18499</link>
      <description>&lt;P&gt;Yes, two suggestions. Whenever you run into an issue trying to create a solid via the API like this, it may help to test the solid creation manually in the end user interface using the same underlying geometry data, as described in:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://thebuildingcoder.typepad.com/blog/2009/07/debug-geometric-form-creation.html" target="_blank"&gt;https://thebuildingcoder.typepad.com/blog/2009/07/debug-geometric-form-creation.html&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The UI will often provide much more useful information on why a specific solid generation fails.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It may even help to implement your own little curve loop visualisation:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://thebuildingcoder.typepad.com/blog/2013/04/geosnoop-net-boundary-curve-loop-visualisation.html" target="_blank"&gt;https://thebuildingcoder.typepad.com/blog/2013/04/geosnoop-net-boundary-curve-loop-visualisation.html&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can also mix the two a bit: generate model curves to represent your curve loops and the extrusion paths, so that you can see better exactly what is being calculated, in case the solid generation fails.&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 15 Jun 2022 05:11:29 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/create-solid-from-cad-polylines/m-p/11235778#M18499</guid>
      <dc:creator>jeremy_tammik</dc:creator>
      <dc:date>2022-06-15T05:11:29Z</dc:date>
    </item>
    <item>
      <title>Re: Create Solid from CAD polylines</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/create-solid-from-cad-polylines/m-p/11236433#M18500</link>
      <description>&lt;P&gt;You will virtually never be able to close a Hermite spline from a set of polyline points, the end tangents of the spline need to be compatible. What you'll end up with also wouldn't be representative of the polyline i.e. the acute changes of direction would be significantly smoothed out. If you try to close it by making the first point the last then it may even become self intersecting.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You should break your polyline profile into a number of splines within your CurveLoop. Perhaps considering the significance of angle formed between n and n-1 against n and n+1 in terms of deciding if the polyline should be split at that point.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I can't understand what you are doing with the shape builder.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Do you have an example to share of the DWG you are inputting?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 15 Jun 2022 11:30:18 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/create-solid-from-cad-polylines/m-p/11236433#M18500</guid>
      <dc:creator>RPTHOMAS108</dc:creator>
      <dc:date>2022-06-15T11:30:18Z</dc:date>
    </item>
    <item>
      <title>Re: Create Solid from CAD polylines</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/create-solid-from-cad-polylines/m-p/11237426#M18501</link>
      <description>&lt;P&gt;That's right, UI seems to blend the solid from the dwg polylines. Fair enough, I'll represent my curve loops one at the time to have more insights. Stay bless Jeremy!&lt;/P&gt;</description>
      <pubDate>Wed, 15 Jun 2022 16:48:40 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/create-solid-from-cad-polylines/m-p/11237426#M18501</guid>
      <dc:creator>miguel.gutierrezD74CZ</dc:creator>
      <dc:date>2022-06-15T16:48:40Z</dc:date>
    </item>
    <item>
      <title>Re: Create Solid from CAD polylines</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/create-solid-from-cad-polylines/m-p/11237576#M18502</link>
      <description>&lt;P&gt;I've not bear in mind that small detail. I'll follow your recommendations , thanks Thomas for the insights! Regarding the direct shape, My goal was to input the polylines points and make a solid out of them. Is there any changes I might need to do to the direct shape code I provided above?&lt;/P&gt;&lt;P&gt;I'm attaching the DWG file too:&lt;/P&gt;</description>
      <pubDate>Wed, 15 Jun 2022 18:26:58 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/create-solid-from-cad-polylines/m-p/11237576#M18502</guid>
      <dc:creator>miguel.gutierrezD74CZ</dc:creator>
      <dc:date>2022-06-15T18:26:58Z</dc:date>
    </item>
    <item>
      <title>Re: Create Solid from CAD polylines</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/create-solid-from-cad-polylines/m-p/11244551#M18503</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/11924778"&gt;@miguel.gutierrezD74CZ&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Having looked at the dwg I can make the following comments:&lt;/P&gt;&lt;P&gt;There are a lot of overlapping lines that need to be resolved into single lines. Generally the Polylines will be formed from connected lines of the same layer/colour. It is not obvious how this will be treated if you have two lines overlapping i.e. will a flat closed loop of two lines be created.&lt;/P&gt;&lt;P&gt;When you import the dwg you should use the option that doesn't correct the out of axis lines. This option straightens lines and could make certain loops open, there is a loop on layer 'E2990500' that suffers from this.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="220619a.PNG" style="width: 780px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/1081596iBFDDBF958E5B589A/image-size/large?v=v2&amp;amp;px=999" role="button" title="220619a.PNG" alt="220619a.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;In any case you can exclude these loops by reviewing CurveLoop.IsOpen after you form them.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For the below I used NurbSpline and Lines to create the loft, each set of lines was resolved into a loop and each loop was coloured in a sequence of Red/Green/Blue (open loops where coloured magenta).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Plotting and colouring the loops in this way allows you to see any errors i.e. if a loop at a certain level was formed from two open loops (instead of one closed loop) then the colour sequence would be discontinuous.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="220619b.PNG" style="width: 999px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/1081597i5AA57D2264B6391B/image-size/large?v=v2&amp;amp;px=999" role="button" title="220619b.PNG" alt="220619b.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Resulting loft with omitted open loop for loft coloured magenta&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 19 Jun 2022 12:32:35 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/create-solid-from-cad-polylines/m-p/11244551#M18503</guid>
      <dc:creator>RPTHOMAS108</dc:creator>
      <dc:date>2022-06-19T12:32:35Z</dc:date>
    </item>
    <item>
      <title>Re: Create Solid from CAD polylines</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/create-solid-from-cad-polylines/m-p/11244803#M18504</link>
      <description>&lt;P&gt;Thanks for replying Thomas and for the recommendations you've provide as well. So you made it by drawing lines as well, gonna give it shoot following your steps then.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Cheers dear colleague!&lt;/P&gt;</description>
      <pubDate>Sun, 19 Jun 2022 17:49:40 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/create-solid-from-cad-polylines/m-p/11244803#M18504</guid>
      <dc:creator>miguel.gutierrezD74CZ</dc:creator>
      <dc:date>2022-06-19T17:49:40Z</dc:date>
    </item>
  </channel>
</rss>

