Site Tools


Get Plant Points

Developer: FlamingoScript
Summary: Demonstrates how get a list of points that represent a Flamingo nXt plant.

Question

I am trying to figure out how to get a list of points Flamingo nXt uses to represent a new Flamingo nXt plant in a document. What can I do?

Answer

The following are examples of how to get a list of points from a plant file definition.

RhinoScript

Option Explicit
 
Call Main()
 
Sub Main()
	Dim objPlugIn, plant, points, count
	On Error Resume Next
	Set objPlugIn = Rhino.GetPluginObject("8008880f-8d13-4b2d-92b0-727e12878a4c")
	If Err Then
		MsgBox Err.Description
		Exit Sub
	End If
  plant = objPlugIn.GetPlantFileName("")
  If Not IsNull(plant) Then
    points = objPlugIn.GetPlantPointCloud(plant)
    If Not IsNull(points) Then
      count = UBound(points)
      If count > 0 Then
        Rhino.AddPointCloud points
      	Rhino.Redraw()
      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 GetSticky(name, default = ""):
    if scriptcontext.sticky.has_key(name): return scriptcontext.sticky[name]
    return default
 
def PlantPointCloud():
    plantFile = GetSticky("PlantFileName")
    result, plantFile = flSDK.GetPlantFileName(None, plantFile)
    if not result: return
    pointList = flSDK.GetPlantPointCloud(plantFile);
    if not pointList or pointList.Length < 1: return
    points = [(point.X, point.Y, point.Z) for point in pointList]
    rs.AddPointCloud(points)
 
if __name__=="__main__":
    PlantPointCloud()

C#

using System;
using System.Collections.Generic;
 
using Rhino;
using Rhino.Geometry;
using Rhino.DocObjects;
using Rhino.Input;
using Rhino.Commands;
 
using FlamingoNXtSDK;
 
partial class Examples
{
  static string m_GetPlantPoints;
  public static Result GetPlantPoints(RhinoDoc doc, Rhino.Commands.RunMode mode)
  {
    SDK sdk = SDK.FlamingoSDK;
    if (null == sdk)
      return Rhino.Commands.Result.Failure;
    if (!sdk.GetPlantFileName(null, ref m_GetPlantPoints))
      return Result.Cancel;
    FlamingoNXtSDK.Point3D[] points = sdk.GetPlantPointCloud(m_GetPlantPoints);
    if (null != points)
    {
      List<Rhino.Geometry.Point3d> point_list = new List<Point3d>();
      foreach (var pt in points)
        point_list.Add(new Point3d(pt.X, pt.Y, pt.Z));
      doc.Objects.AddPointCloud(point_list);
      doc.Views.Redraw();
    }
    return Result.Success;
  }
}
flamingo/flamingosdk/getplantpointcloud.txt · Last modified: 2012/04/19 by johnm