Stencil button to access its shape data

Started by jik_ff, June 11, 2012, 06:20:33 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

jik_ff

Ok, expanding on my floor mapping project (seems as I add more to it, they ask for more features...)  They would like to add a quick printer install feature.  Meaning, on the floor map, I have a stencil for the printers.  This stencil has shape data corresponding to how the printer is set  up (IP, Server/share(s), location, Model, etc.).  What I am hoping to do is (since most printers here have at least 2 queues- PCL and PS) have a mesage box pop up when the printer is double clicked, and give them the options for which printer queue to install.  This would run the \\{server}\{printername} explorer command which (if it is not yet installed) would install the printer.  This is more for travelling staff.

In anycase, I'm hoping the code can be put to a sencil, so that each printer shape placed on the "map" would allow for this, reading off the shape data to make the text for the message box.

I hope that didn't sound more complex than it needed to, but as the subject says, I'm hoping to be able to make a stecil that when double clicked will execute code that will be able to see it's shape data.  I'm sure I can write the code for the message box, I am just a bit lost with the access of the shape data in a stencil.

Jumpy

Quote
Meaning, on the floor map, I have a stencil for the printers.

I don't understand, how you mean that. In my book a stencil is one of those "Shape-Librarys" normally on the left side of your workspace, where you can fetch shapes to drag and drop on your drawing.
Your sentence above sounds more like you're talking about a shape (not a stencil)?

In that case, you can place the formula "=DOCMD(1312)" in the Double-Click-Event-Cell of the ShapeSheet of a shape, to open the ShapeData-Dialog of that shape.

hth Jumpy

aledlund

Can code be placed into a stencil that is 'unique' to the shapes in that stencil, yes. The issue is that you will also have to put code into the 'master' drawing that is aware that it must 'reference' the stencil for those shapes.
al

jik_ff

Sorry Jumpy, that was not clear.  I have created a stencil.  I want the code in the stencil (meaning not having to code for each object instance of the stencil on the page).  I know about putting a stecil on the Document Stencil Shapes Stencil (the side bar thingie) and I know that making changes there also propgates those changes (for the most part that I have found) to the drawing pages.  I also know about the DOCMD(1312), but that is not what I want to do.  I need to reference the data there.  For example, For a given printer it has 2 queues (shape data: Queue1 and Queue2). The data would be stored as follows:
Queue1 = \\server1\printer_PCL
Queue2 = \\server1\pirnter_PS
I would need to reference these pieces of data in code, not display them.  The idea is to make hyperlink buttons on a messagebox.

Quote from: aledlund on June 12, 2012, 11:05:26 AM
Can code be placed into a stencil that is 'unique' to the shapes in that stencil, yes. The issue is that you will also have to put code into the 'master' drawing that is aware that it must 'reference' the stencil for those shapes.
al


Ok, that is my issue.  I don't know how to do that.  Well, ok, I think I know where to put the code in the master drawing, but how to reference the instance of the stencil?  Maybe I'm making this harder than it is...  But I am new to to Visio VB stuff.

jik_ff

#4
While waiting to see if anyone can follow what I am trying to do, I poked around google and found this :
http://jaqoup.wordpress.com/2009/08/28/manipulating-visio-shape-data-using-vba/

A bit more that what I am trying to do, though along the same track.  I don't need to manipulate the Prop shape data, just read it.  Also I don't need a generic one, I would prefere the code be read from/be attached to the stencil itself.  I know the shape data fields I need to access, since I created them.  I just don't know where to put the code or where to start.  Really, I am having trouble searching because I don't really know the syntax to use for this either.
----------------------------------
[edit 3:54pm EST]


I guess I should also add how I want this to work.  I would like to double click on the shape, a message box should pop up with 3 options:
1st would be the PCL Driver install (read from shape.Prop.Queue1)
2nd would be the PS Driver install (read from shape.Prop.Queue2)
3rd would be cancel

The driver install locations are stored in the Queue1 and Queue2 shape data for the stencil.  Sounds simple enough...  I'm ok with making the message box, it's just accessing the stencil data that is throwing me here.

Jumpy

OK, know I hopefully understand enough to help:

In every shape that needs the doubleclick functionality you have to go to the shapesheet.
In the Double-Click-Event cell in the Events section of the ShapeSheet enter the formula:
=Callthis("MyVBAModul.MyVBAMacro","NameOfMyStencil")
NameOfMyStencil is the name of the stencils, where you place the VBA code. It should naturrally be the stencil the shapes come from.
MyVBAModul is the name of the Modul you place your code in and MyVBAMacro is - who would have gussed - the name of the Macro.

The macro shoud look like:

