@@ -106,6 +106,54 @@ protected override Bitmap Internal_Icon_24x24
106106 }
107107 }
108108
109+ /// <summary>
110+ /// Save SketchUp Model Component
111+ /// </summary>
112+ public class SaveSketchUpModel : GH_Component
113+ {
114+ public SaveSketchUpModel ( ) : base ( "Save SketchUp Model" , "Save SketchUp Model" , "Save a SketchUp Model to file" , "GrassUp" , "Model" ) { }
115+
116+ protected override void RegisterInputParams ( GH_Component . GH_InputParamManager pManager )
117+ {
118+ pManager . AddTextParameter ( "Path" , "P" , "Path to Sketchup File (skp)" , GH_ParamAccess . item ) ;
119+ pManager . AddCurveParameter ( "Curves" , "C" , "Curves" , GH_ParamAccess . list ) ;
120+ pManager . AddSurfaceParameter ( "Surfaces" , "S" , "Surfaces" , GH_ParamAccess . list ) ;
121+ }
122+
123+ protected override void RegisterOutputParams ( GH_Component . GH_OutputParamManager pManager )
124+ {
125+
126+ }
127+
128+ protected override void SolveInstance ( IGH_DataAccess DA )
129+ {
130+ GH_String path = new GH_String ( ) ;
131+ DA . GetData < GH_String > ( 0 , ref path ) ;
132+
133+ List < GH_Surface > surfaces = new List < GH_Surface > ( ) ;
134+ DA . GetDataList < GH_Surface > ( 1 , surfaces ) ;
135+ List < GH_Curve > curves = new List < GH_Curve > ( ) ;
136+ DA . GetDataList < GH_Curve > ( 2 , curves ) ;
137+
138+ Geometry . WriteModel ( path . Value , surfaces , curves , false ) ;
139+ }
140+
141+ public override Guid ComponentGuid
142+ {
143+ get
144+ {
145+ return new Guid ( "{5ea8ce3d-d262-4d7f-a733-1573beeb4b5d}" ) ;
146+ }
147+ }
148+ protected override Bitmap Internal_Icon_24x24
149+ {
150+ get
151+ {
152+ return Properties . Resources . Skp ;
153+ }
154+ }
155+ }
156+
109157 /// <summary>
110158 /// Decomposes a SketchUp Model Instance
111159 /// </summary>
@@ -269,12 +317,12 @@ public static SketchUpNET.Curve ToSkpGeo(this Rhino.Geometry.Curve v)
269317 /// <summary>
270318 /// Converts a Rhino Surface to a SketchUp Surface
271319 /// </summary>
272- public static SketchUpNET . Surface ToSkpGeo ( this Rhino . Geometry . Surface surface )
320+ public static SketchUpNET . Surface ToSkpGeo ( this Rhino . Geometry . Brep surface )
273321 {
274322 Surface srf = new Surface ( ) ;
275323 srf . Vertices = new List < Vertex > ( ) ;
276324
277- foreach ( var curve in surface . ToBrep ( ) . Edges )
325+ foreach ( var curve in surface . Edges )
278326 {
279327 if ( curve . IsLinear ( ) )
280328 {
@@ -336,5 +384,38 @@ public static Rhino.Geometry.Brep[] ToRhinoGeo(this SketchUpNET.Surface v, Trans
336384 }
337385 return breps ;
338386 }
387+
388+ public static void WriteModel ( string path , List < GH_Surface > surfaces = null , List < GH_Curve > curves = null , bool append = false )
389+ {
390+ SketchUpNET . SketchUp skp = new SketchUpNET . SketchUp ( ) ;
391+ skp . Surfaces = new List < Surface > ( ) ;
392+ skp . Edges = new List < Edge > ( ) ;
393+ skp . Curves = new List < Curve > ( ) ;
394+
395+ if ( curves != null )
396+ foreach ( var c in curves )
397+ {
398+ var curve = c . Value ;
399+ if ( curve . IsLinear ( ) )
400+ {
401+ var line = new SketchUpNET . Edge ( curve . PointAt ( 0 ) . ToSkpGeo ( ) , curve . PointAt ( 1.0 ) . ToSkpGeo ( ) , DefaultLayer ) ;
402+ skp . Edges . Add ( line ) ;
403+ }
404+ else
405+ {
406+ skp . Curves . Add ( curve . ToSkpGeo ( ) ) ;
407+ }
408+ }
409+
410+ if ( surfaces != null )
411+ foreach ( var surface in surfaces )
412+ skp . Surfaces . Add ( surface . Value . ToSkpGeo ( ) ) ;
413+
414+ if ( System . IO . File . Exists ( path ) && append )
415+ skp . AppendToModel ( path ) ;
416+ else
417+ skp . WriteNewModel ( path ) ;
418+ }
419+
339420 }
340421}
0 commit comments