Domino Code Fragment

Code Name*
Design Object Maintenance
Date*
02/04/1999
Source (or email address if you prefer)*
Don Bechtold (bettndon@flash.net)
IP address:.3.144.28.50
Description*
builds an array of DESIGNOBJECTS
which returns the noteid of a design note
Type*
LotusScript
Categories*
Design Configuration
Implementation:
None (plug and play)
Required Client:
Server:
Limitations:
Comments:
test this on junk databases that don't
matter to anyone prior to using, cause it can be dangerous.
I am putting these things into public domain without any warranty and will not assume liability for their use in any way.
Now having said that, here are three subs/functions that may help you:
Files/Graphics attachments (if applicable): Code:
%REM
1) GetDesignObjectIDs() builds an array of DESIGNOBJECTS with type definition of
Type DESIGNOBJECTS
ObjectName As String
NoteID As String
NoteClass As String
End Type


2) GetDesignIDStr(db As NotesDatabase, DesignName As String, DesignType As Long) As String
which returns the noteid of a design note


3)GetNoteType(db As NotesDatabase, Byval nid As String) As String
which gives you the note type of a specific id.


4) Stuff that goes into an include file:
%end rem

Const NOTE_CLASS_DOCUMENT = &H0001
Const NOTE_CLASS_DATA = NOTE_CLASS_DOCUMENT
Const NOTE_CLASS_INFO = &H0002
Const NOTE_CLASS_FORM = &H0004
Const NOTE_CLASS_VIEW = &H0008
Const NOTE_CLASS_ICON = &H0010
Const NOTE_CLASS_DESIGN = &H0020
Const NOTE_CLASS_ACL = &H0040
Const NOTE_CLASS_HELP_INDEX = &H0080
Const NOTE_CLASS_HELP = &H0100
Const NOTE_CLASS_FILTER = &H0200 'This is an Agent, Macro
Const NOTE_CLASS_FIELD = &H0400
Const NOTE_CLASS_REPLFORMULA = &H0800
Const NOTE_CLASS_PRIVATE = &H1000
Const NOTE_CLASS_DEFAULT = &H8000
Const NOTE_CLASS_NOTIFYDELETION = NOTE_CLASS_DEFAULT
Const NOTE_CLASS_ALL = &H7FFF
Const NOTE_CLASS_ALLNONDATA = &H7FFE
Const NOTE_CLASS_NONE = &H0000
Const NOTE_ID_SPECIAL = &HFFFF0000&


' API Consts and Definitions
TYPE BLOCKID
pool as integer
block as integer
END TYPE


Const NAVIGATE_CURRENT = 0
Const NAVIGATE_NEXT = 1
Const MAXTUMBLERLEVELS = 32
Const READ_MASK_NOTEID = 1&
Const READ_MASK_NOTEUNID = 2&
Const SIGNAL_MORE_TO_DO = &H0020


' Rich Text Field Identifiers
Const MAXFACESIZE = 32
Const BYTERECORDLENGTH = &H0000
Const WORDRECORDLENGTH = &HFF00
Const SIG_CD_TEXT = &H0085 + WORDRECORDLENGTH
Const SIG_CD_BUTTON = &H00AB + WORDRECORDLENGTH
Const SIG_CD_HOTSPOTBEGIN = &H00A9 + WORDRECORDLENGTH
Const SIG_CD_HOTSPOTEND = &H00AA + WORDRECORDLENGTH
Const SIG_CD_V4HOTSPOTBEGIN = &H00AD + WORDRECORDLENGTH
Const SIG_CD_V4HOTSPOTEND = &H00AE + BYTERECORDLENGTH



TYPE LSIG
Signature as Integer
LLength as Long
END TYPE


TYPE WSIG
Signature as Integer
WLength as Integer
END TYPE


TYPE BSIG
Signature as String * 1
BLength as String * 1
END TYPE


TYPE CDTEXT
Header as WSIG
FontID as Long
TextText as String
END TYPE


TYPE CDBUTTON
Header as WSIG
Flags as Integer
Width as Integer
Height as Integer
Lines as Integer
FontID as Long
ButtonText as String
END TYPE



