Main Menu

Recent posts

#1
Programming & Code / Re: Testing row type, before t...
Last post by Nikolay - Today at 05:52:00 AM
@wapperdude
The situation is symmetrical. Meaning, the problem happens when the "type" of the "connection points" section is mismatching the type of the "row" you are adding to it. This is the issue the topic starter is trying to solve, as far as I understand (in his first post). Meaning (as an example):

Adding "visTagCnnctNamedABCD" or "visTagCnnctNamed" will not work if you try to add that to the "CP1.vsd" file from the post above (but will work for CP2.vsd)

Adding "visTagCnnctPt" or "visTagCnnctPtABCD" will not work if you try to add that to the "CP2.vsd" file from the post above (but will work for CP1.vsd)

Here is a table that clarifies it:


          visTagCnnctPt,      visTagCnnctNamed,
File      visTagCnnctPtABCD    visTagCnnctNamedABCD
-------------------------------------------------
CP1.vsd    YES                  NO
CP2.vsd    NO                  YES

The steps to try to do that are simple:

1. Download files CP1.vsd, CP2.vsd
2. Open the file CP1.vsd (or CP2.vsd)
3. Open VBA IDE, and in the "Immediate" window, type:
ActivePage.Shapes(1).AddRow visSectionConnectionPts, 0, visTagCnnctPtthen hit enter.

You can vary the "visTagCnnctPt" with the other options (visTagCnnctNamed, visTagCnnctPtABCD, visTagCnnctNamedABCD) to see if you get an error message or not.

Here is a video to clarify:

#2
Programming & Code / Re: Testing row type, before t...
Last post by wapperdude - May 16, 2024, 03:39:48 PM
@Nikolay:  you're only half wrong  ??? , and I'm only half right  :o

Your last example reminded me of the problem.  My code came from an older post, and I forgot about this issue.  You are using "visTagCnnctPt".  This does indeed replicate the problem.  I am using "visTagCnnctNamedABCD" and has no issue.

Note, using "visTagCnnctNamed" without the ABCD is also fine.
Note 2, using zero, 0, instead of visTag..., also works.  Interestingly, you get named rows, but the D-cell remains inactive.

Conclusion:  the issue is associated with using "visTagConntPt".  There are other options that work fine.
#3
Programming & Code / Re: Testing row type, before t...
Last post by Nikolay - May 16, 2024, 02:56:36 PM
I've updated the post above with an easier example that should help to understand the issue.

The topicstarter is looking for a code that would work for both CP1 and CP2 file above.
#4
Programming & Code / Re: Testing row type, before t...
Last post by wapperdude - May 16, 2024, 02:54:24 PM
@Nikolay:  Wrong.  It does both. 

First row added as normal, deleted, replaced with "named" row.  Here's the steps:
QuotevsoShp.AddRow visSectionConnectionPts, iRow, 0
        vsoShp.DeleteRow visSectionConnectionPts, iRow
        vsoShp.AddNamedRow visSectionConnectionPts, "P" & iRow, visTagCnnctNamedABCD

Second row, similar, except 1st add is named, then deleted, replaced with normal.  I watched the process as I stepped thru the code using <F8> to verify that is what is going on.

So we're all on same page, at least from Forum perspective, here's my latest test case, attached.

The file has two shapes.  Yellow square that has a master, on Document Stencil.  Master has Connection Pts section.  That section has been deleted from the shape on drawing page.  The green circle has no master and no connection pts.

Code has been modified to step thru both shapes.  No error observed.
#5
Programming & Code / Re: Testing row type, before t...
Last post by Nikolay - May 16, 2024, 02:48:02 PM
@wapperdude
The issue happens when you try to add an "unnamed" type connection point to a section that already contains "named" connection points.

Your code does not mix them; to hit the issue, it should.

Better example (attached). You have 2 files, they look exactly the same (ShapeSheet is also the same).
They have a single rectangle inside. The "connection points" section is empty (has no rows).

