Exemplo n.º 1
0
 static void Main(string[] args)
 {
     if (args.Length > 1)
     {
         SketchUpNET.SketchUp skp = new SketchUpNET.SketchUp();
         if (skp.LoadModel(args[1]))
         {
             // do something
         }
     }
 }
Exemplo n.º 2
0
        public void TestInnerLoop()
        {
            SketchUpNET.SketchUp skp = new SketchUpNET.SketchUp();
            skp.Layers = new List <Layer>()
            {
                new Layer("Layer0")
            };
            skp.Surfaces = new List <Surface>();
            skp.Curves   = new List <Curve>();
            skp.Edges    = new List <Edge>();
            List <SketchUpNET.Vertex> Verticies = new List <SketchUpNET.Vertex>();

            SketchUpNET.Loop OuterEdges = new SketchUpNET.Loop();
            OuterEdges.Edges = new List <Edge>();
            {
                OuterEdges.Edges.Add(new SketchUpNET.Edge(new Vertex(0, 0, 0), new Vertex(500, 0, 0), "Layer0"));
                OuterEdges.Edges.Add(new SketchUpNET.Edge(new Vertex(500, 0, 0), new Vertex(500, 500, 0), "Layer0"));
                OuterEdges.Edges.Add(new SketchUpNET.Edge(new Vertex(500, 500, 0), new Vertex(0, 500, 0), "Layer0"));
                OuterEdges.Edges.Add(new SketchUpNET.Edge(new Vertex(0, 500, 0), new Vertex(0, 0, 0), "Layer0"));
            }

            List <Loop> InnerLoops = new List <Loop>();

            {
                SketchUpNET.Loop InnerEdges = new SketchUpNET.Loop();
                InnerEdges.Edges = new List <Edge>();
                InnerEdges.Edges.Add(new SketchUpNET.Edge(new Vertex(100, 100, 0), new Vertex(400, 100, 0), "Layer0"));
                InnerEdges.Edges.Add(new SketchUpNET.Edge(new Vertex(400, 100, 0), new Vertex(400, 400, 0), "Layer0"));
                InnerEdges.Edges.Add(new SketchUpNET.Edge(new Vertex(400, 400, 0), new Vertex(100, 400, 0), "Layer0"));
                InnerEdges.Edges.Add(new SketchUpNET.Edge(new Vertex(100, 400, 0), new Vertex(100, 100, 0), "Layer0"));
                InnerLoops.Add(InnerEdges);
            }

            SketchUpNET.Surface s = new SketchUpNET.Surface(OuterEdges, InnerLoops, null, 0, Verticies, null, "Layer0", null, null);
            skp.Surfaces.Add(s);


            skp.WriteNewModel(@"TempModel.skp");
            skp.LoadModel(@"TempModel.skp");

            Assert.IsTrue(skp.Surfaces.Count == 1);
            Assert.IsTrue(skp.Surfaces[0].InnerEdges.Count == 1);
            Assert.IsTrue(skp.Surfaces[0].InnerEdges[0].Edges.Count == 4);
            Assert.IsTrue(skp.Surfaces[0].OuterEdges.Edges.Count == 4);
        }
