Main Menu

Recent posts

#1
Programming & Code / Re: Testing row type, before t...
Last post by wapperdude - Today at 08:58:36 PM
Actually, my point is that there's no need to test!  Just don't use visTagCnnctPt.  Period. Use 0 instead.  Then, if you want a named row, see syntax given above.  You do not need to test.  Just define the rows as you like. 

Functionally, the only differences between named and unnamed are, well, being able to reference a row by name.  Yeah, I know, Duh!  and having access to the D-cell.  If you don't use either of these features, just use default unnamed.  Visio does not require you to maintain rowtype.  In fact, that was demonstrated in my reply #11 code. 

I guess, one question is,  using multiple copies of this shape?  Again, if you don't use the features of named row, then it's who cares.  Use the "0" and add to your hearts content.

The other question would be, type of connection point:  inward, outward, both.  That has nothing to do with rowtype.
#2
Programming & Code / Re: Testing row type, before t...
Last post by dbramblett - Today at 08:40:36 PM
Hey thanks everyone for jumping on this one. Also my bad all, I assumed the question was a simple thing to answer and didn't think about adding code to demonstrate.

1. @Croc: About Masters: Negative. I actually got started down this road because I wanted to make a stencil of a network switch with connection points for each port and didn't want to manually add all the ports with exact spacing. There are no masters on the sheet at present. Just a rectangle shape I drew. So no masters at all under Document Stencils.

2. @Croc: About the code something like this: Well your not wrong, except that code only works if the row indice is present. If there are no rows, there is nothing to test.

3. @Nikolay: About Just to clarify: Precisely my issue.  Additionally, it never occured to me the section might disappear on save. But I disagree that there is no practical use for knowing what the section will allow in terms of a row type. I think it would allow me to provide better feed back in terms of errors and possibly simplify some code.  Otherwise, I'd have to write a bunch of extra code to check various conditions and derive the correct answer to what kind of addrow method is called for.

4. @wapperdude and @Nikolay: Thanks for the extra effort. What I'm getting out of this is that I can only test for row type, if there is already a row to test. If there isn't I basically just have to try and add the row then see if I get an error, then try the other. Not great, but if that's the only way, I guess that's that.
#3
Programming & Code / Re: deleted data magically rea...
Last post by perry59 - Today at 08:12:15 PM
Quote from: Yacine on Today at 07:07:54 PMThis should come from the Master - not the one in the original stencil, but the one in the document stencil.

If you can afford to delete the master - careful on that point! - this could solve your problem.


BINGO!
As soon as you said "master" the light went on in my head.
I deleted the master from the document stencil and all worked as planned.
Thanks Yacine!
#4
Programming & Code / Re: deleted data magically rea...
Last post by Yacine - Today at 07:07:54 PM
This should come from the Master - not the one in the original stencil, but the one in the document stencil.

If you can afford to delete the master - careful on that point! - this could solve your problem.

#5
Programming & Code / deleted data magically reappea...
Last post by perry59 - Today at 06:21:23 PM
I am working on some code that will convert old versions of shapes I have defined into newer versions. All this entails is deleting user, shape and action data from the shapesheet. Rather than going through each cell I just delete the section. Afterward I replace the deleted data with my new data. Sounds simple right?
while stepping through the code I see the SS sections being deleted and if I stop execution and look at the shapesheet those sections are indeed gone. If I resume execution though when adding those sections back to the shape all the old data reappears! Now the shape has both the old data and the new data!
How can this possibly happen? It's driving me nuts!
thanks for any insights
#6
Programming & Code / Re: Testing row type, before t...
Last post by wapperdude - May 18, 2024, 06:08:42 PM
Follow-up to last above entry, I decided to simplify my code that adds multiple connection points. The code adds 3 rows in this order:  unnamed, named, unnamed.  It was run on both CP1 and CP2 files.  The addrow syntax used is as follows:
> Unnamed:        vsoShp.AddRow visSectionConnectionPts, iRow, visTagCnnctPt
> Named:            vsoShp.AddNamedRow visSectionConnectionPts, "P" & iRow + 1, visTagCnnctNamed
        where iRow is the row index counter

The anticipated result would be error after 1st row attempted addition as indicated by OP.
More likely scenarios would be error after 2nd or 3rd attempts as each would have a preceding, existing different row type.

What was observed, 1st and 2nd row additions always worked for either CP file.  The 3rd row addition generated the error both files.  This was easily corrected with simple change.  In the 3rd row, syntax change to replace visTagCnnctPt with the number 0.  With that change, the code runs with no errors and all 3 connection points are successfully added.

Background:  VisioPro 2019, Win11 64B, CP1.vsdm, CP2.vsdm

The revised code:
Sub ConnPts()
' This macro explores adding connection points to a shape programmitically.
' It is not necessary to add the Connection Point section prior to adding rows.
' This code presumes there are no pre-existing connection points.

' Using visTagCnnctPt seems to cause grief.

    Dim vsoShp As Visio.Shape
    Dim iRow As Integer
    Dim vsoRow As Visio.Row

    iRow = 0
       
    For Each vsoShp In ActivePage.Shapes
        vsoShp.AddRow visSectionConnectionPts, iRow, visTagCnnctPt
        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, visTagCnnctNamed
        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, visTagCnnctPt
        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
    Next

End Sub

QED

Add note:  each CP file was downloaded and immediately saved as vsdm.  Each vsdm file was re-loaded, code was pasted in and run.  Eventually, file resaved with code.  Original vsd files remain unedited.
#7
Programming & Code / Re: Testing row type, before t...
Last post by wapperdude - May 18, 2024, 05:34:41 AM
Yes.  I ran steps 1 - 3, both files.  Re-ran again, just a bit ago.  I get different results from those posted in response #16 posted by Nikolay.
I ran code below, with only 1st line active.  It runs fine for both CP1 and CP2 files.  Then, close Visio, no saving.  Reload each CP file.
Re-run code with just 2nd line active.  Runs fine in both CP1 and CP2 files.  No errors.  Two configuration differences:  1st, I'm running from code window, not immediate window.  The other difference is that I had to save the CP files as vsdm in order to run code.  So, not using vsd files directly.

Here's the code:
Sub Nik()
    ActivePage.Shapes(1).AddRow visSectionConnectionPts, 0, visTagCnnctPt
'    ActivePage.Shapes(1).AddNamedRow visSectionConnectionPts, "P0", visTagCnnctNamed
End Sub
#8
Programming & Code / Re: Testing row type, before t...
Last post by Nikolay - May 17, 2024, 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
#9
Programming & Code / Re: Testing row type, before t...
Last post by wapperdude - May 17, 2024, 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.
#10
Programming & Code / Re: Testing row type, before t...
Last post by Nikolay - May 17, 2024, 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: