protected override Result RunCommand(RhinoDoc doc, RunMode mode) { int currIntOption = 0; var gi = new GetOption(); gi.SetCommandPrompt("Material Index"); gi.AcceptNumber(true, true); var resgi = gi.Get(); if (resgi == GetResult.Number) { currIntOption = Convert.ToInt32(gi.Number()); } Rhino.Input.Custom.GetObject go = new Rhino.Input.Custom.GetObject(); go.SetCommandPrompt("Select objects to apply material"); go.GroupSelect = true; go.SubObjectSelect = false; go.EnableClearObjectsOnEntry(false); go.EnableUnselectObjectsOnExit(false); go.DeselectAllBeforePostSelect = false; go.GetMultiple(1, 0); //Nothing to do - get out quick. if (go.ObjectCount == 0) { return(Result.Success); } var rm = FindMaterial(doc, matName[currIntOption]); if (null == rm) { //Didn't find the material - create one and carry on. //Create a basic material var custom = new Rhino.DocObjects.Material(); custom.Name = matName[currIntOption]; if (currIntOption == 13) { custom.SetEnvironmentTexture(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "/Free Jewels Rhino Plug-Ins/Dia3.jpg"); } custom.CommitChanges(); rm = RenderMaterial.CreateBasicMaterial(custom); rm.BeginChange(RenderContent.ChangeContexts.Program); rm.SetParameter("diffuse", System.Drawing.Color.Black); rm.SetParameter("reflectivity", 1.0); rm.SetParameter("reflectivity-color", System.Drawing.Color.FromArgb(r[currIntOption], g[currIntOption], b[currIntOption])); rm.SetParameter("transparency", fjMatTrans[currIntOption]); rm.SetParameter("shine", fjMatShine[currIntOption]); rm.SetParameter("polish-amount", fjMatShine[currIntOption]); rm.EndChange(); var docMats = doc.RenderMaterials; docMats.Add(rm); } //Now we always have a material to assign, this part is easy for (int i = 0; i < go.ObjectCount; i++) { var obj = go.Object(i).Object(); obj.RenderMaterial = rm; obj.CommitChanges(); } doc.Views.Redraw(); return(Result.Success); }