Drawing Visio diagram using MATLAB 2018b

19 ビュー (過去 30 日間)
harika kurra
harika kurra 2020 年 6 月 1 日
コメント済み: Adam Danz 2021 年 7 月 28 日
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 件のコメント
Adam Danz
Adam Danz 2021 年 7 月 28 日
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.

サインインしてコメントする。

回答 (1 件)

Luis
Luis 2021 年 7 月 28 日
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

カテゴリ

Help Center および File ExchangeGet Started with MATLAB についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by