Main Menu

Recent posts

#1
Shapes & Templates / Re: Connector Shape Geometry Q...
Last post by Yacine - Today at 05:25:25 PM
Here's a solution that combines simplicity with a bit of complexity. Let me explain.

First, let's tackle the basic idea. You can convert the connector to a group and place two lines within it.

1. Line 1 starts at coordinates (0,0) (the local coordinates of the connector's beginning) and ends at the width of the parent with y=0, forming a perfect horizontal line.
2. Line 2 mirrors this setup.

This works well when the connector's dx and dy are calculated. However, there's a caveat: these formulas get replaced by a fixed value below a certain threshold, which in my case is 5mm. The threshold may vary for an "imperial" installation.

I tried to identify this 5mm parameter within the pagesheet but found nothing concrete. Essentially, you'll get an offset in either or both directions.

Not fully understanding how this offset works, I resorted to brute force. It seems related to dx, dy, locpinX, and locpinY. I used these in the Begin/End of X/Y and tweaked the factors until arriving at the following formulas:

Line 1
- BeginX = (Sheet.1!EndX - Sheet.1!BeginX) * -0.5 + Sheet.1!LocPinX * 1
- EndX = (Sheet.1!EndX - Sheet.1!BeginX) * 0.5 + Sheet.1!LocPinX * 1
- BeginY = (Sheet.1!EndY - Sheet.1!BeginY) * -0.5 + Sheet.1!LocPinY * 1
- EndY = (Sheet.1!EndY - Sheet.1!BeginY) * -0.5 + Sheet.1!LocPinY * 1

Line 2
- BeginX = (Sheet.1!EndX - Sheet.1!BeginX) * 0.5 + Sheet.1!LocPinX * 1
- EndX = (Sheet.1!EndX - Sheet.1!BeginX) * 0.5 + Sheet.1!LocPinX * 1
- BeginY = (Sheet.1!EndY - Sheet.1!BeginY) * -0.5 + Sheet.1!LocPinY * 1
- EndY = (Sheet.1!EndY - Sheet.1!BeginY) * 0.5 + Sheet.1!LocPinY * 1

These formulas ensure the two lines follow the desired points.

Switching Modes
The neat part is that this setup allows you to switch between a regular connector and an "almost" straight version. I used a formula in the parent shape to calculate dx and dy, and if they are small enough, the connector switches to the other mode.

Since the 5mm threshold is somewhat arbitrary, I added a custom property so you can set this value yourself. The visibility of either the main connector or the two subshapes toggles exclusively based on this threshold.

This method keeps the connector fully functional while providing the flexibility to switch between different behaviors.

Regards,
Yacine
#2
Shapes & Templates / Re: Connector Shape Geometry Q...
Last post by wapperdude - May 31, 2024, 11:20:59 PM
 ;D   Surprised it didn't ask..."Who's Yacine?"  That would have been hilarious.

Just to be clear, my post was about the original post, not Yacine's 1st reply.  Think I'll go ask chatAI why 2 + 2 =4?
#3
Shapes & Templates / Re: Connector Shape Geometry Q...
Last post by Yacine - May 31, 2024, 09:24:40 PM
I thought, it would be clever to be lazy ... read my inquiry @ chatGPT. Quite funny.
https://chatgpt.com/share/3726e515-2234-4b67-a0c3-abef7453ca3e
#4
Shapes & Templates / Re: Connector Shape Geometry Q...
Last post by wapperdude - May 31, 2024, 08:11:04 PM
Pretty sure I've seen this before.  But, I've not been able to replicate the problem now.  I tend to concur with Yacine's conclusion.  Can you upload a sample file so something simple isn't overlooked?
#5
Shapes & Templates / Re: Connector Shape Geometry Q...
Last post by Yacine - May 31, 2024, 06:46:18 PM
Yes, very annoying this behavior and I wouldn't know of a simple solution.
However you can build your own connector.
You basically work with a 1D group shape and have straight lines in it.


P.S. Specially this exasperating fine tuning of connectors has led to be very strict with grids and connection points.
In cases, where I cannot avoid it, I help myself with connection points attached to control points. Very effective.
#6
Shapes & Templates / Connector Shape Geometry Quest...
Last post by Scott10284 - May 31, 2024, 11:56:06 AM
Is there a way to prevent a Connector shape from automatically straightening itself?

At times I would like to position a connector such that there is a very small "step" in the shape geometry and it responds by straightening itself out into a small slope instead. I have tried changing many different properties in the Behavior menu (such as setting the Connector Style to Right Angle), but none of them seem to work.

Is there a way to prevent this shape behavior?
#7
Programming & Code / Re: Looking for a list of dict...
Last post by Yacine - May 28, 2024, 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.
#8
ShapeSheet & Smart Shapes / Re: Formula Not Updating
Last post by wapperdude - May 28, 2024, 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.

#9
Programming & Code / Looking for a list of dictiona...
Last post by VisioForHVAC - May 28, 2024, 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
#10
ShapeSheet & Smart Shapes / Formula Not Updating
Last post by VisioForHVAC - May 28, 2024, 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.