Sub MyVBAMacro(shp as Visio.Shape)
  Dim q1 as String, q2 as String
  If shp.CellExists("Prop.Queue1",false) then
    q1 = shp.Cells("Prop.Queue1").ResultStr("")
  End If
  If shp.CellExists("Prop.Queue2",false) then
    q2 = shp.Cells("Prop.Queue2").ResultStr("")
  End If
 
  'Create you MessageBox here

  'Here simple Version
  Msgbox q1 & vbCrLf & q2 vbCrLf & "Cancel"
End Sub


If your "MessageBox" is a custom made Windows-Form it's code should be placed in a VBA Modul of the stencil, too.

hth Jumpy

jik_ff

I feel like I'm on the cusp of getting this to work...
Thanks Jumpy, you've added another piece to the puzzle, though I'm still having issues.  I was on the right track, but didn't know you needed to add the name of the stencil too.  OK, best to show what I have...
The Stencil name is PrinterObj.  The Shpaes List is called OfficeLocation (not sure if you need this).  The Module has the default name NewMacros.  Here is the VBA test code:
Sub PrinterInstallMacro(shp As Visio.Shape)
    Call MsgBox("Test", , "From Macro")
End Sub

Pretty much at this point I just need to see that the double click does something, so I am testing a simple text box.  I have edited the master's (the main shape group) ShapeSheet to have this as the code for Event DblClick:
=CALLTHIS("NewMacros.PrinterInstallMacro","PrinterObj")

But when I put an instance of the object on the page and double click on it, nothing happens (well sometimes it picks a subshape, but generally nothing).  What am I missing?

Jumpy

Where exactly did you place the VBA-Code. In the Modul "NewMacros", that's clear. But where is that modul? In which document? The drawing or the stencil? What do you mean by Shapes List?

hth Jumpy

jik_ff

I guess a picture is worth a 1000 words.  Here is a screen shot of what I got:


So on the left you see the sapes list with my vss(?) file with my 3 stencil Masters.  This is the Officelocation.vss that stores the stencils for this project.  NewMacros is the only module and that is where I put my code.

Jumpy

OK. Here's why I had difficulties to understand you from the start.

The "Shapes-List" on the left side as you call it (in this case OfficeLocation) is the stencil!
In official Visio-Speach "Shapes-List" = Stencil. Hence .vss: vs=visio s=stencil.

What you think of as "stencils" is in the official-speach "shapes" and so your "master-stencils" are "master-shapes". And mastershapes reside inside the stencil.

Then there is a visio drawing (.vsd d=drawing). Thats your "Project24Floor...".

Looking at the picture of the VBA-Editor, I can see, that your VBA-Macro is in the modul "NewMacros" as you said, but that modul belongs to the drawing, the .vsd.
It doesn't belong to a shape (what you think of as stencil), because shapes can't contain macros.

So to call the code via Callthis you can omit the documentname and simply use:
CALLTHIS("NewMacros.PrinterInstallMacro").

But what I would recommend is to create a new modul. You may call it NewMacros, too, but another name would be better. Create this modul in the VBA-area of the stencil OfficeLocation.
So the code "travells" with your shapes in the stencils, and when you open a new empty drawing, without VBA-code in it, the code in your stencil is still there and will work. You now have to call the macro via:
CALLTHIS("NewMacrosOrOtherName.PrinterInstallMacro","OfficeLocation").

I hope the communication-difficulties are solved with this rather lengthy explanation :-)
hth Jumpy

jik_ff

#10
No you gave me a good place to start.  syntax (including knowing what parts of the software are what) is very important.  Most of my visio knowledge is self taught.  Funny, my company wants me to do more of this, but they have yet to approve training what so ever...

that aside, thank you for clearing that stuff up.  Let me take a crack at this again now knowing what is what (for the most part).  I will edit this post in about 30 mins when I have a chance to test it all out.

[AFTER TESTING]
Awesome!  the test text box worked (though still got an instance of it selecting a sub object of the grouping, but I think I can fix that).  Thanks for clearing things up for me, I should be good from here.  I found a thread elsewhere that talks about itterating/checking through the object's shape data to find the stuff I need to look up (but I don't think I'll need it since I know the names, and this isn't code for a random object).  Should be good from here.

On one quick note,  There will most likely be one of these drawings for each of our 5 offices here in Ontario, and I will most likely be using this drawing as a template.  2 things to ask.  Does the vss stay with the drawing, or is it only on my computer here.  If so, I need this code to stay with the drawing itself as others may be manipulating it.   

Jumpy

That's right. If you create a template (as base for other drawings) you could/should place the code therein, so it's in every drawing that is based on that template. In that case you are independent from the stencil.
In some invironments/solutions it is advisible, to give away the template or drawings AND the stencil(s). In that case, when the template/drawing opens, it opens the stencil, too. There are some threads arround here, how that is done.

hth Jumpy