Skip to content

Commit

Permalink
Adding write headless doc and 3dm exmaple
Browse files Browse the repository at this point in the history
  • Loading branch information
fraguada committed Oct 10, 2024
1 parent f52be25 commit 6ced73b
Show file tree
Hide file tree
Showing 7 changed files with 179 additions and 0 deletions.
Binary file not shown.
23 changes: 23 additions & 0 deletions rhinocommon/cs/SampleCSWrite3dm/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using Rhino.PlugIns;

// Plug-in Description Attributes - all of these are optional.
// These will show in Rhino's option dialog, in the tab Plug-ins.
[assembly: PlugInDescription(DescriptionType.Address, "")]
[assembly: PlugInDescription(DescriptionType.Country, "")]
[assembly: PlugInDescription(DescriptionType.Email, "")]
[assembly: PlugInDescription(DescriptionType.Phone, "")]
[assembly: PlugInDescription(DescriptionType.Fax, "")]
[assembly: PlugInDescription(DescriptionType.Organization, "")]
[assembly: PlugInDescription(DescriptionType.UpdateUrl, "")]
[assembly: PlugInDescription(DescriptionType.WebSite, "")]

// Icons should be Windows .ico files and contain 32-bit images in the following sizes: 16, 24, 32, 48, and 256.
[assembly: PlugInDescription(DescriptionType.Icon, "Test3dmWrite.EmbeddedResources.plugin-utility.ico")]

// The following GUID is for the ID of the typelib if this project is exposed to COM
// This will also be the Guid of the Rhino plug-in
[assembly: Guid("97837e28-a09b-4c49-a11a-0b4da178714c")]

Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"profiles": {
"Test3dmWrite": {
"commandName": "Executable",
"executablePath": "C:\\Program Files\\Rhino 7\\System\\Rhino.exe",
"commandLineArgs": "$(TargetPath)"
}
}
}
19 changes: 19 additions & 0 deletions rhinocommon/cs/SampleCSWrite3dm/Test3dmWrite.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net48</TargetFramework>
<Version>1.0</Version>
<Title>Test3dmWrite</Title>
<Description>Description of Test3dmWrite</Description>
<TargetExt>.rhp</TargetExt>
</PropertyGroup>

<ItemGroup>
<EmbeddedResource Include="EmbeddedResources\**\*" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="RhinoCommon" Version="7.13.21348.13001" IncludeAssets="compile;build" />
</ItemGroup>

</Project>
25 changes: 25 additions & 0 deletions rhinocommon/cs/SampleCSWrite3dm/Test3dmWrite.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 25.0.1706.9
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Test3dmWrite", "Test3dmWrite.csproj", "{3B736240-9A74-4D59-A445-DBB228CECF7B}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{3B736240-9A74-4D59-A445-DBB228CECF7B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{3B736240-9A74-4D59-A445-DBB228CECF7B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3B736240-9A74-4D59-A445-DBB228CECF7B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3B736240-9A74-4D59-A445-DBB228CECF7B}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {60E93344-4D60-49D0-A049-B1ABAEBE336E}
EndGlobalSection
EndGlobal
75 changes: 75 additions & 0 deletions rhinocommon/cs/SampleCSWrite3dm/Test3dmWriteCommand.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
using System;
using System.Collections.Generic;
using System.IO;
using Rhino;
using Rhino.Commands;
using Rhino.Geometry;
using Rhino.Input;
using Rhino.Input.Custom;

namespace Test3dmWrite
{
public class Test3dmWriteCommand : Command
{
public Test3dmWriteCommand()
{
// Rhino only creates one instance of each command class defined in a
// plug-in, so it is safe to store a refence in a static property.
Instance = this;
}

///<summary>The only instance of this command.</summary>
public static Test3dmWriteCommand Instance { get; private set; }

///<returns>The command name as it appears on the Rhino command line.</returns>
public override string EnglishName => "Test3dmWriteCommand";

protected override Result RunCommand(RhinoDoc doc, RunMode mode)
{
var docH = RhinoDoc.CreateHeadless(null);
var file3dm = new Rhino.FileIO.File3dm();
var mesh = new Rhino.Geometry.Mesh();

mesh.Vertices.Add(0.0, 0.0, 10.0); //0
mesh.Vertices.Add(1.0, 0.0, 1.0); //1
mesh.Vertices.Add(2.0, 0.0, 1.0); //2
mesh.Vertices.Add(3.0, 0.0, 0.0); //3
mesh.Vertices.Add(0.0, 1.0, 1.0); //4
mesh.Vertices.Add(1.0, 1.0, 2.0); //5
mesh.Vertices.Add(2.0, 1.0, 1.0); //6
mesh.Vertices.Add(3.0, 1.0, 0.0); //7
mesh.Vertices.Add(0.0, 2.0, 1.0); //8
mesh.Vertices.Add(1.0, 2.0, 1.0); //9
mesh.Vertices.Add(2.0, 2.0, 1.0); //10
mesh.Vertices.Add(3.0, 2.0, 1.0); //11

mesh.Faces.AddFace(0, 1, 5, 4);
mesh.Faces.AddFace(1, 2, 6, 5);
mesh.Faces.AddFace(2, 3, 7, 6);
mesh.Faces.AddFace(4, 5, 9, 8);
mesh.Faces.AddFace(5, 6, 10, 9);
mesh.Faces.AddFace(6, 7, 11, 10);
mesh.Normals.ComputeNormals();
mesh.Compact();

Console.WriteLine($"PartitionCount: {mesh.PartitionCount}");

docH.Objects.AddMesh(mesh);
file3dm.Objects.AddMesh(mesh);

var path = Path.GetTempPath();
var pDoc = Path.Combine(path, "doc77.3dm");
var p3dm = Path.Combine(path, "file77.3dm");

Console.WriteLine(pDoc);
Console.WriteLine(p3dm);

docH.Write3dmFile(pDoc, new Rhino.FileIO.FileWriteOptions());
file3dm.Write(p3dm, 8);

// ---
return Result.Success;
}
}
}

28 changes: 28 additions & 0 deletions rhinocommon/cs/SampleCSWrite3dm/Test3dmWritePlugin.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using System;
using Rhino;

namespace Test3dmWrite
{
///<summary>
/// <para>Every RhinoCommon .rhp assembly must have one and only one PlugIn-derived
/// class. DO NOT create instances of this class yourself. It is the
/// responsibility of Rhino to create an instance of this class.</para>
/// <para>To complete plug-in information, please also see all PlugInDescription
/// attributes in AssemblyInfo.cs (you might need to click "Project" ->
/// "Show All Files" to see it in the "Solution Explorer" window).</para>
///</summary>
public class Test3dmWritePlugin : Rhino.PlugIns.PlugIn
{
public Test3dmWritePlugin()
{
Instance = this;
}

///<summary>Gets the only instance of the Test3dmWritePlugin plug-in.</summary>
public static Test3dmWritePlugin Instance { get; private set; }

// You can override methods here to change the plug-in behavior on
// loading and shut down, add options pages to the Rhino _Option command
// and maintain plug-in wide options in a document.
}
}

0 comments on commit 6ced73b

Please sign in to comment.