Now try executing this line for each of them (adds one row to connection points section):

ActivePage.Shapes(1).AddRow visSectionConnectionPts, 0, visTagCnnctPt
If you try to execute this for the first file, it succeeds.
If you try to execute the same line for the second file, it fails.

#6
Programming & Code / Re: Testing row type, before t...
Last post by wapperdude - May 16, 2024, 02:15:45 PM
@Croc, @Nikolay:  Interesting thoughts.  I tried each of your suggestions thinking that I missed something.  I have not encountered the OP's problem, nor the issue that Nikolay's code produces.

Here is my updated code to mimic Nikolay's code.  It does both cases that he shows.  It would be easy enough to copy my code and run it.

I'm running V2019 Pro on laptop with Win11 64B.

Sub ConnPts()
    Dim vsoShp As Visio.Shape
    Dim iRow As Integer

    iRow = 0
       
    Set vsoShp = ActiveWindow.Selection(1)
    vsoShp.AddRow visSectionConnectionPts, iRow, 0
    vsoShp.DeleteRow visSectionConnectionPts, iRow
    vsoShp.AddNamedRow visSectionConnectionPts, "P" & iRow, visTagCnnctNamedABCD 'Row index starts at "0", but want names to start at "1"
    Set vsoRow = vsoShp.Section(visSectionConnectionPts).Row(iRow)
    With vsoRow
        .Cell(visCnnctX).FormulaU = "Width*0"
        .Cell(visCnnctY).FormulaU = "Height*0.5"
    End With
   
    vsoShp.AddNamedRow visSectionConnectionPts, "P" & iRow + 1, visTagCnnctNamedABCD 'Row index starts at "0", but want names to start at "1"
    vsoShp.DeleteRow visSectionConnectionPts, iRow + 1
    vsoShp.AddRow visSectionConnectionPts, iRow + 1, 0
    Set vsoRow = vsoShp.Section(visSectionConnectionPts).Row(iRow + 1)
    With vsoRow
        .Cell(visCnnctX).FormulaU = "Width*1"
        .Cell(visCnnctY).FormulaU = "Height*0.5"
    End With

    vsoShp.AddRow visSectionConnectionPts, iRow + 2, 0
    Set vsoRow = vsoShp.Section(visSectionConnectionPts).Row(iRow + 2)
    With vsoRow
        .Cell(visCnnctX).FormulaU = "Width*0.5"
        .Cell(visCnnctY).FormulaU = "Height*1"
    End With

End Sub

#7
Programming & Code / Re: Testing row type, before t...
Last post by Nikolay - May 16, 2024, 01:52:37 PM
Just to clarify, the FULL CODE to reproduce the issue (as far as I understand it):

Code (vb) Select
Dim s As Shape
Set s = ActivePage.DrawRectangle(0, 0, 1, 1)

s.AddSection visSectionConnectionPts

s.AddRow visSectionConnectionPts, 0, visTagCnnctPt
s.DeleteRow visSectionConnectionPts, 0 ' <<< deleted the last row in the section

s.AddNamedRow visSectionConnectionPts, "HELLO", visTagCnnctNamed ' << BOOOM!! Empty section prohibits adding named rows

Other way around

Code (vb) Select
Dim s As Shape
Set s = ActivePage.DrawRectangle(0, 0, 1, 1)

s.AddSection visSectionConnectionPts

s.AddNamedRow visSectionConnectionPts, "HELLO", visTagCnnctNamed
s.DeleteRow visSectionConnectionPts, 0 ' <<< deleted the last row in the section

s.AddRow visSectionConnectionPts, 0, visTagCnnctPt ' << BOOOM!!! Empty section prohibits adding unnamed rows

Interesting fact: if you delete all connection points in a section, it may disappear on save. Meaning, if you save a file with empty connection point sections (i.e. a connection points section without rows), as VSDX and then open the file again, the section disappears. But if you save the file as VSD, them empty connection points section will stay.

