Effacer les filtres
Effacer les filtres

Drawing Visio diagram using MATLAB 2018b

27 vues (au cours des 30 derniers jours)
harika kurra
harika kurra le 1 Juin 2020
Commenté : Adam Danz le 28 Juil 2021
I have been trying to draw an IO diagram in MS Visio using actxserver function of Matlab(2018b).
I am able to open Visio application and draw a rectangle with text in it using the folllowing code:
appVisio = actxserver('Visio.Application');
appVisio.Visible =1;
doc = appVisio.Documents.Add("Basic Diagram.vst");
pagObj = doc.Pages.Item(1);
stnObj=get(appVisio,'Documents','Basic Shapes.vss');
mast_circ = get(stnObj,'Masters','Rectangle');
pagObj.Drop(mast_circ, 5,5);
But I cannot get the position coordinates of rectangle drawn. If I would get the position coordinates of the rectangle drawn, I can draw the arrows to and from the rectangle showing the inputs and outputs of the block represented by the rectangle.
Note: I am using Microsoft VIsio 2007 and MATLAB 2018b
  1 commentaire
Adam Danz
Adam Danz le 28 Juil 2021
With all the software out there that produces these types diagrams, what is the motivation to do this in matlab?
I've been using drawio for a few years. It's free, simple, and fairly flexible. I recommend using that.

Connectez-vous pour commenter.

Réponses (1)

Luis
Luis le 28 Juil 2021
I was looking for something similar, and came to this example
I wrote a similar example for matlab using the actxserver. To manage the coordinates, it computes the center and top of the page, and then adds shapes based on that origin. I hope it helps
clear;
% Application
appVisio = actxserver('Visio.Application');
appVisio.Visible =1;
% Document
doc = appVisio.Documents.Add("Basic Diagram.vst");
% Page
pg = doc.Pages.Item(1);
% Get the center, top of the page:
pg_cent = pg.PageSheet.CellsU("PageWidth").ResultIU / 2
pg_top = pg.PageSheet.CellsU("PageHeight").ResultIU - 1
% Stencil
stnBasic=appVisio.Documents.OpenEx('Basic Shapes.vss',false);
stnConn=appVisio.Documents.OpenEx('Connectors.vss',false);
stnFlow=appVisio.Documents.OpenEx('BASFLO_M.vssx',false);
% Masters for process and decission
mstProcess = get(stnFlow,'Masters','Process');
mstDecision = get(stnFlow,'Masters','Decision');
conn = get(stnConn,'Masters','Dynamic connector');
%% Example 1: Two elements, one connector
a=pg.Drop(mstProcess, pg_cent,pg_top); %inches from lower left corner
a.Text = 'a';
b=pg.Drop(mstProcess, pg_cent,pg_top-1);
b.Text = 'b';
c=pg.Drop(conn, 0,0);
% Glue to the right side:
c.CellsU('BeginX').GlueTo(a.CellsU('PinX'))
c.CellsU('EndX').GlueTo(b.CellsU('PinX'))
%% Example 2: several elements
dy = .75;
for i = 0:5
new=pg.Drop(mstProcess, pg_cent+2,pg_top-i*dy); %inches from lower left corner
new.Text = sprintf('%d',i);
if i>0
c=pg.Drop(conn, 0,0);
% Glue to the right side:
c.CellsU('BeginX').GlueTo(last.CellsU('PinX'))
c.CellsU('EndX').GlueTo(new.CellsU('PinX'))
end
last = new;
end

Catégories

En savoir plus sur MATLAB dans Help Center et File Exchange

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by