Author Topic: Display layer name in shape data (Total beginner)  (Read 4157 times)

0 Members and 1 Guest are viewing this topic.

bandylion

  • Newbie
  • *
  • Posts: 2
Display layer name in shape data (Total beginner)
« on: May 07, 2021, 05:29:52 AM »
Hi,

I'm pretty new to Visio and definitely new to Visual Basic, so please excuse any obvious mistakes.

My friend is building a house and I'm helping him with the electrical part. As someone who likes technical solutions and neat visuals, I wanted to create an "interactive" web page with the ability to highlight which sockets and light fixtures are on which circuit breaker. When I stumbled upon the SVGPublish Visio Extension and saw what it could do, I settled on using Visio.
So this is my first project and my first post.

I've managed to create the house plot and add custom shapes. Here is the current version: https://bartley.no/rubenhus/rubenhus.html
Sorry for everything being in norwegian on the page.

So, to the point:
I am going to create a layer for every circuit breaker in the house and then assign the sockets to the different layers. Currently, all of them are under the same layer, this will be changed.
Also, the sockets will only be assigned to a single layer.
The feature I'm looking for is to display the layer name in the Shape Data(Shape Properties on the web page). I thought this would be fairly simple, but either I'm not as good at googling as I thought or this isn't straightforward.
I was able to add LayerMember to the Shape Data but this only gives me the layer id, which by itself doesn't give me enough information.
What I want is the layer name to display in the shape data, and this should change if I assign the shape to a different layer.
It should look something like one of the two variants in the attached image.

I have read a few posts on this forum about similar things with Visual Basic, and some of the SDK documentation on Microsoft Build.
But Visual Basics doesn't seem basic enough for me. I have done some programming in Java, MATLAB and HTML but mostly just for fun.
I found some comforting words by Jumpy here on the forum:
Visio is often used by professionals, so it's hard to find beginner level stuff.
« Last Edit: May 07, 2021, 05:32:09 AM by bandylion »

Visisthebest

  • Sr. Member
  • ****
  • Posts: 376
Re: Display layer name in shape data (Total beginner)
« Reply #1 on: May 07, 2021, 06:49:01 AM »
Important to take some time to get your head around how Visual Basic works in Visio (the application is very different from Excel/Word that also use Visual Basic), but you’ll find it isn’t that complicated just don’t rush your learning process.
« Last Edit: May 07, 2021, 06:52:19 AM by Visisthebest »
Visio 2021 Professional

wapperdude

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3974
  • Ideas Visio-lized into solutions
Visio 2019 Pro

miless2111s

  • Jr. Member
  • **
  • Posts: 74
Re: Display layer name in shape data (Total beginner)
« Reply #3 on: May 11, 2021, 03:06:15 AM »
I can get you the layer reference number (but not the name so far)....
Select the drawing object
Open the ShapeSheet, in the User-defined cells in prop.row_2 enter "layer name" in the Label field and =layerMember in the value field.
Close the shapesheet
Select the drawing object and hit F2 followed by <CTRL> and <F9> to bring up the Field dialogue.
Chose Shape Data and then Layer Name and OK
Now the reference number of the layer is displayed in the drawing object.

After that it becomes harder to see how to bring the name into the mix (possible in various VBA extracts but I can't see a way to do this in the shape sheet at the moment).

HTH

Miles

bandylion

  • Newbie
  • *
  • Posts: 2
Re: Display layer name in shape data (Total beginner)
« Reply #4 on: May 11, 2021, 03:19:06 AM »
Hi, thanks for the replies!

Yesterday I managed to put this together:

Code
Private WithEvents vsoApplication As Visio.Application
 
Public Sub CellChanged_Example()
 
 Dim vsoShape As Visio.Shape
 
 Set vsoApplication = Application
 
End Sub
 
Private Sub vsoApplication_CellChanged(ByVal vsoCell As IVCell)
 
 Dim cellname As String
 Dim shp As Visio.Shape
 Dim vsoCell2 As Visio.Cell
 cellname = vsoCell.Name
 
 If StrComp(cellname, "LayerMember", 1) = 0 Then
    Set shp = ActivePage.Shapes(vsoCell.Shape.Name)
    If shp.CellExists("Prop.Layer", 1) Then
        shp.Cells("Prop.Layer.Value").Formula = """" + shp.Layer(1) + """"
    End If
 End If
End Sub

Might be a bit crude but it does the job. I might improve it a bit as well.
The first macro I wrote I had to run the macro every time, but with the CellChanged event I only need to run the macro when I start Visio.
Feel free to recommend improvements or give feedback both positive and negative.

Bork

  • Jr. Member
  • **
  • Posts: 25
Re: Display layer name in shape data (Total beginner)
« Reply #5 on: May 12, 2021, 02:16:53 PM »
Just a thought if your friend plans to use a paper version of the drawing.  By each electrical device on the drawing I put the number of the breaker in a label.  For example, I have 5 panels that I've lettered A to E.  So if an outlet is on breaker 22 of Panel B, I label it as B22.  Your friend could also put that number on the actual outlet.  Just remember to tell him to always verify that power is off with a test meter before working on a circuit.