TYPE COLLECTIONPOSITION
Level as Integer
MinLevel as String * 1
MaxLevel as String * 1
Tumbler(0 to MAXTUMBLERLEVELS - 1) as Long
END TYPE


Declare Function NIFFindDesignNote Lib "nnotes.dll" ( _
Byval dbHandle As Long, _
Byval ObjName As String, _
Byval NoteClass As Long, _
retNoteID As Long) As Integer
Declare Sub OSPathNetConstruct Lib "nnotes.dll" ( _
Byval portName As String, _
Byval ServerName As String, _
Byval FileName As String, _
Byval retPathName As String)
Declare Function NSFDbOpen Lib "nnotes.dll" ( _
Byval PathName As String, _
dbHandle As Long) As Integer
Declare Function NSFDbClose Lib "nnotes.dll" (Byval dbHandle) As Integer
Declare Function NIFOpenCollection Lib "nnotes.dll" Alias "NIFOpenCollection" ( _
ByVal hViewDB As Long, _
ByVal hDataDB As Long, _
ByVal ViewNoteID as Long, _
ByVal OpenFlags as Integer, _
ByVal hUnreadList as Long, _
rethCollection as Long, _
ByVal rethViewNote as Long, _
ByVal retViewUNID as Long, _
ByVal rethCollapsedList as Long, _
ByVal rethSelectedList as Long) As Integer
Declare Function NIFCloseCollection Lib "nnotes.dll" Alias "NIFCloseCollection" ( _
ByVal hCollection as Integer) as Integer
Declare Function NIFReadEntries Lib "nnotes.dll" Alias "NIFReadEntries" ( _

ByVal hCollection as Long, _
IndexPos as COLLECTIONPOSITION, _
ByVal SkipNavigator as Integer, _
ByVal SkipCount as Long, _
ByVal ReturnNavigator as Integer, _
ByVal ReturnCount as Long, _
ByVal ReturnMask as Long, _
rethBuffer as Integer, _
retBufferLength as Integer, _
retNumEntriesSkipped as Long, _
retNumEntriesReturned as Long, _
retSignalFlags as Integer) as Integer
Declare Function NSFNoteOpen Lib "nnotes.dll" _
Alias "NSFNoteOpen" ( _
ByVal db_handle as Long, _
ByVal note_id as Long, _
ByVal open_flags as Integer, _
note_handle as Long) as Integer
Declare Function NSFNoteClose lib "nnotes.dll" _
Alias "NSFNoteClose" (ByVal note_handle as Long) as Integer
Declare Function OSLockObject Lib "nnotes.dll" _
Alias "OSLockObject"(ByVal Handle as Integer) as String
Declare Sub OSUnlockObject Lib "nnotes.dll" _
Alias "OSUnlockObject" (ByVal Handle as Integer)
Declare Sub OSMemFree Lib "nnotes.dll" _
Alias "OSMemFree" (ByVal Handle as Integer)
Declare Sub NSFNoteGetInfo Lib "nnotes.dll" _
Alias "NSFNoteGetInfo" ( _

ByVal note_handle as Long, _
ByVal note_member as Integer, _
value_ptr as Long)


Function GetNoteType(db As NotesDatabase, Byval nid As String) As String
Dim dbHandle As Long
Dim status As Integer
Dim Path As String * 256
Dim NoteID As Long
Dim NoteHandle As Long
Dim NoteClass As Long


On Error Goto pError1
' Set handles to NULL (to help in error handling)
dbHandle = 0
GetNoteType = ""
NoteID = Clng("&H" & nid)


Call OSPathNetConstruct("", db.Server, db.FilePath, Path)
If Path = "" Goto pError


status = NSFDbOpen( Path, dbHandle)
If status <> 0 Goto pError


status = NSFNoteOpen(dbHandle, NoteID, 0&, NoteHandle)
If status <> 0 Goto pError


Call NSFNoteGetInfo(NoteHandle, NOTE_CLASS, NoteClass)
If status <> 0 Goto pError


