Exemple #1
1
        public static Dictionary<string, object> LoadModel(string path)
        {
            List<Autodesk.DesignScript.Geometry.Surface> surfaces = new List<Autodesk.DesignScript.Geometry.Surface>();
            List<string> layers = new List<string>();
            List<Instance> Instances = new List<Instance>();
            List<List<Autodesk.DesignScript.Geometry.Line>> curves = new List<List<Autodesk.DesignScript.Geometry.Line>>();
            List<Autodesk.DesignScript.Geometry.Line> edges = new List<Autodesk.DesignScript.Geometry.Line>();

            SketchUpNET.SketchUp skp = new SketchUpNET.SketchUp();
            if (skp.LoadModel(path))
            {

                foreach (Curve c in skp.Curves)
                    curves.Add(c.ToDSGeo());

                    foreach (Surface srf in skp.Surfaces)
                        surfaces.Add(srf.ToDSGeo());

                    foreach (Layer l in skp.Layers)
                        layers.Add(l.Name);

                    foreach (Instance i in skp.Instances)
                        Instances.Add(i);

                    foreach (Edge e in skp.Edges)
                        edges.Add(e.ToDSGeo());

            }

            return new Dictionary<string, object>
            {
                { "Surfaces", surfaces },
                { "Layers", layers },
                { "Instances", Instances },
                { "Curves", curves },
                { "Edges", edges },
            };
        }
Exemple #2
0
        /// <summary>
        /// Reformats an existing SketchUp Model to another Version
        /// </summary>
        /// <param name="filepath">Original Model</param>
        /// <param name="version">Target Version like 2015 or 2018</param>
        /// <param name="newfilepath">Target Model Path</param>
        /// <returns></returns>
        public static bool ReformatModel(string filepath, string version, string newfilepath)
        {
            SketchUpNET.SketchUp skp = new SketchUpNET.SketchUp();
            SKPVersion           v   = SKPVersion.V2021;

            switch (version)
            {
            case "2014": v = SKPVersion.V2014; break;

            case "2015": v = SKPVersion.V2015; break;

            case "2016": v = SKPVersion.V2016; break;

            case "2017": v = SKPVersion.V2017; break;

            case "2018": v = SKPVersion.V2018; break;

            case "2019": v = SKPVersion.V2019; break;

            case "2020": v = SKPVersion.V2020; break;

            case "2021": v = SKPVersion.V2021; break;
            }
            return(skp.SaveAs(filepath, v, newfilepath));
        }
Exemple #3
0
        public static Dictionary <string, object> LoadModel(string path, bool includeMeshes = true)
        {
            List <Autodesk.DesignScript.Geometry.Surface> surfaces = new List <Autodesk.DesignScript.Geometry.Surface>();
            List <Autodesk.DesignScript.Geometry.Mesh>    meshes   = new List <Autodesk.DesignScript.Geometry.Mesh>();
            List <string>   layers    = new List <string>();
            List <Instance> Instances = new List <Instance>();
            List <List <Autodesk.DesignScript.Geometry.Line> > curves = new List <List <Autodesk.DesignScript.Geometry.Line> >();
            List <Autodesk.DesignScript.Geometry.Line>         edges  = new List <Autodesk.DesignScript.Geometry.Line>();
            List <Group> grp = new List <Group>();

            SketchUpNET.SketchUp skp = new SketchUpNET.SketchUp();
            if (skp.LoadModel(path, includeMeshes))
            {
                foreach (Curve c in skp.Curves)
                {
                    curves.Add(c.ToDSGeo());
                }

                foreach (Surface srf in skp.Surfaces)
                {
                    surfaces.Add(srf.ToDSGeo());
                    if (srf.FaceMesh != null)
                    {
                        meshes.Add(srf.FaceMesh.ToDSGeo());
                    }
                }

                foreach (Layer l in skp.Layers)
                {
                    layers.Add(l.Name);
                }

                foreach (Instance i in skp.Instances)
                {
                    Instances.Add(i);
                }

                foreach (Edge e in skp.Edges)
                {
                    edges.Add(e.ToDSGeo());
                }

                foreach (Group gr in skp.Groups)
                {
                    grp.Add(gr);
                }
            }

            return(new Dictionary <string, object>
            {
                { "Surfaces", surfaces },
                { "Layers", layers },
                { "Instances", Instances },
                { "Curves", curves },
                { "Edges", edges },
                { "Meshes", meshes },
                { "Groups", grp }
            });
        }
Exemple #4
0
        public static Dictionary <string, object> LoadModelByLayer(string path, string layername, bool includeMeshes = true)
        {
            List <Autodesk.DesignScript.Geometry.Surface> surfaces = new List <Autodesk.DesignScript.Geometry.Surface>();
            List <Autodesk.DesignScript.Geometry.Mesh>    meshes   = new List <Autodesk.DesignScript.Geometry.Mesh>();
            List <Instance> Instances = new List <Instance>();
            List <Autodesk.DesignScript.Geometry.Line> edges = new List <Autodesk.DesignScript.Geometry.Line>();
            List <Group>    grp  = new List <Group>();
            List <Material> mats = new List <Material>();

            SketchUpNET.SketchUp skp = new SketchUpNET.SketchUp();
            if (skp.LoadModel(path, includeMeshes))
            {
                foreach (Surface srf in skp.Surfaces.Where(s => s.Layer == layername))
                {
                    surfaces.Add(srf.ToDSGeo());
                    if (srf.FaceMesh != null)
                    {
                        meshes.Add(srf.FaceMesh.ToDSGeo());
                    }
                }

                foreach (Instance i in skp.Instances.Where(s => s.Layer == layername))
                {
                    Instances.Add(i);
                }

                foreach (Edge e in skp.Edges.Where(s => s.Layer == layername))
                {
                    edges.Add(e.ToDSGeo());
                }

                foreach (Group gr in skp.Groups.Where(s => s.Layer == layername))
                {
                    grp.Add(gr);
                }

                foreach (var mat in skp.Materials)
                {
                    mats.Add(new Material(mat.Value));
                }
            }

            return(new Dictionary <string, object>
            {
                { "Surfaces", surfaces },
                { "Instances", Instances },
                { "Edges", edges },
                { "Meshes", meshes },
                { "Groups", grp },
                { "Materials", mats }
            });
        }
