diff --git a/cpp/SampleUserInterface/SampleModelessDialog.cpp b/cpp/SampleUserInterface/SampleModelessDialog.cpp index c615879f..585bae33 100644 --- a/cpp/SampleUserInterface/SampleModelessDialog.cpp +++ b/cpp/SampleUserInterface/SampleModelessDialog.cpp @@ -82,7 +82,7 @@ void CSampleModelessDialog::OnOK() void CSampleModelessDialog::OnCancel() { SampleUserInterfacePlugIn().ZeroDlg(); - CRhinoDialog::OnCancel(); + DestroyWindow(); } void CSampleModelessDialog::PostNcDestroy() diff --git a/rhinocommon/cs/SampleCsCommands/SampleCsCommands.csproj b/rhinocommon/cs/SampleCsCommands/SampleCsCommands.csproj index 6126b37e..232dc8a8 100644 --- a/rhinocommon/cs/SampleCsCommands/SampleCsCommands.csproj +++ b/rhinocommon/cs/SampleCsCommands/SampleCsCommands.csproj @@ -211,6 +211,7 @@ + diff --git a/rhinocommon/cs/SampleCsCommands/SampleCsPerFaceMaterial.cs b/rhinocommon/cs/SampleCsCommands/SampleCsPerFaceMaterial.cs new file mode 100644 index 00000000..a8d2b4c5 --- /dev/null +++ b/rhinocommon/cs/SampleCsCommands/SampleCsPerFaceMaterial.cs @@ -0,0 +1,67 @@ +using System; +using System.Security.Cryptography; +using Rhino; +using Rhino.Commands; +using Rhino.DocObjects; +using Rhino.Input.Custom; + +namespace SampleCsCommands +{ + public class SampleCsPerFaceMaterial : Command + { + public override string EnglishName => "SampleCsPerFaceMaterial"; + + protected override Result RunCommand(RhinoDoc doc, RunMode mode) + { + var render_plugin_id = Rhino.Render.Utilities.DefaultRenderPlugInId; + var idi = new GuidIndex(); + + var go = new GetObject(); + go.SetCommandPrompt("Select object with the rendering material you want to assign"); + go.EnablePreSelect(false, true); + go.EnablePostSelect(true); + go.Get(); + if (go.CommandResult() != Result.Success) + return go.CommandResult(); + + var obj = go.Object(0).Object(); + if (null == obj) + return Result.Failure; + + var att = obj.Attributes; + if ((idi.Index = att.MaterialIndex) >= 0) + { + idi.Id = doc.Materials[idi.Index].Id; + } + else + { + MaterialRef mat_ref = null; + if (att.MaterialRefs.ContainsKey(idi.Id)) + mat_ref = att.MaterialRefs[render_plugin_id]; + if (null == mat_ref) + mat_ref = att.MaterialRefs[Guid.Empty]; + if (null != mat_ref) + { + idi.Id = mat_ref.FrontFaceMaterialId; + idi.Index = doc.Materials.Find(idi.Id, true); + } + } + + if (!idi.IsValid) + { + RhinoApp.WriteLine("This object does not have a rendering material."); + return Result.Nothing; + } + + return Result.Success; + } + } + + internal class GuidIndex + { + public Guid Id { get; set; } = Guid.Empty; + public int Index { get; set; } = RhinoMath.UnsetIntIndex; + + public bool IsValid => Id != Guid.Empty && Index >= 0; + } +} \ No newline at end of file diff --git a/rhinocommon/cs/SampleCsCommands/SampleCsSetObjectName.cs b/rhinocommon/cs/SampleCsCommands/SampleCsSetObjectName.cs new file mode 100644 index 00000000..a3ba9e56 --- /dev/null +++ b/rhinocommon/cs/SampleCsCommands/SampleCsSetObjectName.cs @@ -0,0 +1,67 @@ +using Rhino; +using Rhino.Commands; +using Rhino.Input.Custom; + +namespace SampleCsCommands +{ + public class SampleCsSetObjectName : Command + { + public override string EnglishName => "SampleCsSetObjectName"; + + protected override Result RunCommand(RhinoDoc doc, RunMode mode) + { + var go = new GetObject(); + go.SetCommandPrompt("Select objects"); + go.SubObjectSelect = false; + go.ReferenceObjectSelect = false; + go.GetMultiple(1, 0); + if (go.CommandResult() != Result.Success) + return go.CommandResult(); + + string defaultName = null; + foreach (var objRef in go.Objects()) + { + var rhObj = objRef.Object(); + if (null == rhObj) + return Result.Failure; + + if (string.IsNullOrEmpty(defaultName)) + defaultName = rhObj.Attributes.Name; + else if (!defaultName.Equals(rhObj.Attributes.Name)) + { + defaultName = "varies"; + break; + } + } + + var gs = new GetString(); + gs.SetCommandPrompt("Object name"); + gs.SetDefaultString(defaultName); + gs.Get(); + if (gs.CommandResult() != Result.Success) + return gs.CommandResult(); + + var newName = gs.StringResult(); + newName = newName.Trim(); + + if (defaultName.Equals(newName)) + return Result.Nothing; + + foreach (var objRef in go.Objects()) + { + var rhObj = objRef.Object(); + if (null == rhObj) + return Result.Failure; + + if (!newName.Equals(rhObj.Attributes.Name)) + { + var attributes = rhObj.Attributes.Duplicate(); + attributes.Name = newName; + doc.Objects.ModifyAttributes(rhObj, attributes, false); + } + } + + return Result.Success; + } + } +} \ No newline at end of file diff --git a/rhinocommon/cs/SampleCsMouseCallback/Resources/plugin-utility.ico b/rhinocommon/cs/SampleCsMouseCallback/Resources/plugin-utility.ico new file mode 100644 index 00000000..022d1f78 Binary files /dev/null and b/rhinocommon/cs/SampleCsMouseCallback/Resources/plugin-utility.ico differ diff --git a/rhinocommon/cs/SampleCsSkin/Resources/SampleCsSkin.ico b/rhinocommon/cs/SampleCsSkin/Resources/SampleCsSkin.ico new file mode 100644 index 00000000..fdcae332 Binary files /dev/null and b/rhinocommon/cs/SampleCsSkin/Resources/SampleCsSkin.ico differ diff --git a/rhinocommon/cs/SampleCsSkin/Resources/SplashScreen.jpg b/rhinocommon/cs/SampleCsSkin/Resources/SplashScreen.jpg new file mode 100644 index 00000000..dfd012cd Binary files /dev/null and b/rhinocommon/cs/SampleCsSkin/Resources/SplashScreen.jpg differ