Developer: FlamingoScript
Summary: Demonstrates how get an objects Flamingo nXt material assignment.
I am trying to figure out how to get the Flamingo nXt material assigned to an object. What can I do?
The following are examples of how to extract the Flamingo nXt material ID assigned to an object and use it to get the material name.
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 strObject = Rhino.GetObject("Select object") If Not IsNull(strObject) And Not strObject = "" Then strMaterial = objPlugIn.GetMaterialId(strObject) If Not IsNull(strMaterial) And Not strMaterial = "" Then Rhino.Print("Object assigned to Flamingo nXt material ID: " + strMaterial + " Name: " + objPlugIn.GetMaterialName(strMaterial)) Else Rhino.Print("Object does not have a Flamingo nXt material assigned") 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 # 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 MaterialFromOject(): objID = rs.GetObject("Select object") if not objID: return result, materialId = flSDK.GetMaterialId(objID) if result : print "Material assignment: \"", materialId else : print "No material assigned" if __name__=="__main__": MaterialFromOject()
C#
using System; using Rhino; using Rhino.DocObjects; using Rhino.Input; using Rhino.Commands; using FlamingoNXtSDK; partial class Examples { public static Result GetObjectMaterialAssignment(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", false, ObjectType.None, out objRef); if (result == Result.Success && null != objRef) { if (sdk.GetMaterialId(objRef.ObjectId, out matGuid)) RhinoApp.WriteLine("Object references material with Id of: \"" + matGuid + "\""); else RhinoApp.WriteLine("Object not assigned a Flamingo material"); } return Result.Success; } }