Author Topic: Custom Shape EventDrop Macro only work on Stencil?  (Read 13290 times)

0 Members and 1 Guest are viewing this topic.

hakayeazure

  • Newbie
  • *
  • Posts: 8
Custom Shape EventDrop Macro only work on Stencil?
« on: July 09, 2008, 04:40:55 AM »
Hi...

I have a problem creating custom shape using visio, could someone help me please.

I've develop a simple custom shape for testing:
1. I open a new stencil
2. and I add a new master named MyShape then I edit it
3. I put a rectangle shape, select it, and execute Window - Show ShapeSheet
4. On Events section, EventDrop cell, i enter =RUNMACRO("ThisDocument.ShowOption")
5. Using VB Edtior, Under ThisDocument module, I created a public subroutine named ShowOption which show a hello world message box


When I tried to create a new instance of MyShape in stencil page, a message box showing Hello World text appear, but, the problem is when I tried to create a new instance of MyShape into drawing page, nothing happen.

I've tried other ways, like changing EventDrop value into:
=RUNMACRO("Stencil2.ThisDocument.ShowOption")
=RUNADDON("ThisDocument.ShowOption")
=RUNADDON("Stencil2.ThisDocument.ShowOption")
combination of +SETF("EventDrop",0)
place the subroutine into a module.

None working!



If possible, I'd like to create a custom shape which its shape can be determine using an option form which appear on instantiation, such as an option asking how many side the shape has, enter 3 - wooop a triangle, enter 4 - wooop a rectangle etc.

Lars-Erik

  • Sr. Member
  • ****
  • Posts: 278
Re: Custom Shape EventDrop Macro only work on Stencil?
« Reply #1 on: July 09, 2008, 04:54:45 AM »
Here's a working version of your "test"

hakayeazure

  • Newbie
  • *
  • Posts: 8
Re: Custom Shape EventDrop Macro only work on Stencil?
« Reply #2 on: July 09, 2008, 05:39:55 AM »
Wow, thats was quick answer, thanks Lars-Erik.

Mmm... how can I use your Smart Shape other than inside Test.vsd?

Maybe I can save it as a template document... But how can I use it over an existing document? or how can I use it like any other shapes? (like Basic Shapes in Block Diagram which can be inserted into any drawing page, or how to copy Smart Shape into My Shapes --> Favorites)

Thanks a lot.

Lars-Erik

  • Sr. Member
  • ****
  • Posts: 278
Re: Custom Shape EventDrop Macro only work on Stencil?
« Reply #3 on: July 09, 2008, 06:08:34 AM »
The easiest way to copy the shape to one of your own documents would be to drop it on a page, copy it, and then paste it into you own document. Then you can just drag it into a stencil or do with it like anything else.
Ofcourse it will require the macro in the document i attached to be copied aswell.

If you want to make one of your own shapes do this you should do the following:
1-Create a macro in the "ThisDocument" section

Code
Public sub Dropped()
msgbox("Hello World")
End sub

2- Open your shape's shape sheet.
3- find the OnDrop event
4- Make it: =RUNMACRO("ThisDocument.Dropped")
5- Drop the shape to a page and watch it run the macro

That should do the trick.

- Lars

hakayeazure

  • Newbie
  • *
  • Posts: 8
Re: Custom Shape EventDrop Macro only work on Stencil?
« Reply #4 on: July 09, 2008, 06:47:47 AM »
Thanks again for the explanation...

I'd like to create a custom shape when I drop it onto the drawing page a form appear asking how many field there would be, lets say I put number 5 in it, then my custom shape will show 1 rectangle to type in the table name and 5 rectangles to type in fields name.

I think it would be a handfull if I'm asking for the macro so that custom shape below fully working  ;D unless it already developed!

So, maybe just let me know if it is possible to develop or not...

and again thanks for your help, I really appreciate it.  ;)

NB. My purpose is to create a database relationship diagram like we use to using Microsoft Access Database, kind of neat  ;D

hakayeazure

  • Newbie
  • *
  • Posts: 8
Re: Custom Shape EventDrop Macro only work on Stencil?
« Reply #5 on: July 09, 2008, 06:58:34 AM »
Forgot to attach the picture  ;D



Lars-Erik

  • Sr. Member
  • ****
  • Posts: 278
Re: Custom Shape EventDrop Macro only work on Stencil?
« Reply #6 on: July 09, 2008, 07:02:52 AM »
Very much possible :)
Its a  nice project, and I have some time, I'll help you get started ;)
« Last Edit: July 09, 2008, 07:13:51 AM by Lars-Erik »

Lars-Erik

  • Sr. Member
  • ****
  • Posts: 278
Re: Custom Shape EventDrop Macro only work on Stencil?
« Reply #7 on: July 09, 2008, 08:10:22 AM »
Well this is a start:
It will give the user a form and it will draw the require shapes.