Anyway, the whole thing looks like a mental exercise of little to no practical use.

If you have connection points in the section, check the type of the first one.
If you don't have any, just delete the section and re-add it, a new one will be able to hold any kind of connection points.
#8
Programming & Code / Re: Testing row type, before t...
Last post by Croc - May 16, 2024, 11:54:09 AM
You need code something like this
Sub ttt()
    Dim shp As Visio.Shape
    Set shp = ActiveWindow.Selection(1)
    Set mShape = shp.MasterShape
    If Not mShape Is Nothing Then
        If mShape.SectionExists(visSectionConnectionPts, 0) Then
            Debug.Print mShape.RowType(visSectionConnectionPts, 0)
        End If
    End If
End Sub
#9
Programming & Code / Re: Testing row type, before t...
Last post by Croc - May 16, 2024, 07:41:20 AM
dbramblett, perhaps your problem is that you are examining not just a shape, but a shape created on the basis of a master shape. In this case, the master-shape does not allow you to delete all rows from the section. Once deleted, rows are marked as deleted. But the row type is saved in the file. This can be clearly seen if we look at the XML.
Here are two pictures.
One shows a comparison of shapes with named and unnamed strings. Everything is the same, only the Row attributes are different.
The second picture shows the attributes of the deleted Row.
You cannot view this attachment.
You cannot view this attachment.
#10
Programming & Code / Re: Testing row type, before t...
Last post by wapperdude - May 16, 2024, 06:12:12 AM
I wasn't suggesting that you use the GUI, but rather, that is how Visio works.

However, I haven't been able to replicate your issue.  Generally, the code should check to see if a section exists, if not, add the section, and then proceed. Additionally, the code would look for the last row, and add rows from there.

In your use case, the connection points may or maynot have been added, but, the starting point is none.  Therefore no section exists.  That is the case I started with.  Actually, Visio is clever enough not to need the section to pre-exist to add rows.  And, unless otherwise instructed, will default to last row.  Perhaps not the best code form, but such an approach does work.

Sample code below.  This code starts with a selected shape, no Connection Point section.  I tried both cases.  Virgin never having any connection points, and then with connection points deleted.  The code will automatically create the needed section without explicitly telling it to.  It then adds a normal, unnamed row, followed by a named row, followed by another unnamed row.  No errors. Doesn't care if there is a mixture for purposes of adding.  As noted before, once a row is named, all rows are named.  Step thru the code with <F8>, and you will see 1st row is unnamed.  But, when 2nd row is added, both rows become named.  The 3rd row is added as if it is unnamed, but, in fact, gets added as a named row.

If you still experience difficulty, perhaps you can upload a simple case.

Sub ConnPts()
    Dim vsoShp As Visio.Shape
    Dim iRow As Integer
    Dim vsoRow As Visio.Row

    iRow = 0
       
    Set vsoShp = ActiveWindow.Selection(1)
    vsoShp.AddRow visSectionConnectionPts, iRow, 0
    Set vsoRow = vsoShp.Section(visSectionConnectionPts).Row(iRow)
    With vsoRow
        .Cell(visCnnctX).FormulaU = "Width*0"
        .Cell(visCnnctY).FormulaU = "Height*0.5"
    End With
   
    vsoShp.AddNamedRow visSectionConnectionPts, "P" & iRow + 1, visTagCnnctNamedABCD
    Set vsoRow = vsoShp.Section(visSectionConnectionPts).Row(iRow + 1)
    With vsoRow
        .Cell(visCnnctX).FormulaU = "Width*1"
        .Cell(visCnnctY).FormulaU = "Height*0.5"
    End With

    vsoShp.AddRow visSectionConnectionPts, iRow + 2, 0
    Set vsoRow = vsoShp.Section(visSectionConnectionPts).Row(iRow + 2)
    With vsoRow
        .Cell(visCnnctX).FormulaU = "Width*0.5"
        .Cell(visCnnctY).FormulaU = "Height*1"
    End With

End Sub