Site Tools


Query plant object

Developer: FlamingoScript
Summary: Demonstrates how query a plant object.

Question

I am trying to figure out if an object is a plant. What can I do?

Answer

The following are examples of how to extract the plant file and XML definition associated with an object.

RhinoScript

Option Explicit
 
Call Main()
 
Sub Main()
	Dim objPlugIn, strObject, plant
	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
		Set plant = objPlugIn.PlantFromObject(strObject)
    If IsNull(plant) Then
      Rhino.Print("Object is not a plant")
    Else
  		Rhino.Print("Plant assignment: " & plant.FileName & "  XML: " & plant.Xml)
    End If
    Set plant = Nothing
	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 PlantFromOject():
    objID = rs.GetObject("Select plant object")
    if not objID: return
    sdkPlant = flSDK.PlantFromObject(objID)
    if sdkPlant: print "Plant assignment: \"", sdkPlant.FileName, "\"\n\tXML: ", sdkPlant.Xml
 
if __name__=="__main__":
    PlantFromOject()

C#

using System;
 
using Rhino;
using Rhino.DocObjects;
using Rhino.Input;
using Rhino.Commands;
 
using FlamingoNXtSDK;
 
partial class Examples
{
  public static Result PlantFromOject(RhinoDoc doc, Rhino.Commands.RunMode mode)
  {
    SDK sdk = SDK.FlamingoSDK;
    if (null == sdk)
      return Rhino.Commands.Result.Failure;
    ObjRef objRef = null;
    Result result = RhinoGet.GetOneObject("Select object to tag as plant", false, ObjectType.None, out objRef);
    if (result == Result.Success && null != objRef)
    {
      Plant sdkPlant = sdk.PlantFromObject(objRef.ObjectId);
      if (null != sdkPlant)
        RhinoApp.WriteLine("Object tagged as plant: \"" + sdkPlant.FileName + "\"");
    }
    return result;
  }
}
flamingo/flamingosdk/plantfromobject.txt · Last modified: 2012/04/19 by johnm