Simple VBA question

Started by maclarkson, September 02, 2019, 10:20:28 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

maclarkson

Hi all,

I am a bit of a newb to programming.

I have a data field that is populated from an excelsheet called prop.objectname in the shapes sheet. Is there a way to update the shapes text with this value when the object is either linked to its data or the linked data is refreshed.

Many thanks in advanced

dpetrov

Hi mate,

if get this right, you want to populate diagram changes with information provided by excel (e.g. changing hostnames of device). If this is the case - you don't even need programming. One way of doing it is to use Shape data for device naming. So when you're to name a device, use the [field] (from Insert -> Field) and then use the hostname property from the shape data. This way as soon as you import the new table the shape name will change (you'll still have to have some unique indexes such as ShapeKey, etc).

Hope this makes sense and answers your question.

maclarkson

I know about inserting fields, but this is not what I need to do. I want to specifically change the shape text.

vojo


Nikolay

There is an option in my old BackSync extension to set shape text form shape data (also ShapeSheet formulas, if needed, like "PinX" or "Fill")
You could try if it still works :D


maclarkson

hay Nicolay,

I installed your addin a while ago and ts an excellent little adding. I would love to have a go at building something like that. would you be interested in starting up an open source project with me?

I am an Enterprise architect and I have using visio, Aris, Orbus, Mega and a whole heap of other tools. They are extremely expensive.

I have been working on a project to sync a database with visio in a similar fashion to Orbus and I would like to do something similar. The way these tools work is they are extremely simple. There are two tables. An object table and a relationships\connectors table. the connectors table just records all of the relationships between objects using a unique ID.

Here is the scenario for MVP:
1) I start a new diagram I can A) create objects from linked data (this can currently be achieved using the visio pro data connection functionality, if we create something different to do this potentially we can solve peoples problem of having to get a pro version of visio) or B) create new objects and these would be added to the database (this i currently cannot do)
2) I would then connect up the objects, and the connections would automatically be synchronised to the database.

Stretch goals:
1) ability to search the database for an object before adding it to a diagram
2) if the user created a connection in the database between two objects it would be good if i could take the two connected objects, throw them on to a page and then autoapply the connectors.
3) if a user tried to connect two objects up which had already been connected before the user would be prompted with a message
4) if a user tried to create an object that already was already existing it would prompt the user with a message

Would this be hard to do given your expertise?

Thanks

Mike


maclarkson

To my original question.

Can someone please please please just tell me whether it is possible to change the shape text to match up with the data from another Prop. field? and if so how?

maclarkson

Quote from: vojo on September 04, 2019, 11:58:31 AM
To show it...got to insert it

I actually want the text to be hidden as the text I will be simply holding a database unique id.

wapperdude

#8
There's a bit of confusion here.  An example would work wonders.  What do you mean "match up"?

The interpretation is that the prop.field is the text being displayed.  Hence, the insert > field responses. 

But it sounds like what your saying is that if prop.A = value A, then show shapetext = prop.value1, if prop.A = value B, then show prop.value2.

Is that what you're after?
Visio 2019 Pro

Nikolay

#9
Quote from: maclarkson on September 04, 2019, 01:24:57 PM
Can someone please please please just tell me whether it is possible to change the shape text to match up with the data from another Prop. field? and if so how?

It is possible only programmatically (shape.Text = "FOO"). For ShapeSheet formulas, shape text is available as read-only.
The mentioned extension does just that - populates the shape.Text propery from a given Prop. column (if this is enabled in the settings).

The extension is very basic; it relies on Visio data infrastructure.
It does not assume any automatic diagram generation from data actually, and I don't see any possibility for this in the scope of the extension.

maclarkson

The field name is Prop.objectid

The value of this id comes from the data that is supplied from an excel sheet. I basically want

shape.text=Prop.objectid

I then want the shape.text to be hidden and guarded from being changed.

wapperdude

Requires 3 steps.
1) as per Vojo, Insert>Field>Shape Data and pick your entry
2) to hide, open shapesheet, scroll to Misc Section, and set Hide Text = 1
3) to protect scroll to Protection section, set LockTextEdit = 1
4) to protect, scroll to Text Fields section, put guard wrapper around formula in Value cell.  Note, this section only appears after field insert of step1 was done.

That's it

Wapperdude
Visio 2019 Pro

maclarkson

I have written this piece of code which I use to record against the connector the objects connect from and to. At the moment it will give me the text name it came from and the text name it goes to. ShpFrom.text and shpTo.text, but I don't want the text I want the objectID (prop.objectID). Either i change the text on the object or I could directly access the ObjectID. How do I rewrite the code to do this?

Sub GetFlowchartConnections()
' Gets text from shapes connected at each end of every line on page
' Stores text in two shape data fields on each line

    Dim pg As Visio.Page
    Dim shp As Visio.shape
    Dim cnxEndPoints As Visio.Connects
    Dim EP As Visio.Connect
    Dim shpFrom As Visio.shape
    Dim shpTo As Visio.shape
   
    For Each pg In ActiveDocument.Pages
        For Each shp In pg.Shapes
            Call InitFromTo(shp)
           
            ' BeginX only exists if shape is a line
            If shp.CellExists("BeginX", False) Then
                'Get connects collection for current shape
                Set cnxEndPoints = shp.Connects
               
                If cnxEndPoints.Count > 0 Then
                    For i = 1 To cnxEndPoints.Count
                        Set EP = cnxEndPoints(i)
                        If EP.FromPart = visBegin Then
                            ' Get shape this end is attached to
                            Set shpFrom = EP.ToSheet
                            ' Store attached shape's text
                            shp.CellsU("Prop.From").FormulaU = Chr(34) & shpFrom.Text & Chr(34)
                        Else
                            ' Get shape this end is attached to
                            Set shpTo = EP.ToSheet
                            ' Store attached shape's text
                            shp.CellsU("Prop.To").FormulaU = Chr(34) & shpTo.Text & Chr(34)
                        End If
                    Next
                End If
            End If
        Next
    Next

End Sub

maclarkson

Actually this code came from one of these forums. I just altered it but I need to alter it a bit more.

wapperdude

Should be able to change shpFrom.Text to shpFrom.ID.  Same with the other variable.
Visio 2019 Pro