Select Case NoteClass
Case NOTE_CLASS_FORM
GetNoteType = "FORM"
Case NOTE_CLASS_VIEW
GetNoteType = "VIEW"
Case NOTE_CLASS_FIELD
GetNoteType = "FIELD"
Case NOTE_CLASS_FILTER
GetNoteType = "AGENT"
Case Else
GetNoteType = Format(NoteType)
End Select
pError:
If (NoteHandle <> 0) Then
Call NSFNoteClose(NoteHandle)
End If
If (dbHandle <> 0) Then
Call NSFDbClose(dbHandle)
End If
Exit Function
pError1:
If Err Then
Print Cstr(Err), Error$
Resume pError
End If
End Function


Function GetDesignIDStr(db As NotesDatabase, DesignName As String, DesignType As Long) As String
Dim dbHandle As Long
Dim status As Integer
Dim Path As String * 256
Dim NoteID As Long


' Set handles to NULL (to help in error handling)
dbHandle = 0
GetDesignIDStr = ""


On Error Goto pError

Call OSPathNetConstruct("", db.Server, db.FilePath, Path)

Call NSFDbOpen( Path, dbHandle)
If (dbHandle = 0) Then
Error 1
Goto pError
End If


Call NIFFindDesignNote(dbHandle, DesignName, DesignType, NoteID)
GetDesignIDStr = Hex$(NoteID)
pError:


If (dbHandle <> 0) Then
Call NSFDbClose(dbHandle)
End If
'Resume Next
End Function



Sub GetDesignObjectIDs()
logit "Finding Design Elements"
Dim dbHandle As Long
Dim status As Integer
Dim Path As String * 256
Dim tempdoc As notesdocument


' if a copy is made, the design view will not be built
' this opens the default view in the database which builds
' the system view
Dim v As notesview
Set v = db.Views(0)
Call v.refresh()


' Set handles to NULL (to help in error handling)
dbHandle = 0


Call OSPathNetConstruct("", db.Server, db.FilePath, Path)

Call NSFDbOpen( Path, dbHandle )
If dbHandle = 0 Goto badopendatabase


' set up variables for call to NIFOpenCollection
Dim ViewNoteID As Long
Dim OpenFlags As Integer
Dim hUnreadList As Long
Dim rethCollection As Long
Dim rethViewNote As Long
Dim retViewUNID As Long
Dim rethCollapsedList As Long
Dim rethSelectedList As Long


ViewNoteID = NOTE_CLASS_DESIGN Or NOTE_ID_SPECIAL
OpenFlags = 0
hUnreadList = 0&


status = NIFOpenCollection(dbHandle, dbHandle, ViewNoteID, OpenFlags, hUnreadList, _
rethCollection, rethViewNote, retViewUNID, rethCollapsedList, rethSelectedList)
If status <> 0 Goto badopencollection


' set up variables for NIFReadEntries
Dim CollPosition As COLLECTIONPOSITION
CollPosition.Level = 0
CollPosition.Tumbler(0) = 0
Dim rethBuffer As Integer
Dim retBufferLength As Integer
Dim retNumEntriesSkipped As Long
Dim retNumEntriesReturned As Long
Dim retSignalFlag As Integer


Dim idList0 As Variant
Dim idList() As DESIGNOBJECTS


status = NIFReadEntries(rethCollection, CollPosition, _
NAVIGATE_NEXT, 1&, NAVIGATE_NEXT, -1&, READ_MASK_NOTEID, rethBuffer, _
retBufferLength, retNumEntriesSkipped, retNumEntriesReturned, retSIgnalFlag)
If status <> 0 Goto badreadentries


'find the number of entries
If rethBuffer <> 0 Then
numtodo& = retNumEntriesReturned
Redim idlist(1 To numtodo&)
End If
Call NIFCloseCollection(rethCollection)


' now read them 1 at a time
status = NIFOpenCollection(dbHandle, dbHandle, ViewNoteID, OpenFlags, hUnreadList, _
rethCollection, rethViewNote, retViewUNID, rethCollapsedList, rethSelectedList)
If status <> 0 Goto badopencollection


