Click or drag to resize

IMcEngineCreateOperator Method

Create an "operator and store a connection to it in the Object Manager.

Namespace:  MediaCy.IQL.Engine
Assembly:  MediaCy.IQL.Engine (in MediaCy.IQL.Engine.dll) Version: 10.0.6912.0
Syntax
VB
Function CreateOperator ( 
	ProgIDorCLSID As String,
	<OptionalAttribute> varParent As Object,
	Optional Name As String = ""
) As Object

Parameters

ProgIDorCLSID
Type: SystemString
Registered Prog ID of the "coclass" of this object. Or the CLSID in a form like "{DC2F6FCB-08A7-40c0-BBDB-D3894B1C5F68}"; the braces are required. If the class has already been registered with the McObjects object manager, then just the registered type name is required. The registered type name is the portion of the ProgID after the first period up to any second period. All coclasses in the Image Pro type library are registered at start up, so as illustrated in the examples, you can just use the type name for virtually all "operators". As illustrated in Example 3, if a Name is given of an existing McObject or operator, then you may optionally leave the ClassID blank. If you do supply a ClassID along with a Name, then any existing operator of the given name must match the registered type of the ClassID argument.
varParent (Optional)
Type: SystemObject
[in,optional] If given, a parent operator interface or the McObject of the parent operator interface. If no parent is given, then a "global" instance of the operator interface is created. Most operators require a particular type of parent or ancestor to function (e.g., the McHistogram operator shown in the first example needs to be a descendent of a McImage instance). The CreateOperator method may fail if the proper type of parent is not supplied.
Name (Optional)
Type: SystemString
[in,defaultvalue("")] If given, the name of an existing operator of type ClassID, or the name to be given to a newly created operator. If a new operator is given a Name, the operator will not be released until it's McObject is removed from the McObject's collection; see Example 2. If no name is given, then the operator is released as soon as the returned interface is; see Example 1. Named operators with a parent operator can be accessed from VB as if they were a built-in property (see Example 2).

Return Value

Type: Object
The new or existing interface instance.
Remarks
This function provides a convenient way to create an "operator" (an interface implementing IMcHasObject) and registering it in the McObjects Object Manager. This enables the interface to receive notifications and access other registered objects like McEngine or McEngine.Images. You may optionally specify a parent operator (or its connected McObject) and/or a name. If both a name and parent operator are given, then the object becomes available by name from VB (see Example 2).
Note Note
If a Name of an existing operator is supplied, CreateOperator will return any existing operator of the same parent, name and type. An error is generated if the Name is of the wrong type for a given ClassID argument. If the object is created (that is, an object of a given name did not already exist), then it is part of an McObjects category named "CreatedOperator". Named operators are not released until their backing McObject is removed from the McObjects collection. This happens automatically when the parent operator is removed from the collection. Thus in Example 2, the newly created operator named "MyAoiCopy" would be removed from the collection and released as soon as the ThisApplication.ActiveImage was closed, even without the last line in the example.
Examples
VB
'Example 1, create an unnamed, private McHistogram as a child of the ActiveImage
Public Sub PrivateHistogram()
Dim myHistogram As MediaCy.Iql.Operations.McHistogram
myHistogram = ThisApplication.CreateOperator("McHistogram", ThisApplication.ActiveImage)
myHistogram.BinCount = 4   'four only bins
Dim Ch0Bins As Object = myHistogram.Values(-1,0) 'All channel 0 bins
Dim strBins As String = ThisApplication.GlobalTools.McToText(Ch0Bins).Value()
MsgBox( "Counts in the four bins from Ch0 are " + strBins)
myHistogram = Nothing  'Free the operator we created
End Sub 'PrivateHistogram
'Example 2, create an named McRegions as a child of the ActiveImage
Public Sub NamedMcRegionsOperator()
Dim mcregionsAoiCopy As MediaCy.IQL.Features.McRegions
mcregionsAoiCopy = ThisApplication.CreateOperator("McRegions", ThisApplication.ActiveImage, "MyAoiCopy")
mcregionsAoiCopy.CopyFrom ThisApplication.ActiveImage.Aoi ' capture current Aoi
ThisApplication.ActiveImage.Aoi.Reset ' clear the Aoi
mcregionsAoiCopy = Nothing 'Does NOT release the new operator
MsgBox("Aoi should be clear now.",,"NamedMcRegionsOperator")
'Access our new operator just like a built in property. Use it to restore
ThisApplication.ActiveImage.Aoi.CopyFrom ThisApplication.ActiveImage.MyAoiCopy 'the copy of the Aoi.
MsgBox("Aoi should be restored now.",,"NamedMcRegionsOperator")
'Release the new operator by removing its McObject from McObjects and killing it
ThisApplication.McObject(ThisApplication.ActiveImage.MyAoiCopy).KillObjectAndChildren
End Sub 'NamedMcRegionsOperator
'Example 3, access an existing object
Public Sub AccessExistingOperator()
Dim mcregionsAoi As MediaCy.IQL.Features.McRegions
mcregionsAoi = ThisApplication.CreateOperator("", ThisApplication.ActiveImage, "Aoi")
MsgBox("The Aoi has " + CStr(mcregionsAoi.Count) + " individual features.")
' but the following works just as well and is clearer
mcregionsAoi = ThisApplication.ActiveImage.Aoi
MsgBox("The Aoi is of the following overall type: " + Format(mcregionsAoi.Type(-1),"X")) + " hex."
End Sub 'AccessExistingOperator
See Also