Media Cybernetics
From Images to Answers  
  Print version  Search
for
 
Support
Forum Home
My Profile
Register
Active Topics
Search
FAQ
Macros
Files
Files Library

Home > Support
 

IQbase Forum
IQbase Forum
IQbase Forum
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 Macros
MACROS Table of Contents


Go To Top Of PageDatabases
Go To Top Of PageMacro to create a database programmatically and add an image to it

Option Explicit

Private Const cDbName As String = "MyDB2"

Sub Test()
CreateDatabase cDbName, "D:\db\" & cDbName
ArchiveImage path & "images\colordot.tif"
End Sub

Sub CreateDatabase(name As String, path As String)
' create the database at a specific location but with the default thumbnails
Dim db As McDBDatabase
Set db = DataManager.CreateDatabase(name, path)
If Not db Is Nothing Then ' already exists or another error
' Add a folder database object type
If Not Nothing Is DataManager.MakeTypeExist(db, , "McFolder") Then
' make sure that the type is marked as a 'folder'
db.Types.Item("McFolder").Flags = db.Types.Item("McFolder").Flags Or mcdataf_FolderNode
End If

' Create a mcfolder instance as a child of the root node
db.RootNode.Children.Add "McFolder", "Images"
End If
End Sub

Sub ArchiveImage(path As String)

' Choose a command target (//<DB>\Images\)
' This function will activate and open the
' database and reference the specified database object.
If Not Nothing Is DataManager.ActiveDataNodes.Current.SetNode("//" & cDbName & "\Images") Then

' Add the file to the database.
' This will copy the image file to the database file location,
' store a link to the file data, create and store the appropriate jpeg
' thumbnails and extract any existing database attributes.
' This information will be stored to a new database object of type
' McImage named after the Image. It will reside in the database as a
' child of the database object specified by
' DataManager.ActiveDataNodes.Current

DataManager.ActiveDataNodes.addfile path, , mcdatnsm_StoreCopyFileName
End If

' Clear the command Target
DataManager.ActiveDataNodes.Clear

End Sub

Go To Top Of PageExample macro query to find all tif files in a database

if Databases("Demo") is nothing then
Databases.Add "Demo"
end if
Databases("Demo").Open

Set query = Databases("Demo").CreateQuery
query.SetName "*.tif", mcdbEQ Or mcdbIgnoreCase
For Each img In query.Execute: Debug.Print img.Name: Next

Go To Top Of PageHow can I determine if an image already exists in a database?

The following macro uses the McImage's signature
to check for duplicates. The current signature changes however if the image is modified.

Dim str As String

Dim q As McDBQuery

Dim s As McImage
Set s = Images.Open("D:\Images\afm_surf.tif", mcicfNoAddToCollection & mcicfNotVisible)

str = s.CurrentSignature
Databases("Hardwoods").Open
Set q = Databases("Hardwoods").CreateQuery
q.SetAttribute "CurrentSignature", str
Dim pmcdbnodes As mcdbnodes

Set pmcdbnodes = q.Execute
If pmcdbnodes.Count > 0 Then
MsgBox "image already exists"

End If
set pmcdbnodes = nothing

Go To Top Of PageGUI Customizations
Go To Top Of PageHow do I start a macro, form, or project automatically when IQbase opens?

To start a macro, form, or project automatically when IQbase opens use
the following steps.

1) Create a macro or form in an IQbase VBA project.


2) Set the macro or form to open automatically when the project opens. Put this code under the project's IQbase Objects ThisProject object:

'Set to McProject and Open
'start macro named Macro1 automatically when project opens
Private Sub McProject_Open(ByVal Project As McProject, ByVal Storage As Variant)
Macro1
End Sub

The above code runs the macro below, saved under Modules, which opens a form named frmTest:

Sub Macro1()
'open and run the form
frmTest.Show
End Sub


3) Set the project to open automatically when IQbase opens. Note: The IQbase user's default project opens automatically when IQbase opens. The default project is named after the user who is logged on as in "Bob (C:\Documents
and Settings\Bob\My Documents\IQbase\Projects\Bob.iqp)". So if you want to use the default project you don't need the following instructions.

If you want to start a project other than the default project when IQbase opens, then put this code in the default project's IQbase Objects
ThisProject object:

'Set to McProject and Open
Private Sub McProject_Open(ByVal Project As McProject, ByVal Storage As
Variant)
'Open project named OtherProject.iqp
Projects.Open "C:\Documents and Settings\Bob\My
Documents\IQbase\Projects\OtherProject.iqp"
'MsgBox " loaded C:\Documents and Settings\Bob\My
Documents\IQbase\OtherProject"
End Sub

Additional Notes:
The above method only works when the same identity is used. Another approach uses the ThisSession module. The ThisSession module has 2 events that can be used instead of McProject_Open. They give you a more precise control of when the event is fired, but they won't work if the project is loaded after the application is started.

McApplication_Initialize:

This event is fired once the application is fully created but just
before applying the persisted application layout and restoring all
settings. This happens during startup as well as when switching
identities.

McApplication_AfterInitialize:

This event is fired once the application is fully created and after
applying the persisted application layout and restoring all settings.

Go To Top Of PageReports
Go To Top Of PageAdd-Ins
Go To Top Of PageOperators
Go To Top Of PageAOIs & Annotations
Go To Top Of PageImage Enhancement
Go To Top Of PageGeneral
Go To Top Of PageImage Processing
Go To Top Of PageImage Analysis

| top

Register Products    Contact Us    Locate Reseller    Site Map