Exemplo n.º 3
0
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            // Get Revit Environment
            UIApplication uiApp = commandData.Application;
            Document doc = uiApp.ActiveUIDocument.Document;
            UIDocument uidoc = uiApp.ActiveUIDocument;

            GrevitBuildModel c = new GrevitBuildModel(doc);
            GrevitBuildModel.Scale = 3.28084;

            System.Windows.Forms.OpenFileDialog filedialog = new System.Windows.Forms.OpenFileDialog();
            filedialog.Multiselect = false;
            if (filedialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                SketchUpNET.SketchUp skp = new SketchUpNET.SketchUp();
                if (skp.LoadModel(filedialog.FileName))
                {
                    Grevit.Types.ComponentCollection components = new ComponentCollection() { Items = new List<Component>() };

                    foreach (SketchUpNET.Instance instance in skp.Instances)
                    {
                        if (instance.Name.ToLower().Contains("wall"))
                        {
                            foreach (SketchUpNET.Surface surface in instance.Parent.Surfaces)
                            {
                                components.Items.Add(new WallProfileBased(instance.Parent.Name, instance.Parent.Name, new List<Types.Parameter>(), surface.ToGrevitOutline(instance.Transformation), "") { GID = instance.Guid });
                            }
                        }


                        if (instance.Name.ToLower().Contains("floor"))
                        {
                            foreach (SketchUpNET.Surface surface in instance.Parent.Surfaces)
                            {
                                Types.Point bottom = instance.Transformation.GetTransformed(surface.Vertices[0]).ToGrevitPoint();
                                int ctr = surface.Vertices.Count / 2;
                                Types.Point top = instance.Transformation.GetTransformed(surface.Vertices[ctr]).ToGrevitPoint();



                                components.Items.Add(new Slab()
                                {
                                    FamilyOrStyle = instance.Parent.Name,
                                    TypeOrLayer = instance.Parent.Name,
                                    parameters = new List<Types.Parameter>(),
                                    structural = true,
                                    height = 1,
                                    surface =
                                        surface.ToGrevitProfile(instance.Transformation),
                                    bottom = bottom,
                                    top = top,
                                    slope = top.z - bottom.z,
                                    GID = instance.Guid,
                                    levelbottom = "",
                                });
                            }
                        }

                        if (instance.Name.ToLower().Contains("column"))
                        {
                            Grevit.Types.Profile profile = null;
                            Grevit.Types.Point top = null;
                            Grevit.Types.Point btm = new Types.Point(instance.Transformation.X, instance.Transformation.Y, instance.Transformation.Z);

                            foreach (SketchUpNET.Surface surface in instance.Parent.Surfaces)
                            {

                                if (surface.Normal.Z == 1)
                                {
                                    top = new Types.Point(instance.Transformation.X, instance.Transformation.Y,
                                        surface.Vertices[0].ToGrevitPoint(instance.Transformation).z);
                                }

                            }

                            components.Items.Add(new Grevit.Types.Column(instance.Parent.Name, instance.Parent.Name, new List<Types.Parameter>(), btm, top, "", true)
                            {
                                GID = instance.Guid
                            });
                        }



                    }

                    c.BuildModel(components);

                }

            }



            // Return Success
            return Result.Succeeded;
        }
Exemplo n.º 4
0
        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);
        }
