Main Menu

Recent posts

#1
Programming & Code / Re: Testing row type, before t...
Last post by Croc - Today at 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.
#2
Programming & Code / Re: Testing row type, before t...
Last post by wapperdude - Today at 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
#3
Programming & Code / Re: Testing row type, before t...
Last post by Nikolay - Today at 12:46:02 AM
I have absolutely no idea how to TEST it, but you could add using try-catch:

Sub AddConnectionPointRow(s As Shape)

  On Error GoTo IsNamed
  s.AddRow visSectionConnectionPts, 0, visTagCnnctPt
  GoTo Done

  IsNamed:
  s.AddRow visSectionConnectionPts, 0, visTagCnnctNamed

  Done:
End Sub

If it is C#

void AddConnectionPointRow(Shape s) {
  try {
    s.AddRow(VisSectionIndices.visSectionConnectionPts, 0, VisRowTags.visTagCnnctPt)
  } catch {
    s.AddRow(VisSectionIndices.visSectionConnectionPts, 0, VisRowTags.visTagCnnctNamed)
  }
}

Maybe the problem now would be clear for others to help.
If a "connection points" section is named, you can add only named rows to it.
If a "connection points" section is unnamed, you can add only unnamed rows to it.

What a weird behavior but anyway.
#4
Programming & Code / Re: Testing row type, before t...
Last post by dbramblett - May 15, 2024, 08:36:04 PM
@Surrogate @ wapperdude

I appreciate the responses, but I'm beginning to think I'm confused about the nature of this forum. This is a forum for discussing programming and code where visio is concerned, right? I'm not interested in a gui solution. I'm interested in a VBA or API solution.

The use case is, I want the code I've written to be able to explicitly tell me what the problem is if I try to add a VisTagCnnctPt row to a visSectionConnectionPts section that has already been flipped to VisTagCnnctNamed rows. Presently, it just tells me I can't use that row type. But that could mean I'm adding a row to the wrong section, or that I'm adding the wrong row type. I'd like the error to compare the current VisTag type associated with the section to the VisTag I'm trying to use. But I can only do that in all scenarios if I can obtain that information before looking at any rows.

Worst case, I can do something clunkier and simply try the VisTagCnnctNamed add if the VisTagCnnctPt add fails. But that is just an indirect reference, and doesn't scale very well.

Quote from: wapperdude on May 15, 2024, 06:53:18 PM2) if something has been deleted, how can you test it?  BTW, that's rhetorical.

Lol, I'd agree, except for one snag. As described above, I can't add a row of the wrong type even if there are no rows yet "determining that type". This means that the non-existent row, which you state I can't test, is in fact being tested somehow given the fact that I get an error stating that rowtag isn't allowed. I agree there isn't a row to test. I'm not suggesting that I test a non-existent row, I'm postulating that a value exists somewhere else that can be tested.
#5
Programming & Code / Re: Testing row type, before t...
Last post by wapperdude - May 15, 2024, 06:53:18 PM
Couple things.
1). You are referring to shapes, not stencils.  Those are not the same.  They are not interchangeable.

2) if something has been deleted, how can you test it?  BTW, that's rhetorical.  The real question, what is the usage context?  That is, are the connection points referred to by a name or merely row position, e.g., referenced in some code?  Is there a report that refers to them?  That would establish the row type.  If all you typically do is drag/glue a connector, the row type is unimportant.

3) if you have a standardized requirement, then you ought to know what the requirement is, and set the row type accordingly.  Standardized may also include placement order, location, and type.  Perhaps whether or not D-cell is used.  Much more than merely row type.

As Surrogate said, from GUI, Visio merely inserts unnamed row type, regardless of what was there before deletion.  That is the default method.
#6
Programming & Code / Re: Testing row type, before t...
Last post by Surrogate - May 15, 2024, 04:09:46 PM
Quote from: dbramblett on May 15, 2024, 03:02:08 PMWithout opening the shape sheet and manually adding a row to see what happens, how can I query the object and test for it?
IMHO No way! You cant define it without adding rows and check its type
#7
Programming & Code / Re: Testing row type, before t...
Last post by dbramblett - May 15, 2024, 03:02:08 PM
Quote from: Surrogate on May 15, 2024, 02:45:38 PMWhen you add connection points via User Interface these connection points are unnamed! If you make one of them as named point, it make all points as named...

Correct! But my question was, how do I test for it. I.E. Someone else creates a stencil, names the rows, but deletes them all. Then I get the stencil, and need to add rows. How do I determine via code that I need to add an indexed or named row?

Imagine I have dozens or hundreds of similar stencils which need a standard set of connection points added. Without opening the shape sheet and manually adding a row to see what happens, how can I query the object and test for it?

Shape.RowType(Section,Row) works, but only if there is already a row to check. The row index is not optional.
#8
Programming & Code / Re: Testing row type, before t...
Last post by Surrogate - May 15, 2024, 02:45:38 PM
When you add connection points via User Interface these connection points are unnamed! If you make one of them as named point, it make all points as named...
#9
Programming & Code / Testing row type, before their...
Last post by dbramblett - May 15, 2024, 02:10:17 PM
How does one test whether you should add a named row (VisTagCnnctNamed)or just a row (VisTagCnnctPt), if there are not any rows to test?

Shape.RowType(Section,Row) allows you to test the row type of an existing row. But if all the rows have been deleted or none have been added yet, there appears to be no way to determine what kind of row you then have to add.

You'd think that if there are no rows, you could add either type of row for the first row. But no, the operation is not allowed for this row type unless it matches the row type of the rows that don't exist yet. It must be a property found somewhere else, but I just can't seem to find it.
#10
Programming & Code / Re: Python ... again
Last post by Surrogate - May 15, 2024, 07:31:56 AM
Quote from: Yacine on May 14, 2024, 09:18:51 PMEnjoy you Honeymoon, and greetings from me and the whole Visguy core team to your wife.
Absolutely! Thomas my congratulations to you!!!
Quote from: Yacine on May 14, 2024, 09:18:51 PMPPPS - COM, absolutely!
I've made timid attempts to use Python in AutoCAD.