dave-howard / vsdx

vsdx - A python library for processing .vsdx files
BSD 3-Clause "New" or "Revised" License
67 stars 25 forks source link

moving and resizing a shape #50

Open camhilker opened 1 year ago

camhilker commented 1 year ago

Hello,

First of all, thank you for creating this package. You've potentially saved me from having to write vba macros for automating Visio processes for my current job.

That being said, I seem to be having trouble accurately moving and resizing shapes on a page using the "height", "width", "x" and "y" attributes.

Here is a sample of what I'm experiencing:

`with VisioFile('test.vsdx') as vis:
    page = vis.get_page_by_name('box')

    box = [x for x in page.all_shapes if x.shape_name == 'box'][0]
    text = [x for x in page.all_shapes if x.shape_name == 'text'][0]

    box.x = 2.5
    box.y = 2
    box.height = 1
    box.width = 3

    text.text = "NOW A RECTANGLE"
    text.x = 5.5
    text.y = 4
    text.height = 0.5
    text.width = 5
    vis.save_vsdx('test_new.vsdx')`

example_vis_1 example_vis_2

On the second image, I'm expecting the center of the blue rectangle to be updated to (2.5, 2), but instead it appears to be centered somewhere around (2, 0.5).

Is there another way to achieve this?

I'm using Microsoft Visio Professional 2016

dave-howard commented 1 year ago

Hi @camhilker - there are a number of dependent attributes on a shape, like height/width & loc_x/loc_y (the attributes I think you might need to change) that this package isn't automatically updating as yet. It does expose these so you can try setting loc_x/loc_y on the box/rectangle There may be some that it doesn't yet expose but I'll be happy to add them. You can see the properties in the shape xml by logging the xml property - it can get a bit more complex where the shape inherits properties from a master shape but that shouldn't be the case here.