Site Tools


Set Flamingo nXt Object Mapping Properties

Developer: FlamingoScript
Summary: Demonstrates how to set Flamingo nXt mapping properties for an object.

Question

I am trying to figure out how to set Flamingo nXt mapping properties for an object. What can I do?

Answer

The following are examples of how to set Flamingo nXt mapping properties for an object.

RhinoScript

Set Mapping Scale

Option Explicit
 
Call Main()
 
Sub Main()
	Dim objPlugIn, strObject, scale, xscale, yscale, zscale
	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
  	scale = objPlugIn.GetMappingScale(strObject)
    xscale = 1.0
    yscale = 1.0
    zscale = 1.0
    If Not IsNull(scale) Then
      xscale = CDbl(scale(0))
      yscale = CDbl(scale(1))
      zScale = CDbl(scale(2))
    End If
  	xscale = Rhino.GetReal("X-Scale", xscale)
	  If Not IsNull(xscale) Then
  	  yscale = Rhino.GetReal("Y-Scale", yscale)
	    If Not IsNull(xscale) Then
  	    zscale = Rhino.GetReal("Z-Scale", zscale)
	      If Not IsNull(xscale) Then
          If objPlugIn.SetMappingScale(strObject, xscale, yscale, zscale) Then
            Rhino.Print("Object mapping scale set to: x-scale:" & xscale & "  y-scale: " & yscale & "  z-scale: " & zscale)
          Else
            Rhino.Print("Error setting objects mapping scale")
          End If
        End If
      End If
    End If
	End If
	Set objPlugIn = Nothing
End Sub

Set Mapping Origin

Option Explicit
 
Call Main()
 
Sub Main()
	Dim objPlugIn, strObject, origin
	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
  	origin = Rhino.GetPoint("Mapping orgin")
	  If Not IsNull(origin) Then
      If objPlugIn.SetMappingOrigin(strObject, origin) Then
        Rhino.Print("Object mapping origin set to: " & origin)
      Else
        Rhino.Print("Error setting objects mapping origin")
      End If
    End If
	End If
	Set objPlugIn = Nothing
End Sub

Set Mapping Z-Axis

Option Explicit
 
Call Main()
 
Sub Main()
	Dim objPlugIn, strObject, origin, axis
	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
  	origin = objPlugIn.GetMappingOrigin(strObject)
    If IsNull(origin) Then
      origin = Array(0.0,0.0,0.0)
    End If
  	axis = Rhino.GetPoint("Mapping z-axis", origin)
	  If Not IsNull(axis) Then
			axis = Rhino.VectorUnitize(Rhino.VectorCreate(axis, origin))
      If objPlugIn.SetMappingZAxis(strObject, axis) Then
        Rhino.Print("Object mapping z-axis set to: " & Rhino.Pt2Str(axis))
      Else
        Rhino.Print("Error setting objects mapping origin")
      End If
    End If
	End If
	Set objPlugIn = Nothing
End Sub

Set Mapping X-Axis

Option Explicit
 
Call Main()
 
Sub Main()
	Dim objPlugIn, strObject, origin, axis
	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
  	origin = objPlugIn.GetMappingOrigin(strObject)
    If IsNull(origin) Then
      origin = Array(0.0,0.0,0.0)
    End If
  	axis = Rhino.GetPoint("Mapping x-axis", origin)
	  If Not IsNull(axis) Then
			axis = Rhino.VectorUnitize(Rhino.VectorCreate(axis, origin))
      If objPlugIn.SetMappingXAxis(strObject, axis) Then
        Rhino.Print("Object mapping x-axis set to: " & Rhino.Pt2Str(axis))
      Else
        Rhino.Print("Error setting objects mapping origin")
      End If
    End If
	End If
	Set objPlugIn = Nothing
End Sub

Set Mapping Type

Option Explicit
 
Call Main()
 
Sub Main()
	Dim objPlugIn, strObject, mappingType
	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
		mappingType = Rhino.GetInteger("New mapping type", 0, 0, 7)
	  If Not IsNull(mappingType) Then
      If objPlugIn.SetMappingType(strObject, mappingType) Then
        Rhino.Print("Object mapping type set to: " & mappingType)
      Else
        Rhino.Print("Error setting object mapping type")
		  End If
	  End If
	End If
	Set objPlugIn = Nothing
End Sub

Python

