Change shape properties from vba

Started by palomino5, September 04, 2008, 08:54:31 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

palomino5

Hi!
I'm trying to write a vba code to autocreate UML model Diagrams. Now, from VBA editor of VISIO, i can create classes with this code:

Public Sub TestDropShape()
'Dibuixa les classes millor que l'anterior
    Dim stencil As Visio.Document, objshape As Visio.Master
    Set stencil = ThisDocument.Application.Documents.Open("UML Static Structure.vss")
    ThisDocument.Application.Windows(ThisDocument.Index).Activate
    'Set the ActiveWindow to the drawing window.
    Set objshape = stencil.Masters("Class") ' Get the master named "Circle" and drop that shape on the page!
   
    ThisDocument.Pages(1).Drop objshape, 1, 3 ' Drop the shape, mstCircle, at location X=1 Y=3
End Sub


But now i'd like to change their properties from vba, like new methods, properties... Do you know if there is anyway to do this?

Thanks!


Carlos

Paul Herber

#1
I believe the built-in UML add-on won't allow you do do this, all its internal operations are hidden.

I hope VisioGuy won't mind me mentioning my own UML add-on here (I'm sure he can delete my message if he does).
I've created a Visio add-on that can create UML diagrams:
http://www.sandrila.co.uk/visio-sdl/

For what you want to do just add property and methods text to the appropriate sections of a Class symbol. There is nothing more to it than that.

Electronic and Electrical engineering, business and software stencils for Visio -

https://www.paulherber.co.uk/

Visio Guy

Hi Paul,

I don't mind you selling valid products on this site. You have real products that are pertinent to the subject-matter of this site, and to the visitors who read the content.

What's driving me nuts is that people are running Ad-blocking software, which takes a huge chunk out of the support for this site.
For articles, tips and free content, see the Visio Guy Website at http://www.visguy.com
Get my Visio Book! Using Microsoft Visio 2010

Paul Herber

#3
I need to try out the new Chrome browser sometime, for some reason it doesn't block Google ads!
I don't take much notice of the ads, personally, if there are any flashing colours then I cannot have it on the screen. There are quite a few inappropriate ads as well, especially for software competing with Visio.

But anyone running an ad-blocker is never going to click an ad anyway, and you earn income from the clicks, not the display.
Electronic and Electrical engineering, business and software stencils for Visio -

https://www.paulherber.co.uk/

palomino5

i've installed Sandrila and i've try tu put in a document the shape class from sandrila, but i can't.
could you explain how to do this?or better...could you give me some examples??
thanks!

Paul Herber

From the new SanDriLa menu, select Set Diagram Type and choose UML Class diagram from the list.
Drag and drop a Class symbol. Each of the three sections can be double-clicked to enter text, the top sectionbeing the class name etc, the second section is for properties and the third for behaviour.


Electronic and Electrical engineering, business and software stencils for Visio -

https://www.paulherber.co.uk/

palomino5

Thanks!
now i'd like to know if i change this three sections with vba from visual basic editor of Visio.

i need this to create n classes from a file.
I'm trying to do project that it could read from a javascript file and create an automatic class diagram...

Paul Herber

#7
Yes, the Class shape is a group, the three sections can be referenced as .shapes(3), (2) and (1). Unfortunately for historical reasons the top section is (3), middle is (2) and bottom is (1).
The shape and its parts resize automatically to contain all the text within the shape.

{addendum}
Editing the class name, attributes and behaviour sections automatically changes the shape's height, the width has to changed manually.
Also, I'm in the process of editing the shapes to give each of the subshapes more sensible names.
Electronic and Electrical engineering, business and software stencils for Visio -

https://www.paulherber.co.uk/

palomino5

Hi!
I'm understanding you, but i don't know if what i'm doing now it's not how it should be done.
this is my code:

Public Sub TestDropShape()
'Dibuixa les classes millor que l'anterior
    Dim stencil As Visio.Document, objmaster As Visio.Master
    Set stencil = ThisDocument.Application.Documents.Open("Object Model.vss")
    Dim shpObj2 As Visio.Shape
    ThisDocument.Application.Windows(ThisDocument.Index).Activate
    'Set the ActiveWindow to the drawing window.
    Set objmaster = stencil.Masters("Class")
   
    'ThisDocument.Pages(1).Drop objshape, 5, 7 ' Drop the shape, mstCircle, at location X=1 Y=3
     Set shpObj2 = ThisDocument.Pages(1).Drop(objmaster, 5, 7)
     shpObj2.Shapes(1) = "111111"
     shpObj2.Shapes(2) = "222222"
     shpObj2.Shapes(3) = "333333"
     

     shpObj2.Name = "jajajaj"
     
     
End Sub


Could you explain me if i'm doing something wrong, because it does'nt appear yet anything in the classes.

Thank you for all your help! :)

palomino5

sorry!
i've discovered that i've only needed to write .shapes(1).text ="example"