Main Menu

Recent posts

#1
Programming & Code / Re: Python ... again
Last post by Yacine - May 14, 2024, 09:18:51 PM
PPPS - COM, absolutely! I use it on simple text files, Excel of course, but also Word.
The thing that did not work at all were Access Databases. Some 32/64 bit issue, that I absolutely could not solve.


Bottom line: All the editings that are too big to do by hand and too seldom to write a right program for, are wonderfully handled by Jupyter Notebooks.

Enjoy you Honeymoon, and greetings from me and the whole Visguy core team to your wife. (I am sure no one will contradict).
#2
Programming & Code / Re: Python ... again
Last post by Yacine - May 14, 2024, 09:07:52 PM
Now we're talking. How could we use Visio in our Honeymoon.
Wrong answers only, please. ;)

P.S.: sure it's yours, but we're anxiously following along and holding our thumbs for you!
P.P.S.: Python would be a plus!
#3
Programming & Code / Re: Python ... again
Last post by Thomas Winkel - May 14, 2024, 08:08:21 PM
Hi Yacine, sorry I didn't find the time testing your notebooks yet. And now we're on our honeymoon for the next three weeks... 🥰
But this is a very exciting topic. Not only for Visio, but also for any other software with a COM interface.
I'll be back in a few weeks 8)
#4
Programming & Code / Re: Python ... again
Last post by Surrogate - May 09, 2024, 05:49:48 AM
Quote from: Yacine on May 04, 2024, 08:38:39 AMI'll rather upload some commented notebooks.
You can upload the notebooks to GitHub for easy viewing. Users do not need to download notebooks for viewing and do not need to have specific software to view ipynb files.

As an example of one of my published notebooks...
#5
General Visio / Re: A long list of shape data ...
Last post by Yacine - May 08, 2024, 08:49:44 AM
In Visual Studio there are options to generate forms from a kind of markup language (HTML or CSS like) - forgot the name.
You could use that to prepare the actual form.

Also vs being object oriented, you may consider writing generic functions to handle the different types of props. i.e. not individual routines for each prop, but a parametrized one that handles all of them and that would be editable at a unique place instead of having 30 routines to modify.
#6
General Visio / Re: A long list of shape data ...
Last post by Visisthebest - May 08, 2024, 08:26:11 AM
Thank you Yavine these are some very useful options!

I am working from a Visio VSTO so to be able to release without macros I need to create a .NET WinForm to do all this. But this is a good solution direction thank you!
#7
Visio Bugs (er...Issues) / Re: Visio 365 - Cannot link to...
Last post by wapperdude - May 08, 2024, 05:48:48 AM
...and for kicks, tried this with vsdx.  All same problems exist for this format too.
#8
Visio Bugs (er...Issues) / Re: Visio 365 - Cannot link to...
Last post by wapperdude - May 07, 2024, 07:20:53 PM
Interesting.  I agree.  There is initial issue with 1st edit in a Visio session, with VSDM, even with desktop V2019 Pro...as indicated by Surrogate.  It's as though 1st time editing the reference shape, Visio isn't capturing the event.  Open and re-edit the shape, and it's fine.  I can see this on all subsequent pages, Page-2 thru Page-4.

Few more tries...
Sometimes Page-2 updates per Surrogate.  I even saw pages 2 & 4 update, but not page 3. 

Seems, all that is needed to get all pages to update is to merely "wiggle" the reference shape.  Not necessary to edit.

...and another thing,  it's not just text.  Same issue holds true, for example, fill foreground coloring. 
#9
Visio Bugs (er...Issues) / Re: Visio 365 - Cannot link to...
Last post by Surrogate - May 07, 2024, 06:21:42 PM
Quote from: Nikolay on May 07, 2024, 10:16:03 AMRight, now I can reproduce it as well.
I use Visio 2019 Professional. I can reproduce it when after changing the text at 1st page, I switch to 2nd page. There I can see updated value in field. But then I switch to 3rd or 4th page where I find old value.

If after changing the text at 1st page, I switch to 3rd or 4th page this issue dont reproduced.  :o

If save document as vsd issue is also not reproduced...
#10
General Visio / Re: A long list of shape data ...
Last post by Yacine - May 07, 2024, 11:19:13 AM
And the jupyter notebook for the preparation magic.

# Too Many Props


```python
import xlwings as xw
```


```python
run vBase.ipynb
```

    Microsoft Visio
    TooManyProps_2024_05_07.vsdm
    Zeichenblatt-1
   


```python
filename = r'C:\Users\...\Documents\Visguy\TooManyProps\Props.xlsm' # insert the right path here.
```


```python
wb = xw.Book(filename)
```


```python
sht = wb.sheets[0]
data = sht.range('Table1').value
```


