Main Menu

Recent posts

#1
Programming & Code / Re: Testing row type, before t...
Last post by Nikolay - Today at 05:35:02 PM
The first step to solve the problem is to understand it :D
Meaning, to reproduce the issue. That's what I was trying to show - to explain the issue, not to solve it.

Did you try to follow the steps form the above post?
I mean, 1, 2, 3
#2
Programming & Code / Re: Testing row type, before t...
Last post by wapperdude - Today at 01:54:40 PM
@Nikolay:
Clearly we're not on same page.  I tried to follow the video, but couldn't quite understand it.

I took the CP1 and CP2 files, copied my code from reply #11.  Code ran fine for both files.  Added 3 connPts both files.  No errors.   Note, the code syntax "shape.addrow" does NOT like any visTagCnnct entry.  Only a "0".  It is the "shape.addnamedrow" that accepts the visTag entries, except not the visTagCnnctPt.

I'm not seeing your objection.  I don't understand why you haven't tried the code.  I don't understand why you haven't tried the sample file that I provided.  The one caveat is that you start with a shape that has no connection points...like your 2 CP files do.  So, if you run the code once, you need to go back into shapesheet and delete the connection points before running the code again.  If you don't, you get extra connection point added to shape.  But, code kinda runs => produces exception error.

While not necessary, I would tile the drawing window and shapesheet window as your files do, plus the code window so that all 3 are easily visible.  Then, step thru the code using <F8> to execute code 1 line at a time.  You will see that for row1, it is 1st unnamed.  Then deleted.  Then named, as progression thru code continues.  Row2 starts by setting it to named.  Deleted.  Then unnamed.  As it always appears to be a named row, due to row1, the point of the 2nd row is to show that the code does execute in reverse order.  Row3 is a simple addition that takes place after the above 2.

It is then easy enough to modify the code, specifically, change the visTagCnncts entry.  visTagCnnctsPt fails.  Replacing the entry with "0" (no quotes) works too.

It is a simple test.  Do me the courtesy to try it.  I tried yours.  The visTagCnnctPt produced an error everytime.  On that we agree.
#3
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:

#4
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.
#5
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.
#6
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.
#7
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.

#8
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

#9
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.
#10
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