TexasBrownsFan
(Fresh Scripter)
2005-12-13 11:52 PM
Visio Custom Properties

I am working on a script that will create a visio diagram. I can create the the document and add items to the document. The problem i am having is that i want to add custom properties to each of the items i place on the document. I basically created a macro of what i wanted to do and now i am trying to convert it from VB over to kixtart.

Here is the Code:
Code:
Dim UndoScopeID1 As Long
UndoScopeID1 = Application.BeginUndoScope("Define Custom Properties")
Dim vsoShape1 As Visio.Shape
Dim intPropRow2 As Integer
Set vsoShape1 = Application.ActiveWindow.Page.Shapes.ItemFromID(2)
intPropRow2 = vsoShape1.AddRow(visSectionProp, visRowLast, visTagDefault)
vsoShape1.CellsSRC(visSectionProp, intPropRow2, visCustPropsLabel).FormulaU = """Property1"""
vsoShape1.CellsSRC(visSectionProp, intPropRow2, visCustPropsType).FormulaU = "0"
vsoShape1.CellsSRC(visSectionProp, intPropRow2, visCustPropsFormat).FormulaU = """@"""
vsoShape1.CellsSRC(visSectionProp, intPropRow2, visCustPropsLangID).FormulaU = "1033"
vsoShape1.CellsSRC(visSectionProp, intPropRow2, visCustPropsCalendar).FormulaU = ""
vsoShape1.CellsSRC(visSectionProp, intPropRow2, visCustPropsPrompt).FormulaU = ""
vsoShape1.CellsSRC(visSectionProp, intPropRow2, visCustPropsValue).FormulaU = """Value1"""
vsoShape1.CellsSRC(visSectionProp, intPropRow2, visCustPropsSortKey).FormulaU = ""
Application.EndUndoScope UndoScopeID1, True



Richard H.Administrator
(KiX Supporter)
2005-12-14 10:32 AM
Re: Visio Custom Properties

A quick direct conversion is:
Code:
$TRUE=Not 0
$FALSE=Not $TRUE

$UndoScopeID1 = $Application.BeginUndoScope("Define Custom Properties")
$vsoShape1 = $Application.ActiveWindow.Page.Shapes.ItemFromID(2)
$intPropRow2 = $vsoShape1.AddRow($visSectionProp, $visRowLast, $visTagDefault)
$vsoShape1.CellsSRC($visSectionProp, $intPropRow2, $visCustPropsLabel).FormulaU = '"Property1"'
$vsoShape1.CellsSRC($visSectionProp, $intPropRow2, $visCustPropsType).FormulaU = "0"
$vsoShape1.CellsSRC($visSectionProp, $intPropRow2, $visCustPropsFormat).FormulaU = '"@@"'
$vsoShape1.CellsSRC($visSectionProp, $intPropRow2, $visCustPropsLangID).FormulaU = "1033"
$vsoShape1.CellsSRC($visSectionProp, $intPropRow2, $visCustPropsCalendar).FormulaU = ""
$vsoShape1.CellsSRC($visSectionProp, $intPropRow2, $visCustPropsPrompt).FormulaU = ""
$vsoShape1.CellsSRC($visSectionProp, $intPropRow2, $visCustPropsValue).FormulaU = '"Value1"'
$vsoShape1.CellsSRC($visSectionProp, $intPropRow2, $visCustPropsSortKey).FormulaU = ""
$Application.EndUndoScope($UndoScopeID1, $TRUE)



However, there are a number of variables or enumerations which you didn't include in your code sample, so I don't know if you have defined them elsewhere in your script.


TexasBrownsFan
(Fresh Scripter)
2005-12-14 04:54 PM
Re: Visio Custom Properties

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



Chris S.
(MM club member)
2005-12-15 01:35 AM
Re: Visio Custom Properties

Wow! That has got to be the coolest and most imaginative use of fnLDAPQuery() I've seen yet. Please share the full code when you get it working.

NTDOCAdministrator
(KiX Master)
2005-12-15 01:57 AM
Re: Visio Custom Properties

Agreed overall, just scripting Visio to that degree is amazing. I use LanMapShot (no longer available) to diagram my network, but never tried doing anything with the AD layout.

What version of Visio are you running this on?
 


TexasBrownsFan
(Fresh Scripter)
2005-12-15 02:52 AM
Re: Visio Custom Properties

I am using Visio 2003 Pro. I will share the complete code when i get it finished. There is a lot that i want to put in to the script, as it is still in the early stages of development. The next part of the script i am pulling values from the first query and using that to query the subnets to find all associated subnets that portion is almost there. I have plans to map all objects associated to a sight in this script, Link Cost Etc.

I would really like to figure how to add these custom attributes so i can store all Object proberties in the visio document. The top code was created by recording a macro in Visio and then view the vb script, and that works fine as a VB Script, but can not get it to convert to Kix correctly.

If anyone can figure it out, drop me aline and i will get it into the script.


ShawnAdministrator
(KiX Supporter)
2005-12-15 04:13 AM
Re: Visio Custom Properties

crap, now I'm going to have to scam me a copy of Visio so to see this beauty - is there anyway anybody can post a sample picture of the output here ? ;0)

Les
(KiX Master)
2005-12-15 04:24 AM
Re: Visio Custom Properties

I don't have Visio 2003. I do have 2002 Enterprise with the VENT kit that does this sort of thing but MS abandoned VENT before 2003.

TexasBrownsFan
(Fresh Scripter)
2005-12-15 04:27 AM
Re: Visio Custom Properties

How can i post a picture on the BBS

ShawnAdministrator
(KiX Supporter)
2005-12-15 04:42 AM
Re: Visio Custom Properties

email the image to me at stassie (at) sympatico.ca and I will host it for you ...

Mart
(KiX Supporter)
2005-12-15 09:51 AM
Re: Visio Custom Properties

Sweet. Very cool scripting
Would like to give it a go on our AD when it's done.
Shawn, you received the picture yet?


ShawnAdministrator
(KiX Supporter)
2005-12-15 02:15 PM
Re: Visio Custom Properties

nope, no got yet.