Site Tools


Differences

This shows you the differences between two versions of the page.

Link to this comparison view

developer:dotnettorhinoscript [2015/09/14]
127.0.0.1 external edit
developer:dotnettorhinoscript [2016/02/09] (current)
sandy
Line 1: Line 1:
-====== Passing ​data from a .NET plug-in to RhinoScript ======+====== Passing ​Data from a .NET Plug-in to RhinoScript ======
 > **Version:​** //Rhino 4.0// > **Version:​** //Rhino 4.0//
  
-See Also: [[developer:​sdksamples:​extendrhinoscript|How to extend RhinoScript with a .NET plug-in]]+See also [[developer:​sdksamples:​extendrhinoscript|How to extend RhinoScript with a .NET plug-in.]]
  
-=====Question===== +=====Problem===== 
-I am trying to use the plug-in object'​s **GetPlugInObjectInterface** facility to return information from my .NET plug-in to be used in [[developer:​rhinoscript|RhinoScript]]. I can successfully define a class with the **ComVisible** attribute and return an object of that classes ​type to [[developer:​rhinoscript|RhinoScript]] to be used in a sample script. ​However, I can not seem to find a way to return a collection or array of objects of that type and use it in the script. Any help here would be appreciated.+I am trying to use the plug-in object'​s **GetPlugInObjectInterface** facility to return information from my .NET plug-in to be used in [[developer:​rhinoscript|RhinoScript]]. I can successfully define a class with the **ComVisible** attribute and return an object of that class type to RhinoScript used in a sample script. ​Yet, I can not find a way to return a collection or array of objects of that type and use it in the script. ​
  
-=====Answer===== +=====Solution===== 
-A quick review: Rhino 4.0 plug-ins can extend the [[developer:​rhinoscript|RhinoScript]] with new objects and methods. ​This is done by declaring .NET classes with the **ComVisible(true)** parameter, and by overriding the plug-in object'​s **GetPlugInObjectInterface** to return these classes when requested by [[developer:​rhinoscript|RhinoScript]].+A quick review: Rhino 4.0 plug-ins can extend the [[developer:​rhinoscript|RhinoScript]] with new objects and methods. ​Do this by declaring .NET classes with the **ComVisible(true)** parameter, and by overriding the plug-in object'​s **GetPlugInObjectInterface** to return these classes when requested by RhinoScript.
  
-The following sample code will demonstrate ​how to return different data types from .NET to RhinoScript,​ including objects and arrays of objects. The code samples are written in C#, but could very easily be written in VB.NET.+The following sample code demonstrates ​how to return different data types from .NET to RhinoScript,​ including objects and arrays of objects. The code samples are written in C#, but could easily be written in VB.NET.
  
 Also, the code samples assume the following COM visible class has been declared: Also, the code samples assume the following COM visible class has been declared:
Line 28: Line 28:
 } }
 </​code>​ </​code>​
-====Returning ​Simple Data Types====+====Returning ​simple data types====
  
 Simple data types, such as integers, doubles, and strings are easily marshalled between .NET and [[developer:​rhinoscript|RhinoScript]] because their values can be easily converted to the **Object** .NET data type. Simple data types, such as integers, doubles, and strings are easily marshalled between .NET and [[developer:​rhinoscript|RhinoScript]] because their values can be easily converted to the **Object** .NET data type.
Line 51: Line 51:
 </​code>​ </​code>​
  
-====Returning ​Arrays====+====Returning ​arrays====
 In RhinoScript,​ 3-D points are represented as  zero-based, one-dimensional arrays that contain three numbers. And, arrays of 3-D points are zero-based, one-dimensional arrays of 3-D points. In RhinoScript,​ 3-D points are represented as  zero-based, one-dimensional arrays that contain three numbers. And, arrays of 3-D points are zero-based, one-dimensional arrays of 3-D points.
  
-Array are a little more difficult to deal with, but not impossible. The .NET array classes have a **ToArray** member that will copy the elements of the array to a new **Object** array. A .NET **Object** array will marshall to COM as a **SafeArray**.+Arrays ​are a little more difficult to deal with, but not impossible. The .NET array classes have a **ToArray** member that will copy the elements of the array to a new **Object** array. A .NET **Object** array will marshall to COM as a **SafeArray**.
  
 To return a 3-D point or an array of 3-D points from our TestRhinoScriptObject object, we could add the following public members: To return a 3-D point or an array of 3-D points from our TestRhinoScriptObject object, we could add the following public members:
  
-For example: 
 <code c#> <code c#>
      ​public object GetPoint()      ​public object GetPoint()
Line 102: Line 101:
      }      }
 </​code>​ </​code>​
-====Returning ​Arrays ​of Objects====+====Returning ​arrays ​of objects====
  
 Now, lets define another COM visible class in our .NET plug-in: Now, lets define another COM visible class in our .NET plug-in:
Line 144: Line 143:
 } }
 </​code>​ </​code>​
-====Using .NET Objects ​from RhinoScript====+====Using .NET objects ​from RhinoScript====
 The following sample [[developer:​rhinoscript|RhinoScript]] code demonstrates how to get the above objects and print their return values to Rhino'​s command history window. The following sample [[developer:​rhinoscript|RhinoScript]] code demonstrates how to get the above objects and print their return values to Rhino'​s command history window.
  
developer/dotnettorhinoscript.txt · Last modified: 2016/02/09 by sandy