```python
data
```




    [[1.0, 'Base', 'personalID', 0.0, None],
     [2.0, 'Base', 'ForeName', 0.0, None],
     [3.0, 'Base', 'SecondName', 0.0, None],
     [4.0, 'Base', 'SurName', 0.0, None],
     [5.0, 'Base', 'BirtdDate', 5.0, None],
...




```python
shp = vWin.Selection(1)
```


```python
cats = []
for i in data:
    cat = i[1]
    if not cat in cats:
        cats.append(cat)
cats
```




    ['Base',
     'Address',
     'Contact',
     'Work',
     'HRL',
     'FacilityManagement',
     'Family',
     'Health',
     'Allergenes',
     'Medications',
     'OnCall']



### Collapsible Sub-sections


```python
cat_name = '___' + 'AllProps' + '___'
shp.AddNamedRow(visSectionProp, cat_name, visTagDefault)
shp.Cells('prop.' + cat_name + '.label').Formula = chr(34) + cat_name + chr(34)
shp.Cells('prop.' + cat_name + '.type').Formula = 1
shp.Cells('prop.' + cat_name + '.format').Formula = chr(34) + "INDIVIDUAL;TRUE;FALSE" + chr(34)
for cat in cats:
    cat_name = '___' + cat + '___'
    shp.AddNamedRow(visSectionProp, cat_name, visTagDefault)
    shp.Cells('prop.' + cat_name + '.label').Formula = chr(34) + cat_name + chr(34)
    shp.Cells('prop.' + cat_name + '.type').Formula = 3
    if cat == 'Base':
        shp.Cells('prop.' + cat_name).Formula = "TRUE"
        shp.Cells('prop.' + cat_name + '.invisible' ).Formula = "TRUE"
    cat_rows = [i for i in data if i[1] == cat]
    for row in cat_rows:
        prop = row[2]
        type_ = int(row[3])
        shp.AddNamedRow(visSectionProp, prop, visTagDefault)
        shp.Cells('prop.' + prop + '.label').Formula = chr(34) + prop + chr(34)
        shp.Cells('prop.' + prop + '.type').Formula = type_
        if type_ == 1:
            format_ = row[4]
            if format_:
                shp.Cells('prop.' + prop + '.format' ).Formula = chr(34) + format_ + chr(34)
        if cat != "Base":
            formula = 'IF(STRSAME(Prop.___AllProps___,"INDIVIDUAL"),NOT(Prop.' + cat_name + '),NOT(Prop.___AllProps___) )'
            #print(formula)
            shp.Cells('prop.' + prop + '.invisible' ).FormulaU = formula
   
```


```python
shp.DeleteSection(visSectionProp)
```

### Input form


```python
for cat in cats:
    cat_name = '___' + cat + '___'
    '''shp.AddNamedRow(visSectionProp, cat_name, visTagDefault)
    shp.Cells('prop.' + cat_name + '.label').Formula = chr(34) + cat_name + chr(34)
    shp.Cells('prop.' + cat_name + '.type').Formula = 3
    if cat == 'Base':
        shp.Cells('prop.' + cat_name).Formula = "TRUE"
        shp.Cells('prop.' + cat_name + '.invisible' ).Formula = "TRUE"
    '''
    cat_rows = [i for i in data if i[1] == cat]
    for row in cat_rows:
        prop = row[2]
        type_ = int(row[3])
        shp.AddNamedRow(visSectionProp, prop, visTagDefault)
        shp.Cells('prop.' + prop + '.label').Formula = chr(34) + prop + chr(34)
        shp.Cells('prop.' + prop + '.type').Formula = type_
        if type_ == 1:
            format_ = row[4]
            if format_:
                shp.Cells('prop.' + prop + '.format' ).Formula = chr(34) + format_ + chr(34)
    '''
        if cat != "Base":
            formula = 'IF(STRSAME(Prop.___AllProps___,"INDIVIDUAL"),NOT(Prop.' + cat_name + '),NOT(Prop.___AllProps___) )'
            #print(formula)
            shp.Cells('prop.' + prop + '.invisible' ).FormulaU = formula
    '''
```

### Sub-shapes as input



```python
shp.ConvertToGroup()
```


    ---------------------------------------------------------------------------

    com_error                                 Traceback (most recent call last)

    Cell In[51], line 1
    ----> 1 shp.ConvertToGroup()
   

    File D:\miniconda3\envs\YG1\Lib\site-packages\win32com\gen_py\00021A98-0000-0000-C000-000000000046x0x4x16\IVShape.py:155, in IVShape.ConvertToGroup(self)
        154 def ConvertToGroup(self):
    --> 155     return self._oleobj_.InvokeTypes(48, LCID, 1, (24, 0), (),)
   

    com_error: (-2147352567, 'Ausnahmefehler aufgetreten.', (0, 'Visio Professional', '\n\nRequested operation is presently disabled.', None, 0, -2032465766), None)



```python
previous_shp = None
for row in data:
    field = row[2]
    #print(field)
    fieldshp = shp.Drop(vDoc.Masters("Field"),1,1)
    try:
        fieldshp.NameU = field
    except:
        print("Error with :", field)
    fieldshp.Cells('user.invisible').Formula = "not(sheet." + str(shp.ID) + "!user.editmode)"
    if previous_shp:
        fieldshp.Cells('pinx').Formula = "sheet." + str(previous_shp.ID) + "!pinx"
        formula = "if(sheet." + str(shp.ID) + "!user.editmode; sheet." + str(previous_shp.ID) + "!piny - sheet." + str(previous_shp.ID) + "!height;0)"
        print(formula)
        fieldshp.Cells('piny').Formula = formula
    else:
        fieldshp.Cells('pinx').Formula = "sheet." + str(shp.ID) + "!controls.input"
        fieldshp.Cells('piny').Formula = "sheet." + str(shp.ID) + "!controls.input.y"
    previous_shp = fieldshp
previous_shp = None
```

    if(sheet.1!user.editmode; sheet.374!piny - sheet.374!height;0)
    if(sheet.1!user.editmode; sheet.376!piny - sheet.376!height;0)
...
   


```python
n = shp.Shapes.Count
for i in range(n,0,-1):
    shp.Shapes(i).Delete()
```


```python

```