Not applicable
10-14-2018
08:28 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I try to read a json style data from a file ,and load the data to use TessellatedShapeBuilder make a Mesh or AnyGeometry.
The data has 27 faces,but only 3 faces show out(by eyes).like the pic below:
And no error comes out . It seems verything is right.
Before the question,I tried to find some information form the commutiy,about TessellatedShapeBuilder,which maybe useful for me.But I found some information about the TessellatedShapeBuilder limit or how to create solid or some else,but ,may not useful for this phenomenon?
Need help,could anybody give me any information about this?
Here is the codes:
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { string file_name = @"F:\data.txt"; Autodesk.Revit.DB.Document RevitDoc = commandData.Application.ActiveUIDocument.Document; string data = null; using (System.IO.StreamReader file = System.IO.File.OpenText(file_name)) { data = file.ReadToEnd(); } UIApplication uiapp = commandData.Application; UIDocument uidoc = uiapp.ActiveUIDocument; Autodesk.Revit.ApplicationServices.Application app = uiapp.Application; Autodesk.Revit.DB.Document doc = uidoc.Document; using (Transaction tx = new Transaction(doc)) { tx.Start("Create DirectShape"); try { TessellatedShapeBuilder builder = new TessellatedShapeBuilder(); builder.OpenConnectedFaceSet(false); JObject all_data = JObject.Parse(data); JArray ja_points = JArray.Parse(all_data["points"].ToString()); JArray ja_faces = JArray.Parse(all_data["faces"].ToString()); IList<XYZ> points_all = new List<XYZ>(); foreach (JToken point_tmp in ja_points) { JArray tmp_point = JArray.Parse(point_tmp.ToString()); XYZ a = new XYZ(double.Parse(tmp_point[0].ToString()), double.Parse(tmp_point[1].ToString()), double.Parse(tmp_point[2].ToString())); points_all.Add(a); } foreach (JToken points in ja_faces) { List<XYZ> args = new List<XYZ>(); JArray ja_points_face = JArray.Parse(points.ToString()); foreach (JToken index_number in ja_points_face) { int point_index = int.Parse(index_number.ToString()); XYZ tmp = points_all[point_index]; args.Add(tmp); } TessellatedFace face_tmp = new TessellatedFace(args, ElementId.InvalidElementId); builder.AddFace(face_tmp); } builder.CloseConnectedFaceSet(); builder.Target = TessellatedShapeBuilderTarget.AnyGeometry; builder.Fallback = TessellatedShapeBuilderFallback.Mesh; builder.Build(); TessellatedShapeBuilderResult result = builder.GetBuildResult(); ElementId categoryId = new ElementId(BuiltInCategory.OST_GenericModel); DirectShape ds = DirectShape.CreateElement(doc, categoryId); IList<GeometryObject> ilist_geometryobject = result.GetGeometricalObjects(); ds.SetShape(ilist_geometryobject); ds.Name = "Test"; } catch (Exception e) { message = e.Message; return Result.Failed; } tx.Commit(); } return Result.Succeeded; }
the data.txt file is below attachments. Which is like:
{ "points":[[0,0,0],[1,1,1],[2,1,3],...,[100,200,150]], "faces":[[1,2,3],[2,3,4,5,6],...,[10,11,20,40]], }
Solved! Go to Solution.