Image Sampler Node Update

Hi All,

I am testing out another workflow using some hand drawings, I have a thought of using the image sampler but my skills in Visual Studio are not great.

The old ImageSamplerNode visual studio code has some updates needed. I was wondering if anyone knew where I would start looking for information on what to change. 

There are "type or namespace" errors in lines

using Bentley.GenerativeComponents.Nodes;

[Replicatable, ParentNodeScope] int ArrPtsX,

I am making a guess but would this be a UtilityNode as it doesn't produce geometry, it sort of functions like the calculator node in the sample addin?


Any pointers would be appreciated.



The script in full is:


// Source adapted from Ralf Lindemann's imageUVSampler
// which had been based code by Marc Hoppermann (

using System;
using System.Drawing;
using System.Collections.Generic;
//using System.Windows.Forms;
//using Bentley.Geometry;
using Bentley.GenerativeComponents;
using Bentley.GenerativeComponents.Features;
using Bentley.GenerativeComponents.GCScript.NameScopes;
using Bentley.GenerativeComponents.GeneralPurpose;
using Bentley.GenerativeComponents.GCScript;
using Bentley.GenerativeComponents.MicroStation;
using Bentley.GenerativeComponents.View;
using Bentley.Interop.MicroStationDGN;
using Bentley.GenerativeComponents.GCScript.GCTypes;
using Bentley.GenerativeComponents.GCScript.ReflectedNativeTypeSupport;
using Bentley.GenerativeComponents.Nodes;

namespace ImageSampler
[GCNamespace("User")] // This custom attribute specifies that, when this node type is loaded into GC, it will be put into
// the GC namespace "User". (So, within GC, this node type's full name will be "User.ImageSamplerNode".)

[NodeTypePaletteCategory("Utility")] // The NodeTypePaletteCategory attribute lets us specify where this
// Calculator node type will appear within GC's Node Types dialog.
// So, it will appear within a group named "Sample Add-In".

[NodeTypeIcon("Resources/ImageSamplerNode.png")] // The NodeTypeIcon attribute lets us specify the graphical image (icon)
// that will appear on the Calculator node type's button within GC's Node
// Types dialog.

public class ImageSampler: Feature
/// <summary>ImageSampler reading pixels</summary>
public NodeUpdateResult ReadPixels
NodeUpdateContext updateContext,
[Replicatable, ParentNodeScope] int ArrPtsX,
[Replicatable] int ArrPtsY,
[Replicatable] int GridH,
[Replicatable] int GridV,
string ImagePath,
[Out] ref int Width,
[Out] ref int Height,
[Out] ref int R,
[Out] ref int G,
[Out] ref int B,
[Out] ref double Grayscale
double x = ArrPtsX;
double y = ArrPtsY;
if(false == System.IO.File.Exists(ImagePath))
Width = 0;
Height = 0;
R = 0;
G = 0;
B = 0;
Grayscale = 0.0;
return new NodeUpdateResult.IncompleteInputs("ImagePath");

Bitmap myBitmap = new Bitmap(ImagePath);
Width = myBitmap.Width;
Height = myBitmap.Height;

// this logic needs review
double stepX = Width / GridH;
double stepY = Height / GridV;
double pixelPosX = stepX * x;
double pixelPosY = stepY * y;

// get pixel information
Color pixelValue = myBitmap.GetPixel(Convert.ToInt32(pixelPosX), Convert.ToInt32(pixelPosY));

R = pixelValue.R;
G = pixelValue.G;
B = pixelValue.B;

// calculate gray scale
Grayscale = (0.3 * R + 0.59 * G + 0.11 * B) / 255.0;

return NodeUpdateResult.Success;


Parents Reply Children