Exemple #5
0
        /// <summary>
        /// Write SketchUp Model.
        /// This node writes surfaces and cures into a SketchUp model.
        /// </summary>
        /// <param name="path">Path to SketchUp file</param>
        /// <param name="surfaces">Surface Geometries</param>
        /// <param name="curves">Curve Geometries</param>
        public static void WriteModel(string path, List <Autodesk.DesignScript.Geometry.Surface> surfaces = null, List <Autodesk.DesignScript.Geometry.Curve> curves = null)
        {
            SketchUpNET.SketchUp skp = new SketchUpNET.SketchUp();
            skp.Surfaces = new List <Surface>();
            skp.Edges    = new List <Edge>();
            skp.Curves   = new List <Curve>();

            if (curves != null)
            {
                foreach (Autodesk.DesignScript.Geometry.Curve curve in curves)
                {
                    if (curve.GetType() == typeof(Autodesk.DesignScript.Geometry.Line))
                    {
                        Autodesk.DesignScript.Geometry.Line line = (Autodesk.DesignScript.Geometry.Line)curve;
                        skp.Edges.Add(line.ToSKPGeo());
                    }
                    else
                    {
                        Curve skpcurve = new Curve();
                        skpcurve.Edges = new List <Edge>();
                        foreach (Autodesk.DesignScript.Geometry.Curve tesselated in curve.ApproximateWithArcAndLineSegments())
                        {
                            Edge e = new Edge(tesselated.StartPoint.ToSKPGeo(), tesselated.EndPoint.ToSKPGeo(), "");
                            skpcurve.Edges.Add(e);
                        }
                        skp.Curves.Add(skpcurve);
                    }
                }
            }

            if (surfaces != null)
            {
                foreach (Autodesk.DesignScript.Geometry.Surface surface in surfaces)
                {
                    skp.Surfaces.Add(surface.ToSKPGeo());
                }
            }

            if (System.IO.File.Exists(path))
            {
                skp.AppendToModel(path);
            }
            else
            {
                skp.WriteNewModel(path);
            }
        }
Exemple #6
0
        public static void WriteModel(string path, List <GH_Surface> surfaces = null, List <GH_Curve> curves = null, bool append = false)
        {
            SketchUpNET.SketchUp skp = new SketchUpNET.SketchUp();
            skp.Surfaces = new List <Surface>();
            skp.Edges    = new List <Edge>();
            skp.Curves   = new List <Curve>();

            if (curves != null)
            {
                foreach (var c in curves)
                {
                    var curve = c.Value;
                    if (curve.IsLinear())
                    {
                        var line = new SketchUpNET.Edge(curve.PointAt(0).ToSkpGeo(), curve.PointAt(1.0).ToSkpGeo(), DefaultLayer);
                        skp.Edges.Add(line);
                    }
                    else
                    {
                        skp.Curves.Add(curve.ToSkpGeo());
                    }
                }
            }

            if (surfaces != null)
            {
                foreach (var surface in surfaces)
                {
                    skp.Surfaces.Add(surface.Value.ToSkpGeo());
                }
            }

            if (System.IO.File.Exists(path) && append)
            {
                skp.AppendToModel(path);
            }
            else
            {
                skp.WriteNewModel(path);
            }
        }
Exemple #7
0
        /// <summary>
        /// Write SketchUp Model
        /// </summary>
        /// <param name="path">Path to SketchUp file</param>
        public static void WriteModel(string path, List<Autodesk.DesignScript.Geometry.Surface> surfaces = null, List<Autodesk.DesignScript.Geometry.Curve> curves = null)
        {
            SketchUpNET.SketchUp skp = new SketchUpNET.SketchUp();
            skp.Surfaces = new List<Surface>();
            skp.Edges = new List<Edge>();
            skp.Curves = new List<Curve>();

            if (curves != null)
            foreach (Autodesk.DesignScript.Geometry.Curve curve in curves)
            {
                if (curve.GetType() == typeof(Autodesk.DesignScript.Geometry.Line))
                {
                    Autodesk.DesignScript.Geometry.Line line = (Autodesk.DesignScript.Geometry.Line)curve;
                    skp.Edges.Add(line.ToSKPGeo());
                }
                else
                {
                    Curve skpcurve = new Curve();
                    skpcurve.Edges = new List<Edge>();
                    foreach (Autodesk.DesignScript.Geometry.Curve tesselated in curve.ApproximateWithArcAndLineSegments())
                    {
                        Edge e = new Edge(tesselated.StartPoint.ToSKPGeo(), tesselated.EndPoint.ToSKPGeo());
                        skpcurve.Edges.Add(e);
                    }
                    skp.Curves.Add(skpcurve);
                }
            }

            if (surfaces != null)
            foreach (Autodesk.DesignScript.Geometry.Surface surface in surfaces)
                skp.Surfaces.Add(surface.ToSKPGeo());

            if (System.IO.File.Exists(path))
                skp.AppendToModel(path);
            else
                skp.WriteNewModel(path);
        }