public static Grevit.Types.Point ToGrevitPoint(this SketchUpNET.Vertex v, SketchUpNET.Transform t = null) { if (t != null) { SketchUpNET.Vertex vertex = t.GetTransformed(v); return(new Grevit.Types.Point(vertex.X, vertex.Y, vertex.Z)); } else { return(new Grevit.Types.Point(v.X, v.Y, v.Z)); } }
public static ComponentCollection Translate(string filename) { SketchUpNET.SketchUp skp = new SketchUpNET.SketchUp(); if (skp.LoadModel(filename)) { Grevit.Types.ComponentCollection components = new ComponentCollection() { Items = new List <Component>() }; components.scale = 3.28084; components.update = true; components.delete = false; foreach (SketchUpNET.Instance instance in skp.Instances) { SketchUpNET.Transform transform = instance.Transformation; transform.Data[12] /= 39.3701; transform.Data[13] /= 39.3701; transform.Data[14] /= 39.3701; string elementType = instance.Parent.Name.ToLower(); string family = instance.Parent.Name; string type = instance.Parent.Name; if (instance.Parent.Description.Contains(";")) { string[] data = instance.Parent.Description.Split(';'); family = data[0]; type = data[1]; } if (elementType.Contains("wall")) { foreach (SketchUpNET.Surface surface in instance.Parent.Surfaces) { components.Items.Add(new WallProfileBased(family, type, new List <Types.Parameter>(), surface.ToGrevitOutline(transform), "") { GID = instance.Guid }); } } else if (elementType.Contains("grid")) { foreach (SketchUpNET.Edge edge in instance.Parent.Edges) { components.Items.Add(new Grid(new List <Types.Parameter>(), edge.Start.ToGrevitPoint(transform), edge.End.ToGrevitPoint(transform), instance.Parent.Name) { GID = instance.Guid }); } } else if (elementType.Contains("line")) { foreach (SketchUpNET.Edge edge in instance.Parent.Edges) { components.Items.Add(new RevitLine() { curve = edge.ToGrevitLine(transform), isModelCurve = true, isDetailCurve = false, isRoomBounding = false, parameters = new List <Parameter>(), GID = instance.Guid, FamilyOrStyle = family, TypeOrLayer = type }); } } else if (elementType.Contains("floor")) { foreach (SketchUpNET.Surface surface in instance.Parent.Surfaces) { Types.Point bottom = transform.GetTransformed(surface.Vertices[0]).ToGrevitPoint(); int ctr = surface.Vertices.Count / 2; Types.Point top = transform.GetTransformed(surface.Vertices[ctr]).ToGrevitPoint(); components.Items.Add(new Slab() { FamilyOrStyle = family, TypeOrLayer = type, parameters = new List <Types.Parameter>(), structural = true, height = 1, surface = surface.ToGrevitProfile(transform), bottom = bottom, top = top, slope = top.z - bottom.z, GID = instance.Guid, levelbottom = "", }); } } else if (elementType.Contains("column")) { Grevit.Types.Profile profile = null; Grevit.Types.Point top = null; SketchUpNET.Vertex v = new SketchUpNET.Vertex(0, 0, 0); Grevit.Types.Point btm = v.ToGrevitPoint(transform); foreach (SketchUpNET.Surface surface in instance.Parent.Surfaces) { if (surface.Normal.Z == 1) { top = new Types.Point(v.ToGrevitPoint(transform).x, v.ToGrevitPoint(transform).y, surface.Vertices[0].ToGrevitPoint(transform).z); } } components.Items.Add(new Grevit.Types.Column(family, type, new List <Types.Parameter>(), btm, top, "", true) { GID = instance.Guid }); } } return(components); } return(null); }