Skip to content

Commit

Permalink
DestroyWindow
Browse files Browse the repository at this point in the history
  • Loading branch information
dalefugier committed Feb 16, 2024
1 parent 320cedd commit 8ec81c5
Show file tree
Hide file tree
Showing 7 changed files with 136 additions and 1 deletion.
2 changes: 1 addition & 1 deletion cpp/SampleUserInterface/SampleModelessDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ void CSampleModelessDialog::OnOK()
void CSampleModelessDialog::OnCancel()
{
SampleUserInterfacePlugIn().ZeroDlg();
CRhinoDialog::OnCancel();
DestroyWindow();
}

void CSampleModelessDialog::PostNcDestroy()
Expand Down
1 change: 1 addition & 0 deletions rhinocommon/cs/SampleCsCommands/SampleCsCommands.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@
<Compile Include="SampleCsSetCameraTarget.cs" />
<Compile Include="SampleCsSetDisplayMode.cs" />
<Compile Include="SampleCsSetDocumentUserText.cs" />
<Compile Include="SampleCsSetObjectName.cs" />
<Compile Include="SampleCsSetPoint.cs" />
<Compile Include="SampleCsShadedBrep.cs" />
<Compile Include="SampleCsShadedView.cs" />
Expand Down
67 changes: 67 additions & 0 deletions rhinocommon/cs/SampleCsCommands/SampleCsPerFaceMaterial.cs
Original file line number Diff line number Diff line change
@@ -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;
}
}
67 changes: 67 additions & 0 deletions rhinocommon/cs/SampleCsCommands/SampleCsSetObjectName.cs
Original file line number Diff line number Diff line change
@@ -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;
}
}
}
Binary file not shown.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 8ec81c5

Please sign in to comment.