Custom Shape Adjustment Event Handlers

Started by soulshined, September 18, 2017, 01:48:37 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

soulshined

I'm not asking anyone to code my project for me, (this disclaimer is because I'm used to stack overflow people), I just need someone to show me the right direction in setting shape adjustments in code.

For example, something similar to the arrow adjustment. You can drag and drop the yellow icon to make the arrow fatter more or less:


How do I do this with VBA, Drawing a line for example? Cant find anything juicy on MSDN

wapperdude

Since all of this can be done in the shapesheet, not sure the goal / desire for coding?

Wapperdude
Visio 2019 Pro

Yacine

Key is to unterstand that behind the GUI elements there are simple cells holding their values.
The "adjustment handle", actually a "control point" would be addressed as shp.cells("controls.row_1").formulaU = ..."
To discover all these cells, use the macro recorder and observe the code beeing generated when you modify the shape in the GUI.

You will also need to understand that the macro recorder handles specific shapes defined by their ID. Your code however will need to a strategy to recognize an arbitrary shape. There are many examples in the forum showing how to do this.

Note also that most of the formulas generated are in the form cellSRC. I prefer the direct address as shown above.
And last but not least a lot of unnecessary code is generated. Learn to recognize the important lines.

HTH,
Y.
Yacine

soulshined

Quote from: wapperdude on September 18, 2017, 02:06:11 AM
Since all of this can be done in the shapesheet, not sure the goal / desire for coding?

Wapperdude

The desire for this is simple. I'm creating a custom Ribbon Tab where a button simply drops a custom made shape (not a generic basic shape Microsoft offers) with adjustment points. I come from Excel, strictly for the last 4 years so relearning all the properties, lingo and event handlers is not easy IMO with the current MSDN setup. 

soulshined

Quote from: Yacine on September 18, 2017, 07:17:32 AM
Key is to unterstand that behind the GUI elements there are simple cells holding their values.
The "adjustment handle", actually a "control point" would be addressed as shp.cells("controls.row_1").formulaU = ..."
To discover all these cells, use the macro recorder and observe the code beeing generated when you modify the shape in the GUI.

You will also need to understand that the macro recorder handles specific shapes defined by their ID. Your code however will need to a strategy to recognize an arbitrary shape. There are many examples in the forum showing how to do this.

Note also that most of the formulas generated are in the form cellSRC. I prefer the direct address as shown above.
And last but not least a lot of unnecessary code is generated. Learn to recognize the important lines.

HTH,
Y.

Thanks, yeah Macro recorder was the first thing I went to. And I did a forum search, but didn't get any results because Excel calls them adjustments so I was searching for that. This is a great start though. Thank you. I'll recheck the forum

wapperdude

To clarify, you're looking to just drop a pre-defined shape, and not build and drop it?

Wapperdude
Visio 2019 Pro

soulshined

Quote from: wapperdude on September 18, 2017, 02:10:32 PM
To clarify, you're looking to just drop a pre-defined shape, and not build and drop it?

Wapperdude

Sorry, no. Definitely build and then drop it. Most of my shapes are custom polygons, or variations of. Unless there is an easier way to store a pre-built shape in a macro environment using Visio

wapperdude

#7
In my opinion, easier to store on a custom stencil. 

Build your shape in the usual "Visio" way, open a custom stencil, drag and drop your shape on the stencil, give the shape a unique name.  When completely done, save the stencil with unique name.  If this is going to be for distribution, you may want to clear the drawing page, and then save as a template.  That way, the stencil will travel with the file.  (Although, Hey Ken has a somewhat different approach...don't remember the link though, it's in the forum.)

So, before you save the template, you will want to add all your other "embellishments", including macros.  Here is typical VBA call to drop a decision shape onto the drawing.  It will need modification for your specific needs.

Note:  BASFLO_U.VSS is the stencil name,  and Decision is the shape name.



Sub Macro1()

    ActiveWindow.Page.Drop Application.Documents.Item("BASFLO_U.VSS").Masters.ItemU("Decision"), 3.875, 7.625

End Sub


Otherwise, to build on-the-fly, your macro becomes very detailed, needing to place each shape element in the precise locations, add the controls, etc. The steps that Yacine outlines would be very helpful, but I think on-the-fly is a nightmare approach.

HTH
Wapperdude
Visio 2019 Pro

soulshined

Quote from: wapperdude on September 18, 2017, 03:13:28 PM
In my opinion, easier to store on a custom stencil. 

Build your shape in the usual "Visio" way, open a custom stencil, drag and drop your shape on the stencil, give the shape a unique name.  When completely done, save the stencil with unique name.  If this is going to be for distribution, you may want to clear the drawing page, and then save as a template.  That way, the stencil will travel with the file.  (Although, Hey Ken has a somewhat different approach...don't remember the link though, it's in the forum.)

So, before you save the template, you will want to add all your other "embellishments", including macros.  Here is typical VBA call to drop a decision shape onto the drawing.  It will need modification for your specific needs.

Note:  BASFLO_U.VSS is the stencil name,  and Decision is the shape name.



Sub Macro1()

    ActiveWindow.Page.Drop Application.Documents.Item("BASFLO_U.VSS").Masters.ItemU("Decision"), 3.875, 7.625

End Sub


Otherwise, to build on-the-fly, your macro becomes very detailed, needing to place each shape element in the precise locations, add the controls, etc. The steps that Yacine outlines would be very helpful, but I think on-the-fly is a nightmare approach.

HTH
Wapperdude

Yes, this is exactly what I am going for. I agree with you, readable code makes easier life with VBA. Didn't know you could bring stencils with you as a template, until you layed it out the way you did. Thanks for all your help guys. I will play around with this method tonight and tomorrow and hopefully it all goes well. You guys are great

soulshined

Quote from: wapperdude on September 18, 2017, 03:13:28 PM
In my opinion, easier to store on a custom stencil. 

Build your shape in the usual "Visio" way, open a custom stencil, drag and drop your shape on the stencil, give the shape a unique name.  When completely done, save the stencil with unique name.  If this is going to be for distribution, you may want to clear the drawing page, and then save as a template.  That way, the stencil will travel with the file.  (Although, Hey Ken has a somewhat different approach...don't remember the link though, it's in the forum.)

So, before you save the template, you will want to add all your other "embellishments", including macros.  Here is typical VBA call to drop a decision shape onto the drawing.  It will need modification for your specific needs.

Note:  BASFLO_U.VSS is the stencil name,  and Decision is the shape name.



Sub Macro1()

    ActiveWindow.Page.Drop Application.Documents.Item("BASFLO_U.VSS").Masters.ItemU("Decision"), 3.875, 7.625

End Sub


Otherwise, to build on-the-fly, your macro becomes very detailed, needing to place each shape element in the precise locations, add the controls, etc. The steps that Yacine outlines would be very helpful, but I think on-the-fly is a nightmare approach.

HTH
Wapperdude


This is all working great thank you. Stencils are the way to go. However, Im running into locking the controls max/min x origins.

For example, how do I stop the control from going to -10 past the shapes left edge, and lock it to 0

wapperdude

Visio 2019 Pro