Main Menu

Recent posts

#1
Programming & Code / Re: Python ... again
Last post by Surrogate - Today at 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 notepads... 
#2
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.
#3
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!
#4
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.
#5
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. 
#6
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...
#7
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

```

#8
General Visio / Re: A long list of shape data ...
Last post by Yacine - May 07, 2024, 11:18:02 AM
The subject inspired me. Have a look at the enclosed files.
They may give you some inspiration as well and maybe start a longer discussion.

The first demonstrates displaying only certain sub-sections of the props.
I has a global switch - ignore (shows what the sub-sections want), all on, all off
Each section has a title, highlighted by "___" title "___" to toggle the visibility of the subsection.
What I haven't done is realize a deeper hierarchy than 1. But probably easily doable.

The second approach is a form, but unlike standard forms, it is non-modal (stays open) and shows the values of the current selected shape.
With auto-update in both directions.
Splitable in sub-sections by means of a tab control.
This offers the biggest versatility, watch page 2 of the tab control, where it demonstrates the concatenation and spliting of values.
This probably a more tedious part. At least for me in VBA.
If you were to accept the idea to work with Python, then an automatically generated form is thinkable.
As for the code itself. Python may also help by generating the VBA, which you would then copy paste into the VBA IDE.
But you're still stuck with the GUI to build up manually.

Last but not least having "input" sub-shapes.
This can be specially interesting if you want to play with some graphics stuff - sliders, connections, etc.

Visio is a quite powerful tool. Most often it's us being the "bottle neck".
Visualising how a UI / a workflow has to be is IMHO the expert part of coding.
#9
Visio Bugs (er...Issues) / Re: Visio 365 - Cannot link to...
Last post by Nikolay - May 07, 2024, 10:16:03 AM
Right, now I can reproduce it as well.
It happens when you open the for file first time, like you said.
No idea how to fix. File a bug report to Microsoft?

I mean, seriously, you can click "Feedback to Microsoft" button in Visio and describe the problem, probably giving a link to this topic.
They may contact you in a few days/weeks. Even if the fix could take months or years, this could still be helpful for others.
#10
Visio Bugs (er...Issues) / Re: Visio 365 - Cannot link to...
Last post by Leines - May 07, 2024, 09:56:38 AM
Quote from: Nikolay on May 01, 2024, 09:58:34 AMThe behavior does not seem to be reproducible (see the attached sample - VSDM - updates properly)

Could it be that some macro in the VSDM file prevents the formula from working?

that's exactly how my visio is set up. i also have this bug in your visio as soon as i use Visio365.