Exemplo n.º 5
0
        private void ConvertToSketchup(string path, string name)
        {
            // Read source shape file
            ShapeDataReader reader = new ShapeDataReader($"{Path.Combine(path, name)}.shp");

            var mbr = reader.ShapefileBounds;

            var result = reader.ReadByMBRFilter(mbr);

            double bx;
            double by;

            var shapeFeature = result.ToList()[0];

            bx = shapeFeature.BoundingBox.MinX;
            by = shapeFeature.BoundingBox.MinY;

            List <Coordinate> coordsForSketchup = new List <Coordinate>();

            foreach (var co in shapeFeature.Geometry.Coordinates)
            {
                coordsForSketchup.Add(new Coordinate(co.X - bx, co.Y - by, 0));
            }

            var csFactory = new CoordinateSystemFactory();
            var ctFactory = new CoordinateTransformationFactory();

            var osgb36 = csFactory.CreateFromWkt("PROJCS[\"OSGB 1936 / British National Grid\",GEOGCS[\"OSGB 1936\",DATUM[\"OSGB_1936\",SPHEROID[\"Airy 1830\",6377563.396,299.3249646,AUTHORITY[\"EPSG\",\"7001\"]],TOWGS84[446.448,-125.157,542.06,0.15,0.247,0.842,-20.489],AUTHORITY[\"EPSG\",\"6277\"]],PRIMEM[\"Greenwich\",0,AUTHORITY[\"EPSG\",\"8901\"]],UNIT[\"degree\",0.0174532925199433,AUTHORITY[\"EPSG\",\"9122\"]],AUTHORITY[\"EPSG\",\"4277\"]],PROJECTION[\"Transverse_Mercator\"],PARAMETER[\"latitude_of_origin\",49],PARAMETER[\"central_meridian\",-2],PARAMETER[\"scale_factor\",0.9996012717],PARAMETER[\"false_easting\",400000],PARAMETER[\"false_northing\",-100000],UNIT[\"metre\",1,AUTHORITY[\"EPSG\",\"9001\"]],AXIS[\"Easting\",EAST],AXIS[\"Northing\",NORTH],AUTHORITY[\"EPSG\",\"27700\"]]");
            var wgs84  = csFactory.CreateFromWkt("GEOGCS[\"WGS 84\",DATUM[\"WGS_1984\",SPHEROID[\"WGS 84\",6378137,298.257223563,AUTHORITY[\"EPSG\",\"7030\"]],AUTHORITY[\"EPSG\",\"6326\"]],PRIMEM[\"Greenwich\",0,AUTHORITY[\"EPSG\",\"8901\"]],UNIT[\"degree\",0.0174532925199433,AUTHORITY[\"EPSG\",\"9122\"]],AUTHORITY[\"EPSG\",\"4326\"]]");

            var transform = ctFactory.CreateFromCoordinateSystems(osgb36, wgs84);

            var lowerLeftOSGB = new Coordinate(bx, by);

            var lowerLeftWGS = transform.MathTransform.Transform(lowerLeftOSGB);

            // Create a sketchup file with the building outline in (Not yet georefed)

            SketchUpNET.SketchUp skp = new SketchUpNET.SketchUp();

            skp.Latitude  = lowerLeftWGS.Y;
            skp.Longitude = lowerLeftWGS.X;

            //skp.LoadModel("NewSquare2.skp");

            // Nothing is initialised by default, and we need to init it all even stuff we don't use
            skp.Components = new System.Collections.Generic.Dictionary <string, SketchUpNET.Component>();
            skp.Curves     = new System.Collections.Generic.List <SketchUpNET.Curve>();
            skp.Groups     = new System.Collections.Generic.List <SketchUpNET.Group>();
            skp.Instances  = new System.Collections.Generic.List <SketchUpNET.Instance>();
            skp.Materials  = new System.Collections.Generic.Dictionary <string, SketchUpNET.Material>();

            skp.Layers = new System.Collections.Generic.List <SketchUpNET.Layer>();
            skp.Layers.Add(new SketchUpNET.Layer("Layer0"));

            skp.Edges = new System.Collections.Generic.List <SketchUpNET.Edge>();

            for (int current = 0; current < (coordsForSketchup.Count - 1); current++)
            {
                skp.Edges.Add(new SketchUpNET.Edge(
                                  new SketchUpNET.Vertex(coordsForSketchup[current].X, coordsForSketchup[current].Y, 0),
                                  new SketchUpNET.Vertex(coordsForSketchup[current + 1].X, coordsForSketchup[current + 1].Y, 0),
                                  skp.Layers[0].Name
                                  ));
            }

            var surface = new SketchUpNET.Surface();

            surface.Layer  = skp.Layers[0].Name;
            surface.Normal = new SketchUpNET.Vector(0, 0, -1);

            surface.OuterEdges       = new SketchUpNET.Loop();
            surface.OuterEdges.Edges = new System.Collections.Generic.List <SketchUpNET.Edge>();

            foreach (var edge in skp.Edges)
            {
                surface.OuterEdges.Edges.Add(edge);
            }

            surface.Vertices = new System.Collections.Generic.List <SketchUpNET.Vertex>();

            for (int current = 0; current < (coordsForSketchup.Count - 1); current++)
            {
                surface.Vertices.Add(new SketchUpNET.Vertex(coordsForSketchup[current].X, coordsForSketchup[current].Y, 0));
            }

            skp.Surfaces = new System.Collections.Generic.List <SketchUpNET.Surface>();
            skp.Surfaces.Add(surface);

            skp.WriteNewModel("Temp.skp");
            skp.SaveAs("Temp.skp", SketchUpNET.SKPVersion.V2017, $"{Path.Combine(path, name)}.skp");

            File.Delete("Temp.skp");
        }