Author Topic: How to draw entity in empty diagram?  (Read 140 times)

0 Members and 1 Guest are viewing this topic.

jaryszek

  • Jr. Member
  • **
  • Posts: 15
How to draw entity in empty diagram?
« on: December 03, 2018, 01:40:04 AM »
Hi,

i want to add entity in empty crow's foot diagram.

So open new page and add entity "tblDisks" with 3 fields:
1. Primary Key Attribute - "DiskID"
2. FieldName - DiskName
3. FieldName - DiskSize

How can i achieve this?

Best,
Jacek

Surrogate

  • Hero Member
  • *****
  • Posts: 865
    • ShapeSheet™ Knowledge Base
Re: How to draw entity in empty diagram?
« Reply #1 on: December 03, 2018, 04:00:06 AM »
Hi, Jacek !
Start macro-recorder, do these steps with user interface and analyze code.

jaryszek

  • Jr. Member
  • **
  • Posts: 15
Re: How to draw entity in empty diagram?
« Reply #2 on: December 10, 2018, 03:59:36 AM »
hi,

thank you.

Maybe it is good way to start.
Maybe any examples?

Best,
Jacek

Yacine

  • Hero Member
  • *****
  • Posts: 2509
Re: How to draw entity in empty diagram?
« Reply #3 on: December 10, 2018, 09:54:38 AM »
Hello Jacek,
there seems to be a misunderstanding.

In Visio there is a feature called "macro recorder". It is only available if you set your Visio application in "developer" mode.
Once started, this feature makes Visio write in VBA every thing you do manually in the UI.
The so recorded code (the macro) can then be edited to make suitable for generic use.

Witaj Jacek,
wydaje się, że istnieje nieporozumienie.

W Visio istnieje funkcja zwana "makro rejestratorem". Jest ona dostępna tylko wtedy, gdy aplikacja Visio jest ustawiona w trybie "deweloperskim".
Po uruchomieniu ta funkcja sprawia, że Visio pisze w VBA każdą rzecz, którą robisz ręcznie w interfejsie użytkownika.
Zarejestrowany w ten sposób kod (makro) można następnie edytować w celu dostosowania go do użytku ogólnego.
« Last Edit: December 10, 2018, 09:57:32 AM by Yacine »
Yacine

jaryszek

  • Jr. Member
  • **
  • Posts: 15
Re: How to draw entity in empty diagram?
« Reply #4 on: December 11, 2018, 05:51:39 AM »
hi Yacine,

thank you. It is the best way to create macros in Visio? Recording them?
In Excel recorded macro have very bad performence and using not very fast methods and properties...


Best,
Jacek

Surrogate

  • Hero Member
  • *****
  • Posts: 865
    • ShapeSheet™ Knowledge Base
Re: How to draw entity in empty diagram?
« Reply #5 on: December 11, 2018, 06:48:47 AM »
Hi, Jacek !

Of course recorded macros have not best performance, but this way is better for persons who not familiar with VBA in MS Visio.

Yacine

  • Hero Member
  • *****
  • Posts: 2509
Re: How to draw entity in empty diagram?
« Reply #6 on: December 12, 2018, 04:14:43 AM »
@Jacek,

no, the macro recorder is not meant to make a final perfect macro. But it shows you the VBA commands you are looking for.

In your case the question is "how can I draw a shape?" or "how can I a drop a master from a stencil on the drawing?". The recorder will show you that "drop" is the right command.
Now you have to manually write your VBA code, where you define the target (activepage), the stencil (either hard coded or entered by means of a dialog), same for the master, an so on.
First recorded macro - using the mectric basic shapes stencils could look as follows:
Code: [Select]
Sub Macro1()

    'Enable diagram services
    Dim DiagramServices As Integer
    DiagramServices = ActiveDocument.DiagramServicesEnabled
    ActiveDocument.DiagramServicesEnabled = visServiceVersion140 + visServiceVersion150

    Application.Windows.ItemEx("Drawing1  [Compatibility Mode]").Activate
    Application.ActiveWindow.Page.Drop Application.Documents.Item("BASIC_M.VSSX").Masters.ItemU("Rectangle"), 4.527559, 8.464567

    'Restore diagram services
    ActiveDocument.DiagramServicesEnabled = DiagramServices

End Sub
There will be very little left when you strip all the unnecessary parts:
Sub Macro1()

    'Enable diagram services

    Dim DiagramServices As Integer
    DiagramServices = ActiveDocument.DiagramServicesEnabled
    ActiveDocument.DiagramServicesEnabled = visServiceVersion140 + visServiceVersion150

    Application.Windows.ItemEx("Drawing1  [Compatibility Mode]").Activate

    Application.ActiveWindow.Page.Drop Application.Documents.Item("BASIC_M.VSSX").Masters.ItemU("Rectangle"), 4.527559, 8.464567

    'Restore diagram services
    ActiveDocument.DiagramServicesEnabled = DiagramServices


End Sub
You get: "Application.ActiveWindow.Page.Drop Application.Documents.Item("BASIC_M.VSSX").Masters.ItemU("Rectangle"), 4.527559, 8.464567"
Now you strip the line into single parts Application.ActiveWindow.Page.Drop Application.Documents.Item("BASIC_M.VSSX").Masters.ItemU("Rectangle"), 4.527559, 8.464567.     Drop is the command identified - you google it and find out that you need a target (red), a source (blue) and a position (green) where to drop the shape.
The elements (target, source, ...) are unfortunately always formulated in a very specific way. You need to learn to understand and reformulate them. That's something you need to find out and get accustomed to. -
Application.ActiveWindow.Page translates to "activepage".
-
Application.Documents.Item("BASIC_M.VSSX").Masters.ItemU("Rectangle") could be translated for sake of generalisation into:
Code: [Select]
dim myStencilSting as string
dim myMasterString as string

dim shp as shape

Then you would re-write the macro to:

Code: [Select]
myMasterString = "Rectangle" 'or dynamic input
myStencilString = "Basic_M.VSSX" 'or dynamic input

x=0

y=0
set shp = ActivePage.drop (ActiveDocument.Item(myStencilString, myMasterString, x,y)
« Last Edit: December 12, 2018, 06:49:39 AM by Yacine »
Yacine