partialclassExamples{publicstaticRhino.Commands.ResultAddLayer(Rhino.RhinoDoc doc){// Cook up an unused layer namestring unused_name = doc.Layers.GetUnusedLayerName(false);// Prompt the user to enter a layer nameRhino.Input.Custom.GetString gs =newRhino.Input.Custom.GetString();
gs.SetCommandPrompt("Name of layer to add");
gs.SetDefaultString(unused_name);
gs.AcceptNothing(true);
gs.Get();if(gs.CommandResult()!=Rhino.Commands.Result.Success)return gs.CommandResult();// Was a layer named entered?string layer_name = gs.StringResult().Trim();if(string.IsNullOrEmpty(layer_name)){Rhino.RhinoApp.WriteLine("Layer name cannot be blank.");returnRhino.Commands.Result.Cancel;}// Is the layer name valid?if(!Rhino.DocObjects.Layer.IsValidName(layer_name)){Rhino.RhinoApp.WriteLine(layer_name +" is not a valid layer name.");returnRhino.Commands.Result.Cancel;}// Does a layer with the same name already exist?int layer_index = doc.Layers.Find(layer_name,true);if(layer_index >=0){Rhino.RhinoApp.WriteLine("A layer with the name {0} already exists.", layer_name);returnRhino.Commands.Result.Cancel;}// Add a new layer to the document
layer_index = doc.Layers.Add(layer_name,System.Drawing.Color.Black);if(layer_index <0){Rhino.RhinoApp.WriteLine("Unable to add {0} layer.", layer_name);returnRhino.Commands.Result.Failure;}returnRhino.Commands.Result.Success;}}
importRhinoimport scriptcontext
importSystem.Guid,System.Drawing.ColordefAddLayer():# Cook up an unused layer name
unused_name = scriptcontext.doc.Layers.GetUnusedLayerName(False)# Prompt the user to enter a layer name
gs =Rhino.Input.Custom.GetString()
gs.SetCommandPrompt("Name of layer to add")
gs.SetDefaultString(unused_name)
gs.AcceptNothing(True)
gs.Get()if gs.CommandResult()!=Rhino.Commands.Result.Success:return gs.CommandResult()# Was a layer named entered?
layer_name = gs.StringResult().Trim()ifnot layer_name:
print "Layer name cannot be blank."returnRhino.Commands.Result.Cancel# Is the layer name valid?ifnotRhino.DocObjects.Layer.IsValidName(layer_name):
print layer_name,"is not a valid layer name."returnRhino.Commands.Result.Cancel# Does a layer with the same name already exist?
layer_index = scriptcontext.doc.Layers.Find(layer_name,True)if layer_index>=0:
print "A layer with the name", layer_name,"already exists."returnRhino.Commands.Result.Cancel# Add a new layer to the document
layer_index = scriptcontext.doc.Layers.Add(layer_name,System.Drawing.Color.Black)if layer_index<0:
print "Unable to add", layer_name,"layer."returnRhino.Commands.Result.FailurereturnRhino.Commands.Result.Successif __name__=="__main__":AddLayer()
PartialClassExamplesPublicSharedFunctionAddLayer(ByVal doc AsRhino.RhinoDoc)AsRhino.Commands.Result' Cook up an unused layer nameDim unused_name AsString= doc.Layers.GetUnusedLayerName(False)' Prompt the user to enter a layer nameDim gs AsNewRhino.Input.Custom.GetString()
gs.SetCommandPrompt("Name of layer to add")
gs.SetDefaultString(unused_name)
gs.AcceptNothing(True)
gs.Get()If gs.CommandResult()<>Rhino.Commands.Result.SuccessThenReturn gs.CommandResult()EndIf' Was a layer named entered?Dim layer_name AsString= gs.StringResult().Trim()IfString.IsNullOrEmpty(layer_name)ThenRhino.RhinoApp.WriteLine("Layer name cannot be blank.")ReturnRhino.Commands.Result.CancelEndIf' Is the layer name valid?IfNotRhino.DocObjects.Layer.IsValidName(layer_name)ThenRhino.RhinoApp.WriteLine(layer_name &" is not a valid layer name.")ReturnRhino.Commands.Result.CancelEndIf' Does a layer with the same name already exist?Dim layer_index AsInteger= doc.Layers.Find(layer_name,True)If layer_index >=0ThenRhino.RhinoApp.WriteLine("A layer with the name {0} already exists.", layer_name)ReturnRhino.Commands.Result.CancelEndIf' Add a new layer to the document
layer_index = doc.Layers.Add(layer_name,System.Drawing.Color.Black)If layer_index <0ThenRhino.RhinoApp.WriteLine("Unable to add {0} layer.", layer_name)ReturnRhino.Commands.Result.FailureEndIfReturnRhino.Commands.Result.SuccessEndFunctionEndClass