AnsweredAssumed Answered

SW coding best practices?

Question asked by perry leets on May 21, 2010
Latest reply on Jun 30, 2010 by chris misztur

I have been doing vba and .net for Autocad for quite awhile, and a little vba for SW.

This is my first real attempt at .net for SW and there is a bit of confusion. Right now I am

working on a fairly simple little addin that just adds a toolbar and menu (have'nt got to property pages

or task panes yet), there seems to be at least a couple of ways for doing the same task and I

wonder which is best.

Examples and documentation for coding in SW is a bit limited, furthermore, the "examples" found on

the SW website are obviously pretty old if not obsolete. Not much help there.


My first question, when connecting and disconnecting from SW, I am seeing it done via interface methods

and non-interface methods. i.e. "iSwApp = (ISldWorks)ThisSW" and  "SwApp = (SldWorks)ThisSW". I am

assuming using the interface methods is preferable, is this true? Are there cases where one type would be

selected over the other?


My next question, when adding menus and toolbars, I again see two distinct ways of doing so.

One way is to construct them using the Addmenu and AddmenuItem functions (plus AddToolbar & AddToolbarCommand).

I get the impression this is an older method, although I do like the control it affords.

The other way is to construct them using via the CommandManager->CommandGroup methods and specifying the "hasmenu"

and "hastoolbar" options.

Are one of these procedures better than another? Are there cases where one would work as desired and the other not?


Finally, I have attached my entire (small) project which utilizes both these menu construction procedures.

It works, more or less, but the tooltips do not appear and the menu callback functions are not being called.

I would much appreciate it if someone could take a look at it and tell me what I have done wrong here.