Import Shape and set their location

B

booner

I have a VB.net app (Visual Studio 2005), .net 2.0 and I'm generating some
Visio documents on the fly - importing multiple graphics (figured that all
out). So if for example, I import 4 graphics from file (could be up to 20)
in a row - they are all stacked on top of one another in the middle of the
page. What I would prefer is to have each graphic lined up next to one
another (no overlap) - starting in the upper left hand corner of the page
and each graphic be lined up - moving left to right (almost like tiling
them).

I recorded a macro - import a graphic .. select it .. move it to where I
wanted ... but this seems to be a move (relative position). I also found a
Drop method - but that seems to make a copy of the shape.

Any pointers on how best to do this would be much appreciated.

BBB
 
P

Paul Herber

I have a VB.net app (Visual Studio 2005), .net 2.0 and I'm generating some
Visio documents on the fly - importing multiple graphics (figured that all
out). So if for example, I import 4 graphics from file (could be up to 20)
in a row - they are all stacked on top of one another in the middle of the
page. What I would prefer is to have each graphic lined up next to one
another (no overlap) - starting in the upper left hand corner of the page
and each graphic be lined up - moving left to right (almost like tiling
them).

I recorded a macro - import a graphic .. select it .. move it to where I
wanted ... but this seems to be a move (relative position). I also found a
Drop method - but that seems to make a copy of the shape.

Any pointers on how best to do this would be much appreciated.

you need to set the X and Y coordinates of each shape, these are set
using the PinX and PinY cells of the shape's shapesheet.
There are many examples on the web, search for Visio shape pinx

knowing the width and height of each graphic you can calculate the X
and Y for further shapes.
 
B

booner

I googled Visio Shape pinx ... didn't see much obvious to me (if you have a
specific link - would be much appreciated) ... but after enough searching
.... did find references to this kind of thing:

vShape = vApp.ActivePage.Import(<image file>)
vShape.Cells("PinX").Formula = 1
vShape.Cells("PinY").Formula = 1

This does move the shape (evidently the units are in inches) - so need to
figure out how to move shape using other units (i.e. pixels).

Another insight - most may know ... the lower left of the the page is 0,0 (I
thought that would be upper left.
 
A

Al Edlund

I'd suggest that you check this out

http://msdn2.microsoft.com/en-us/library/aa245244(office.10).aspx

and download the visio sdk from msdn

al

booner said:
I googled Visio Shape pinx ... didn't see much obvious to me (if you have a
specific link - would be much appreciated) ... but after enough searching
... did find references to this kind of thing:

vShape = vApp.ActivePage.Import(<image file>)
vShape.Cells("PinX").Formula = 1
vShape.Cells("PinY").Formula = 1

This does move the shape (evidently the units are in inches) - so need to
figure out how to move shape using other units (i.e. pixels).

Another insight - most may know ... the lower left of the the page is 0,0
(I thought that would be upper left.
 
B

booner

Just to follow up ... several possible units to use ... in, mm, pt .. for my
purposes pt seems the best option (closest to pixels I could determine)

vShape.Cells("PinX").Formula = "10 pt"
vShape.Cells("PinY").Formula = "10 pt"

Will then use page width/height and shape's width/height and lay out the
shapes accordingly.



Al Edlund said:
I'd suggest that you check this out

http://msdn2.microsoft.com/en-us/library/aa245244(office.10).aspx

and download the visio sdk from msdn

al
 
A

Al Edlund

actually (as I remember) there is an example of converting shape coordinates
to screen coordinates in the visio sdk, which would probably save you some
time.

al
 
B

booner

Thanks - I search some more - as with searching ... all about the search
criteria you use.
 
C

Chris Roth [Visio MVP]

Hi BBB,

I've got some Visio development articles on my Visio Guy web site.

One post illustrates many facets of automating the creation of Visio
documents via code. The example generates a very simple Visio flowchart
using Visual Basic code.

Create Visio Flowcharts Programmatically
http://www.visguy.com/2006/09/13/create-visio-flowcharts-programmatically/

Translating this to VB.NET shouldn't be too hard, perhaps this will get
you going!

--
Hope this helps,

Chris Roth
Visio MVP


Visio Guy: Smart Graphics for Visual People
http://www.visguy.com
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top