Page 1 of 1 1
Topic Options
#153356 - 05/12/13 11:52 PM Visio Custom Properties
TexasBrownsFan Offline
Fresh Scripter

Registered: 01/02/07
Posts: 36
Loc: Fort Worth , TX, USA
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


Top
#153357 - 05/12/14 10:32 AM Re: Visio Custom Properties
Richard H. Administrator Offline
Administrator
*****

Registered: 00/01/24
Posts: 4940
Loc: Leatherhead, Surrey, UK
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.

Top
#153358 - 05/12/14 04:54 PM Re: Visio Custom Properties
TexasBrownsFan Offline
Fresh Scripter

Registered: 01/02/07
Posts: 36
Loc: Fort Worth , TX, USA
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 (05/12/15 07:45 PM)

Top
#153359 - 05/12/15 01:35 AM Re: Visio Custom Properties
Chris S. Moderator Offline
Moderator
*****

Registered: 02/03/18
Posts: 2368
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.
Top
#153360 - 05/12/15 01:57 AM Re: Visio Custom Properties
NTDOC Administrator Online   content
Administrator
*****

Registered: 00/07/28
Posts: 11382
Loc: CA
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?
 

Top
#153361 - 05/12/15 02:52 AM Re: Visio Custom Properties
TexasBrownsFan Offline
Fresh Scripter

Registered: 01/02/07
Posts: 36
Loc: Fort Worth , TX, USA
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.

Top
#153362 - 05/12/15 04:13 AM Re: Visio Custom Properties
Shawn Administrator Offline
Administrator
*****

Registered: 99/08/13
Posts: 8601
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)
Top
#153363 - 05/12/15 04:24 AM Re: Visio Custom Properties
Les Offline
KiX Master
*****

Registered: 01/06/11
Posts: 12734
Loc: fortfrances.on.ca
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.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#153364 - 05/12/15 04:27 AM Re: Visio Custom Properties
TexasBrownsFan Offline
Fresh Scripter

Registered: 01/02/07
Posts: 36
Loc: Fort Worth , TX, USA
How can i post a picture on the BBS
Top
#153365 - 05/12/15 04:42 AM Re: Visio Custom Properties
Shawn Administrator Offline
Administrator
*****

Registered: 99/08/13
Posts: 8601
email the image to me at stassie (at) sympatico.ca and I will host it for you ...
Top
#153366 - 05/12/15 09:51 AM Re: Visio Custom Properties
Mart Moderator Online   content
KiX Supporter
*****

Registered: 02/03/27
Posts: 4413
Loc: Rotterdam, The Netherlands
Sweet. Very cool scripting
Would like to give it a go on our AD when it's done.
Shawn, you received the picture yet?


Edited by Mart (05/12/15 09:51 AM)
_________________________
Mart

- I don't have an attitude! I just have a personality that you cannot handle! - Jerry the mouse.

Top
#153367 - 05/12/15 02:15 PM Re: Visio Custom Properties
Shawn Administrator Offline
Administrator
*****

Registered: 99/08/13
Posts: 8601
nope, no got yet.
Top
Page 1 of 1 1


Moderator:  Chris S., Shawn, ShaneEP, Sealeopard, Bryce, Jochen, Radimus, Kdyer, Howard Bullock, Glenn Barnas, Allen, Benny69, Mart 
Hop to:
Shout Box

Who's Online
4 registered (Mart, Allen, NTDOC, Bonji) and 34 anonymous users online.
Newest Members
defghi726589, ghijkl436221, ap3tech, Sean_Tyler, Villanueva
16718 Registered Users

Generated in 0.069 seconds in which 0.026 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org