Mapping Origin

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 SetMappingOrigin():
    objID = rs.GetObject()
    if not objID: return
    point = rs.GetPoint("Mapping origin")
    if not point: return
    if flSDK.SetMappingOrigin(objID, FlamingoNXtSDK.Point3D(point.X, point.Y, point.Z)):
        print "Mapping origin set to: ", point
    else: print "Error setting mapping origin"
 
if __name__=="__main__":
    SetMappingOrigin()

 

Z-Axis

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 SetMappingZAxis():
    objID = rs.GetObject()
    if not objID: return
    result, basePoint = flSDK.GetMappingOrigin(objID)
    base_point = rs.coerce3dpoint((basePoint.X, basePoint.Y, basePoint.Z))
    point = rs.GetPoint("Mapping Z-Axis", base_point)
    if not point: return
    zaxis = rs.PointSubtract(point, base_point)
    zaxis = rs.VectorUnitize(zaxis)
    if flSDK.SetMappingZAxis(objID, zaxis.X, zaxis.Y, zaxis.Z):
        print "Mapping Z-Axis set to: ", zaxis
    else: print "Error setting mapping origin"
 
if __name__=="__main__":
    SetMappingZAxis()

X-Axis

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 SetMappingXAxis():
    objID = rs.GetObject()
    if not objID: return
    result, basePoint = flSDK.GetMappingOrigin(objID)
    base_point = rs.coerce3dpoint((basePoint.X, basePoint.Y, basePoint.Z))
    point = rs.GetPoint("Mapping X-Axis", base_point)
    if not point: return
    xaxis = rs.PointSubtract(point, base_point)
    xaxis = rs.VectorUnitize(xaxis)
    if flSDK.SetMappingXAxis(objID, xaxis.X, xaxis.Y, xaxis.Z):
        print "Mapping X-Axis set to: ", xaxis
    else: print "Error setting mapping origin"
 
 
if __name__=="__main__":
    SetMappingXAxis()

Mapping Type

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 SetMappingType():
    objID = rs.GetObject()
    if not objID: return
    print "Mapping types (0:", FlamingoNXtSDK.MaterialMappingType.Default, " 1:", FlamingoNXtSDK.MaterialMappingType.Box, " 2:", FlamingoNXtSDK.MaterialMappingType.Cylindrical, " 3:", FlamingoNXtSDK.MaterialMappingType.Spherical, " 4:", FlamingoNXtSDK.MaterialMappingType.Planar, " 5:", FlamingoNXtSDK.MaterialMappingType.UV, " 6:", FlamingoNXtSDK.MaterialMappingType.Equirectangular, ")"
    number = rs.GetInteger("Mapping type, value from 0 to 6")
    if not number: return
    mapping = FlamingoNXtSDK.MaterialMappingType.None
    if number == 0: mapping = FlamingoNXtSDK.MaterialMappingType.Default
    if number == 1: mapping = FlamingoNXtSDK.MaterialMappingType.Box
    if number == 2: mapping = FlamingoNXtSDK.MaterialMappingType.Cylindrical
    if number == 3: mapping = FlamingoNXtSDK.MaterialMappingType.Spherical
    if number == 4: mapping = FlamingoNXtSDK.MaterialMappingType.Planar
    if number == 5: mapping = FlamingoNXtSDK.MaterialMappingType.UV
    if number == 6: mapping = FlamingoNXtSDK.MaterialMappingType.Equirectangular
    if flSDK.SetMappingType(objID, mapping):
        print "Mapping set to ", mapping
    else:
        print "Error setting mapping"
 
if __name__=="__main__":
    SetMappingType()

C#

using System;
 
using Rhino;
using Rhino.DocObjects;
using Rhino.Input;
using Rhino.Commands;
 
using FlamingoNXtSDK;
 
partial class Examples
{
  public static Result SetMappingOrigin(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)
      return result;
    Rhino.Geometry.Point3d origin;
    result = RhinoGet.GetPoint("Mapping origin", false, out origin);
    if (result != Result.Success)
      return result;
    if (sdk.SetMappingOrigin(objRef.ObjectId, new FlamingoNXtSDK.Point3D(origin.X, origin.Y, origin.Z)))
      RhinoApp.WriteLine("Object mapping origin set to: " + origin);
    else
      RhinoApp.WriteLine("Error setting objects mapping origin");
    return Result.Success;
  }
}
flamingo/flamingosdk/setmapping.txt · Last modified: 2020/08/14 (external edit)