The script i am working on is a script that creates a visio diagram based on Active directory Site Information. The goal is to add custom attributes to each object that resides on the Visio document as the document is created.

I am still in the early developmental stages of the script. But here is the complete script along with the Area i am having issues with.
Code:

; Script Name: VS-SiteOV.Kix
; Author: Bryan Sockel
; Script File Used to Pull Site Information from Active Directory and create a AD Site Overview Diagram


; ****************************************************************************************************
; Version Information
; ****************************************************************************************************

; Version 1.0
; 12-12-2005 - Connects to Active Directory and Pulls Site Information From Active Directory and
; Creates a Visio Diagram

; ****************************************************************************************************
; Prerequisites
; ****************************************************************************************************
; In order for Script to work correctly, the PC that the script is run from must have the following:
; * Visio Professional, not Visio Standard Visio standard does not have the AD Stencils
; * Must Include the UDF for fnLDAPQuery()
; ****************************************************************************************************
; Main Script
; ****************************************************************************************************
;Cls
Break on

include ".\Ldap.UDF"
$PageCnt = 1
$StenRowCnt = 0

$AppVisio = CreateObject("visio.application")
$docsObj = $AppVisio.Documents
$DocObj = $docsObj.Add("ACTDIR_U.VST")
$pagsObj = $AppVisio.ActiveDocument.Pages
$pagObj = $pagsObj.Item(1)

; ****************************************************************************************************
; SiteOverView Diagram
; ****************************************************************************************************
SSpacing()
$ReportHeader = "Site Overview Diagram" ; Text To appear at the top of the Report
$PageDesc = "SiteOV" ; Page Name
$pagObj.Name = "$PageDesc-P$Pagecnt"
$AppWindow = $AppVisio.ActiveWindow.Page
$Header = $AppWindow.DrawRectangle(0.2, 10.5, 8.2, 10.8) ; Create Title Box
$Header.TextStyle = "Normal"
$Header.LineStyle = "Text Only"
$Header.FillStyle = "Text Only"
$Header.Text = "$ReportHeader"
$aAttributes = "Name"
$sADsPath = "LDAP://"+GetObject("LDAP://rootDSE").Get("ConfigurationNamingContext")
$strFilter = "(&(objectClass=Site)(Name=*))"
; $strFilter = "(&(objectClass=Subnet)(Name=*))" ; Setting Filter for AD Query
$SiteResults = fnLDAPQuery($aAttributes,$sADsPath,$strFilter,"Name")
For $c = 0 to Ubound($SiteResults)
For $r = 0 to UBound($SiteResults,2)
$Site=$SiteResults[$c,$r]
$A=AddStencil("ADO_U.vss","Site",$Site)
Next
Next


; ****************************************************************************************************
; Subnet OverView Diagram
; ****************************************************************************************************
$=SSpacing()
$ReportHeader = "Subnet Overview Diagram" ; Text To appear at the top of the Report
$PageDesc = "SubnetOV" ; Page Name
$=AddPage()
$AppWindow = $AppVisio.ActiveWindow.Page
$aAttributes = "CN"
$strFilter = "(&(objectClass=Subnet)(Name=*))" ; Setting Filter for AD Query
$SubnetResults = fnLDAPQuery($aAttributes,$sADsPath,$strFilter,"Name")
For $c = 0 to Ubound($SubnetResults)
For $r = 0 to UBound($SubnetResults,2)
$Subnet=$SubnetResults[$c,$r]
$=AddStencil("ADO_U.vss","IP Subnet",$Subnet)
Next
Next


Function AddStencil($VSS,$ObjType,$ObjText);,$StencilX,$StencilY)
; ******************************************************************************************
; Function Creates Objects on Visio Document
; ******************************************************************************************
; Creating Object On Visio Diagram
$stnObj = $AppVisio.Documents("$VSS")
$mastObj = $stnObj.Masters("$ObjType")
$shpObj = $pagObj.Drop($mastObj, "$StencilX", "$StencilY")
$shpObj.Text = "$ObjText"
$shpObj.Name = "$ObjText"
$shpObj.ID = "$ObjText"

; Icrementing Counters
$StencilX = Cstr(Cdbl($StencilX) + CDbl($StenXSp))

; Checking to see if they are at the end of the row
; If So Movin on to the next row.
If $StencilX >= 8.25
$StencolCnt=0
$StencilY = CStr(cdbl($Stencily) - CDbl($StenYSP))
$StencilX = "0.5"
Endif

; Checking to see if the page is full, if the page is full
; If the page is full Creating a new page in the work book and adding the header
If $Stencily=0
; Create a new Page
$=AddPage()
$StencilY="10.00"
EndIf
EndFunction

Function AddPage()
; ******************************************************************************************
; Function Creates on New Visio Page And Adds Header
; ******************************************************************************************
$PageCnt = $PageCnt + 1
$pagsObj = $AppVisio.ActiveDocument.Pages
$Addpage = $PagsObj.Add
$addPage.Name = "$PageDesc-P$Pagecnt"
$pagObj = $pagsObj.Item(2)
$AppWindow = $AppVisio.ActiveWindow.Page
$Header = $AppWindow.DrawRectangle(0.2, 10.5, 8.2, 10.8)
$Header.TextStyle = "Normal"
$Header.LineStyle = "Text Only"
$Header.FillStyle = "Text Only"
$Header.Text = "$ReportHeader"
EndFunction

Function SSpacing()
$StencilX = "0.5" ; Starting point for the Horizontal Rows
$StencilY = "10.00" ; Starting Point for the veritcal rows
$StenYSp = "0.5" ; Used to determing the Vertical Spacing of the Rows
$StenXSp = "0.75" ; Used to determing the Horizontal Spacing of the Rows
EndFunction



Edited by bsockel (2005-12-15 07:45 PM)