Developer: FlamingoScript
Summary: Demonstrates how to assign a Flamingo nXt material to an object.
I am trying to figure out how to assign a Flamingo nXt material to an object. What can I do?
The following are examples of how to assign a Flamingo nXt material to an object.
RhinoScript
Option Explicit Call Main() Sub Main() Dim objPlugIn, strObject, strMaterial On Error Resume Next Set objPlugIn = Rhino.GetPluginObject("8008880f-8d13-4b2d-92b0-727e12878a4c") If Err Then MsgBox Err.Description Exit Sub End If strMaterial = objPlugIn.ModalMaterialBrowser() If Not IsNull(strMaterial) And Not strMaterial = "" Then strObject = Rhino.GetObject("Select object") If Not IsNull(strObject) And Not strObject = "" Then If objPlugIn.SetMaterialId(strObject, strMaterial) Then Rhino.Print("Object assigned to material " + objPlugIn.GetMaterialName(strMaterial)) Else Rhino.Print("Error assigning material to object") End If End If End If Set objPlugIn = Nothing End Sub
Python
import clr # Load the Flamingo nXt SDK DLL clr.AddReference("FlamingoNXtSDK") import FlamingoNXtSDK import rhinoscriptsyntax as rs import scriptcontext # Get the Flamingo nXt plug-in's SDK implimentaion, this will force the # plug-in to load if it is not currently loaded flSDK = FlamingoNXtSDK.SDK.FlamingoSDK def AssignMaterialToObject(): # Display the modal material browser and prompt the user for a material rc, matName, matGuid = flSDK.ModalMaterialBrowser(None) if not rc: return # Prompt user to select oject to assign material to objID = rs.GetObject() if not objID: return # Attempt to assign material to picked object if flSDK.SetMaterialId(objID, matGuid): print "Material \"", matName, "\" assigned to selected object" scriptcontext.doc.Views.Redraw() else: print "Unable to assign \"", matName, "\" to selected object" if __name__=="__main__": AssignMaterialToObject()
C#
using System; using Rhino; using Rhino.DocObjects; using Rhino.Input; using Rhino.Commands; using FlamingoNXtSDK; partial class Examples { public static Result AssignMaterialToObject(RhinoDoc doc, Rhino.Commands.RunMode mode) { SDK sdk = SDK.FlamingoSDK; if (null == sdk) return Rhino.Commands.Result.Failure; string matName = string.Empty; Guid matGuid = Guid.Empty; if (!sdk.ModalMaterialBrowser(Rhino.RhinoApp.MainWindow(), out matName, out matGuid)) return Rhino.Commands.Result.Cancel; ObjRef objRef = null; Result result = RhinoGet.GetOneObject("Select object to assign material to", false, ObjectType.None, out objRef); if (result == Result.Success && null != objRef) { if (sdk.SetMaterialId(objRef.ObjectId, matGuid)) RhinoApp.WriteLine("Material \"" + matName + "\" assigned to selected object"); else result = Result.Failure; } return result; } }