Some things you might still improve/look at:
- Some better catching of errors / invalid input (very basic atm)
- Group the shapes when they have been dropped
- Could rewrite some code so you drop the master "Title" and the RUNMACRO would call it, the other shapes would be automaticly dropped on the right location below it and grouped (that would be really nice)
- Change the masters so the shapes end up looking better ;)
- Have some basic text added to the shape on dropping, you could use the loop counter for that ( "Field"&N )

I don't know how well you know VBA, if you need help with certain parts dont hesitate to ask, and keep us in the loop how it works out.

- Lars
« Last Edit: July 09, 2008, 08:12:03 AM by Lars-Erik »

hakayeazure

  • Newbie
  • *
  • Posts: 8
Re: Custom Shape EventDrop Macro only work on Stencil?
« Reply #8 on: July 09, 2008, 08:41:11 AM »
Thanks,

I'm working on it...

And I promise I'll keep visguy posted  ;D

Regards
.hakaye.

Visio Guy

  • Administrator
  • Hero Member
  • *****
  • Posts: 1716
  • Smart Graphics for Visual People...n' Stuff
    • Visio Guy
Re: Custom Shape EventDrop Macro only work on Stencil?
« Reply #9 on: July 09, 2008, 08:45:37 AM »
Hi Guys,

I haven't checked the examples in detail, but one tip might come in handy...

For shapes like these, where you have a sub-shape "unit" that needs to be repeated, I try to put all intelligence regarding size and position into User-cells, and have these attributes key off of User.index.

The ultimate goal is to have the code simply duplicate a sub-shape, and increment User.index.

A simple example would be:

User.Index = 2

Height = GUARD( Sheet.5!Height - Height*User.Index )

Sometimes the Height formula gets blasted by the duplicate, so it helps to create user cells for those too. For example, make a User.height, then have the code automatically set Height = GUARD(User.Height). This simplifies your code, and the intricacies of what your code must do.

For articles, tips and free content, see the Visio Guy Website at http://www.visguy.com
Get my Visio Book! Using Microsoft Visio 2010

hakayeazure

  • Newbie
  • *
  • Posts: 8
Re: Custom Shape EventDrop Macro only work on Stencil?
« Reply #10 on: July 09, 2008, 06:08:20 PM »
Hi guys, thanks for all your help  ;)

I finally finish my first visio custom shape ;D thanks to Lars-Erik and Visio Guy.

Please check it up guys and I love to know if there is another way to do it...

When I finish this, I haven't read Visio Guy posting, kind of confuse on how to implement it either since I'm a 2 day visio newbie  ;D lot of visio terms that I dont know.

Thanks again guys! You have a great site here! Love it!

Regards,
.hakaye.

Lars-Erik

  • Sr. Member
  • ****
  • Posts: 278
Re: Custom Shape EventDrop Macro only work on Stencil?
« Reply #11 on: July 10, 2008, 12:00:26 AM »
Very nice! One more thing I'd like to say about it though :)

Maybe consider integrating a nice way to fill in the subshapes.
Perhaps add a custom property for each field added and link the fields so the custom property ends up in the field?
I don't know what a nice way of filling in the fields is... Atleast if you have Visio pro the custom property way you can link Excel to it.

- Lars

hakayeazure

  • Newbie
  • *
  • Posts: 8
Re: Custom Shape EventDrop Macro only work on Stencil?
« Reply #12 on: July 10, 2008, 12:50:12 AM »
No need to say it ;D I also feel that filling fields content is very inconvenient when I started to use it myself ;D

Also when actual field count changed, I need to redo the whole filling fields names process :'(

I'll posting it again after it been modified.

.hakaye.

Lars-Erik

  • Sr. Member
  • ****
  • Posts: 278
Re: Custom Shape EventDrop Macro only work on Stencil?
« Reply #13 on: July 10, 2008, 01:24:31 AM »
Heres some stuff I found:

- Dropping the shape, and pressing cancel will result in the shape being droped, and protected against deletion (Doh!)
- See if you can make it work with Visio 2007's theme function?

- Nice catching of the input value, 1000 is alot, but still only takes like 7 seconds. (depends on computer i suppose)
- 3,4 is a valid input, it rounds it off to 3 though. (just wondering if theres an easy way to catch this, can you check for integer? or just for numbers?)
« Last Edit: July 10, 2008, 01:26:31 AM by Lars-Erik »

hakayeazure

  • Newbie
  • *
  • Posts: 8
Re: Custom Shape EventDrop Macro only work on Stencil?
« Reply #14 on: July 10, 2008, 07:12:51 AM »
Thanks for the debugging and the suggestions ;D I appreciate it...

And here is the improved result  ;D


.hakaye.