Main Menu

Recent posts

#1
Programming & Code / Re: Looking for a list of dict...
Last post by Yacine - Today at 06:32:31 PM
You're pointing to a very vast aspect of Visio. Data handling and exchange with external apps.
There are so many possibilities.

Just to name some.
- reports - they export directly to Excel if wished
- linking shapes to an external DB or Excel file with refresh and so on.
- opening data sources by code for reading and writing
- and probably many others ...

Your method, writing data in individual dictionaries looks indeed clunky. A collection would make more sense???

Very cheap, but efficient: build up a string with defined separators.
#2
ShapeSheet & Smart Shapes / Re: Formula Not Updating
Last post by wapperdude - Today at 04:53:25 PM
The problem is TextWidth, it is defined for composed shape text, not general strings.  Syntax ~ TextWidth(theText).  See full fcn definition: https://learn.microsoft.com/en-us/office/client-developer/visio/textwidth-function

Is the Prop.BomTag the only text for this shape, and, the only way to edit the shapetext? 

If so, in the shapesheet Text Transform section, set the TxtWidth cell = TextWidth(theText), and  then, possible formula in the Width cell is:  guard(ceiling(txtwidth, 0.25))

I have replaced Floor with Ceiling such that rounding will always be larger than the text width.

There are other formulations possible using either SETF, or SETATREF functions.  Plus, you may need to protect shapetext editing.

#3
Programming & Code / Looking for a list of dictiona...
Last post by VisioForHVAC - Today at 03:28:23 PM
I have a custom shape that identifies a part that needs to be ordered and added to the bill of material for the project. The shape has the following shape data fields, TAG, PART NO, QTY, MANUFACTURER, and DESCRIPTION. I am working on a VBA script that reads through all of these shapes and combines it into one list. Eventually I will want to export that list to Excel. I'm probably thinking a csv for that, but I haven't gotten there yet.

Right now, I use a separate dictionary for each shape data field. I use the "PART NO" entry as the key to keep them organized. I feel like this isn't very efficient and there is probably a better solution that I'm not thinking of. What I really want is a list of dictionaries with multiple key value pairs. Below is what I would do in python. Is there any way to do something similar to this in VBA? Does anyone have advice on a better approach? I'm still fairly new to VBA so any input is welcome.

ls = [
    {"tag": "A", "partNO": "a", "qty": "1", "manuf": "Manuf A", "description": "the letter a"},
    {"tag": "B", "partNO": "b", "qty": "1", "manuf": "Manuf B", "description": "the letter b"},
    {"tag": "C", "partNO": "c", "qty": "1", "manuf": "Manuf C", "description": "the letter c"},
    ]

print(ls)

Public Sub test()

Dim vPage As Visio.Page
Set vPage = ActivePage
   
Dim shp As Visio.Shape
Dim tag As String
Dim partNo As String
Dim qty As Integer
Dim manuf As String
Dim desc As String

Dim tagDict As New Dictionary
Dim partNoDict As New Dictionary
Dim qtyDict As New Dictionary
Dim manufDict As New Dictionary
Dim descDict As New Dictionary

For Each shp In vPage.Shapes
   
    If shp.CellExistsU("Prop.testTag" & THePropertyName, 0) Then             
       
        tag = UCase(shp.CellsU("Prop.tag").ResultStr(visNone))
        partNo = UCase(shp.CellsU("Prop.PartNo").ResultStr(visNone))
        qty = shp.CellsU("Prop.qty.Value").ResultInt(visNone, 0)
        manuf = UCase(shp.CellsU("Prop.manuf").ResultStr(visNone))
        desc = UCase(shp.CellsU("Prop.descr").ResultStr(visNone))

        If partNoDict.Exists(partNo) Then
            qtyDict(partNo) = qtyDict(partNo) + qty
        Else           
            tagDict.Add partNo, tag
            partNoDict.Add partNo, partNo
            qtyDict.Add partNo, qty
            manufDict.Add partNo, manuf
            descDict.Add partNo, descDict           
        End If   
    End If
Next
   
End Sub
#4
ShapeSheet & Smart Shapes / Formula Not Updating
Last post by VisioForHVAC - Today at 03:03:40 PM
I have a custom shape with a shape data field where the user can enter text that shows upon the shape. I want the shape size to automatically adjust based on the length of the text. I used the following equitation in the Shape Transform -> Width section, "=GUARD(FLOOR(TEXTWIDTH(Prop.BomTag)+0.25,0.25))." This appears to work but for some reason it doesn't always update. I have to put the same text in multiple times to get the shape to re-size. I'm curious if anyone knows why it doesn't update automatically or advice on a better approach.
#5
General Visio / Re: Keep drawing maximized whe...
Last post by Yacine - May 27, 2024, 08:28:36 PM
My left foot was aching yesterday.  ;D
#6
General Visio / Re: Keep drawing maximized whe...
Last post by YossiD - May 27, 2024, 12:42:07 PM
Ok, now it has started working the way I want, but I have no idea why, as I didn't change anything. Can someone explain this?
#7
General Visio / Keep drawing maximized when op...
Last post by YossiD - May 27, 2024, 12:36:57 PM
When I open a shapesheet, the drawing window reduces to half height, and I have to "re-maximize" it after closing the shapesheet (quite annoying). Is there a way to keep the drawing window maximized, with the shapesheet opening in its own smaller window over the drawing? I'm pretty sure it worked that way for me in the past, but I can't find a setting for it.

Alternatively, is there a way to get the drawing window to automatically "re-maximize" when closing the shapesheet?

I am in Visio 2013.
#8
Shapes & Templates / Re: Grouped Shapes WILL NOT GL...
Last post by wapperdude - May 23, 2024, 09:27:08 PM
I need to get a life...

Well, for those who don't want the restrictions of combining, there is a work-around.  It might be a bit tedious.  It uses code and the Cell.GlueTo connection point method.  (Edit:  BTW, forgot to mention, that the combining approach as indicated by Nikolay, does work to reduce shape count and allow manual gluing to take place.)

The process involves adding an outward connection point to the large grouped array of shapes.  In this example, there are 51 shapes.  The 51st is a large shape, converted to group.  The remaining 50 are added to this lg shape.  It has the connection point.  A small circular shape has inward connection point.  The circular shape remains stationary, the grouped shape is moved such that its connection point glues to the circle's.  Doing this manually fails.  Doing this with code works.  The tedious part is that the group shape must be moved precisely such that its connection point aligns with the circle's.

The attachment contains the shapes and the code.  The code is actually quite simple.  The shapeID's are hard coded for this proof of concept.  Also, the coordinates of the LocPins are set to coincide with the respective connection points to simplify the movement positioning.
#9
Shapes & Templates / Re: Grouped Shapes WILL NOT GL...
Last post by wapperdude - May 23, 2024, 05:32:09 PM
For those unfamiliar with the "combining" technique, it needs to be pointed out that all "shapes" combined into a single, multiple geometry construct inherit identical formatting features.  That is, they no longer have individual, unique values for fill coloring, line style formats, etc.  For example, if one has bold, blue lines, all will have bold blue lines.  So, plan ahead when combining.  It may not be a satisfactory, global/universal solution.
#10
Shapes & Templates / Re: Grouped Shapes WILL NOT GL...
Last post by Nikolay - May 23, 2024, 03:20:53 PM
@Scott10284

Sure, you cna use "Open Group" from the context menu to edit the contents of a group without ungrouping.