For i& = 1 To numtodo&
CollPosition.Level = 0
CollPosition.Tumbler(0) = i&
status = NIFReadEntries(rethCollection, CollPosition, _
NAVIGATE_NEXT, 0&, NAVIGATE_NEXT, 1&, READ_MASK_NOTEID, rethBuffer, _
retBufferLength, retNumEntriesSkipped, retNumEntriesReturned, retSIgnalFlag)
If status <> 0 Goto badreadentries


If rethBuffer <> 0 Then
idList0 = OSLockObject(rethBuffer)
t$ = Left$(idList0, 4)
lb& = 0
For mylen = 1 To Len(t$)
lb& = lb& + Asc(Mid(t$, mylen, 1)) * Clng(256 ^ (mylen - 1))
Next
idlist(i&).NoteID = Hex$(lb&)
Call OSUnlockObject(rethBuffer)
Call OSMemFree(rethBuffer)
End If
Next
Call NIFCloseCollection(rethCollection)
Call NSFDBClose(dbHandle)


'the saga continues
Redim slobj(0 To 0)
Redim sfobj(0 To 0)
Redim nobj(0 To 0)
Redim vobj(0 To 0)
Redim aobj(0 To 0)
Redim fobj(0 To 0)
sl% = 0
sf% = 0
nav% = 0
vw% = 0
ao% = 0
fm% = 0
Forall x In db.views
Redim Preserve vobj(0 To vw%)
vobj(vw%).objectname = x.name
vobj(vw%).NoteID = GetDesignIDStr(db, vobj(vw%).objectname, NOTE_CLASS_VIEW)
If x.isfolder Then
vobj(vw%).NoteClass = "FOLDER"
Else
vobj(vw%).NoteClass = "VIEW"
End If
vw% = vw% + 1
End Forall
Forall x In db.forms
Redim Preserve fobj(0 To fm%)
fobj(fm%).objectname = x.name
fobj(fm%).NoteID = GetDesignIDStr(db, fobj(fm%).objectname, NOTE_CLASS_FORM)
If x.issubform Then
fobj(fm%).NoteClass = "SUBFORM"
Else
fobj(fm%).NoteClass = "FORM"
End If
fm% = fm% + 1
End Forall
If Isarray(db.agents) Then
Forall x In db.agents
Redim Preserve aobj(0 To ao%)
aobj(ao%).objectname = x.name
aobj(ao%).NoteID = GetDesignIDStr(db, aobj(ao%).objectname, NOTE_CLASS_FILTER)
aobj(ao%).NoteClass = "AGENT"
ao% = ao% + 1
End Forall
End If
'Dim item As notesitem
Forall dss In idList

dss.NoteClass = GetNoteType(db, dss.NoteID)

Select Case dss.NoteClass
Case "AGENT"
Forall y In aobj
If dss.NoteID = y.NoteID Goto agentfound
End Forall
dss.objectname = GetIDTitle(dss.NoteID)
If dss.objectname <> "" Then
Redim Preserve slobj(0 To sl%)
slobj(sl%) = dss
slobj(sl%).NoteClass = "SCRIPTLIB"
sl% = sl% + 1
End If


Case "VIEW"
Forall y In vobj
If dss.NoteID = y.NoteID Goto viewfound
End Forall
dss.ObjectName = GetIDTitle(dss.NoteID)
If dss.ObjectName <> "" Then
Redim Preserve nobj(0 To nav%)
nobj(nav%) = dss
nobj(nav%).NoteClass = "NAVIGATOR"
nav% = nav% + 1
End If


Case "FIELD"
Redim Preserve sfobj(0 To sf%)
sfobj(sf%) = dss
sfobj(sf%).ObjectName = GetIDTitle(dss.NoteID)
sf% = sf% + 1
End Select
agentfound:
viewfound:
End Forall
logit "Found All Design Elements"
Exit Sub


badreadentries:
badopennote:
status = 0
goodreadentries:
badopencollection:
If status = 0 Then
Call NIFCloseCollection(rethCollection)
End If
badopendatabase:
If dbHandle <> 0 Then
Call NSFDBClose(dbHandle)
End If
logit "Found All Design Elements"
End Sub