Add a button

Add a button

Anonymous
Not applicable
1,031 Views
28 Replies
Message 1 of 29

Add a button

Anonymous
Not applicable
Hi all,
I used ScanDrawingViews addin as a template and add a extra button. The
program works fine, howver, the second button called oButtonDefPart is not
shown up in IV. Anyone please see the code
Thx, Chris

Implements ApplicationAddInServer

Private WithEvents oButtonDefScanDrawingViews As ButtonDefinition
Private WithEvents oButtonDefPart As ButtonDefinition '
*********************

Private oInventorApp As Inventor.Application

Private Sub ApplicationAddInServer_Activate(ByVal AddInSiteObject As
Inventor.ApplicationAddInSite, ByVal FirstTime As Boolean)

' Save a reference to the Application object.
Set oInventorApp = AddInSiteObject.Application

'create the button to create the text graphics
Set oButtonDefScanDrawingViews =
oInventorApp.CommandManager.ControlDefinitions.AddButtonDefinition("ScanDrawingViews",
_
"ScanDrawingViewsCmdIntName",
kQueryOnlyCmdType, "{0E2365C9-C7A2-4304-9B1C-29285781218A}", _
"Scan Drawing Views", "Scan Drawing
Views")
Set oButtonDefPart =
oInventorApp.CommandManager.ControlDefinitions.AddButtonDefinition("Part",
"Generate a Part", kQueryOnlyCmdType, _
"{0E2365C9-C7A2-4304-9B1C-29285781218A}", "Part",
"Generate a part")


'enable the button
oButtonDefScanDrawingViews.Enabled = True
oButtonDefPart.Enabled = True

'if AddIn is called first time, create toolbar and add button to toolbar
If FirstTime = True Then

'create a new toolbar
Dim oCommandBar As CommandBar
Set oCommandBar =
oInventorApp.UserInterfaceManager.CommandBars.Add("ScanDrawingViews",
"ScanDrawingViewsToolbarIntName", , _
"{0E2365C9-C7A2-4304-9B1C-29285781218A}")

'add the button to the toolbar
oCommandBar.Controls.AddButton oButtonDefScanDrawingViews
oCommandBar.Controls.AddButton oButtonDefPart

'make the toolbar visible
oCommandBar.Visible = True

End If

End Sub

--
IV11 Pro. sp1 (uninstall)
Window XP Pro sp2
Pentium 3.2 Ghz, 3.0 GB of RAM
NVIDIA FX 3400 84.26
SpacePilot V 1.1.2
0 Likes
1,032 Views
28 Replies
Replies (28)
Message 21 of 29

Anonymous
Not applicable
Brian,
I'm trying to follow along with everyone.. As I am trying to accomplish the same things as Chris. Attached is a pic of the "folder" in the registry. Are you suppose to delete this in order for Inventor to resume its default?
Thanks Wayne
0 Likes
Message 22 of 29

Anonymous
Not applicable
That's right. I know it seems like a lot, but if you delete this key
Inventor will create it again the next time you run it and the UI will be
reset back to the default state. As always, be careful when working in the
registry, but the key that you have highlighted is the correct one to
delete.
--
Brian Ekins
Autodesk Inventor API

wrote in message news:5271983@discussion.autodesk.com...
Brian,
I'm trying to follow along with everyone.. As I am trying to accomplish the
same things as Chris. Attached is a pic of the "folder" in the registry. Are
you suppose to delete this in order for Inventor to resume its default?
Thanks Wayne
0 Likes
Message 23 of 29

Anonymous
Not applicable
Ok, I did it....It worked.

I just get a little freaked out when messing with the registry. Just needed to make sure.

Thanks.
0 Likes
Message 24 of 29

Anonymous
Not applicable
Correct me if I'm wrong, but doing that will also delete all the other
UI customizations I have done, like adding macros to toolbars, etc?
Is there some more specific method I can use so I don't lose all those
macro buttons?

Bob

Brian Ekins (Autodesk) wrote:
> That's right. I know it seems like a lot, but if you delete this key
> Inventor will create it again the next time you run it and the UI will be
> reset back to the default state. As always, be careful when working in the
> registry, but the key that you have highlighted is the correct one to
> delete.
0 Likes
Message 25 of 29

Anonymous
Not applicable
Bob,
I think you'd better save your setup before trying anything which you're
unsure
Chris
"Bob S." wrote in message
news:5272097@discussion.autodesk.com...
Correct me if I'm wrong, but doing that will also delete all the other
UI customizations I have done, like adding macros to toolbars, etc?
Is there some more specific method I can use so I don't lose all those
macro buttons?

Bob

Brian Ekins (Autodesk) wrote:
> That's right. I know it seems like a lot, but if you delete this key
> Inventor will create it again the next time you run it and the UI will be
> reset back to the default state. As always, be careful when working in
> the
> registry, but the key that you have highlighted is the correct one to
> delete.
0 Likes
Message 26 of 29

Anonymous
Not applicable
You're correct. This will reset Inventor back to it's default state which
means that all UI customization that has been doen will be lost. In a
development environment this isn't typically a problem and is the easiest
solution to describe. If you want to limit the effect you can dig deeper
into the registery and change the value that Inventor uses to determine if
your Add-In has been loaded before or not.

There's a value in the same area of the registry that you can set that will
cause just the portion of the UI that's associated with your Add-In to be
reset. The attached image shows the registry editor open to this area. The
"Command Owner ID's" key has a list of all of the loaded Add-Ins. You'll
need to find the GUID that represents your Add-In. Under the key for your
Add-In are two values; "Has Initialized UI" and "Version". Change the value
of the "Version" value to anything other than its current value. When you
start Inventor it will reinitialize the Add-In's user-interface and call the
Add-In with FirstTime equal to True.

When you shutdown Inventor, Inventor will set this value back to it's
original value. Because of this you could create a small .reg file that
would change this value and then just run the reg file when you need to test
the Add-In's UI code.
--
Brian Ekins
Autodesk Inventor API

"Bob S." wrote in message
news:5272097@discussion.autodesk.com...
Correct me if I'm wrong, but doing that will also delete all the other
UI customizations I have done, like adding macros to toolbars, etc?
Is there some more specific method I can use so I don't lose all those
macro buttons?

Bob

Brian Ekins (Autodesk) wrote:
> That's right. I know it seems like a lot, but if you delete this key
> Inventor will create it again the next time you run it and the UI will be
> reset back to the default state. As always, be careful when working in
> the
> registry, but the key that you have highlighted is the correct one to
> delete.
0 Likes
Message 27 of 29

Anonymous
Not applicable
There's one other way to force the UI for your Add-In to be reinitialized.
I just looked at the programming help and saw that this in not currently
documented in it. You would typically use this option when you've made
changes in the Add-In's UI and want it to reinitialize when the end-user
intalls it on their system.

Below is an example of settings for the various registry values that you
have to supply as part of your Add-In's registration. All but the last one
are documented in the online help for Add-Ins. The version is used for your
Add-In to specify it's user-interface version.

"LoadOnStartUp"="1"
"Type"="Standard"
"SupportedSoftwareVersionGreaterThan"="10.."
"Version" = dword:1

Here are a couple of examples of how this can be used. Let's say there's a
first release of an Add-In (R1) that when installed creates a new toolbar
and adds three buttons to that toolbar. We'll call this version 1 of its
user-interface. For R2 of the Add-In they add additional functionality to
those existing three commands but don't need to add, or remove any buttons
on the toolbar so the version remains version 1 for this R2 release. This
is useful because if the end-user has made any changes to the UI these
changes will stay intact. For the R3 release of the Add-In they decide to
get rid of one of the commands and replace it with two new ones. In this
case they need to change the Inventor UI that's associated with them so
their version will be 2 for R3. When the Add-in is run for the first time
Inventor sees that it's a different version than what was run previously so
Inventor removes all existing UI associated with that Add-In and then calls
the Add-In with FirstTime equal to True so the Add-In can recreate their UI.

Hopefully this makes sense.

--
Brian Ekins
Autodesk Inventor API
0 Likes
Message 28 of 29

Anonymous
Not applicable
Hi Brian,
1) First, I want to make sure to understand your mesg completely before
trying it
Let say I start a brand new addin that when installed creates (1) toolbar
and (3) buttons. Then I include "Version"=dword:1 in the reg file. Later on,
I decide to add one more button and the toolbar for some reason is not shown
in the IV. If I change "Version"=dword:2 then I'd expect to see the toolbar
to appear again in IV?

2) Is "Version"=dword:1 a default in the reg file ? If not, how to set it
up in the existing addin which the toolbar was gone?

3) I tried "Version"=dword:1 in the reg file of an existing addin and run
it. Open IV and both toolbar and button (in customize/commands/Add-Ins)
were gone

I'll a little bit more and let you know ...

Thx, Chris

"Brian Ekins (Autodesk)" wrote in message
news:5272468@discussion.autodesk.com...
There's one other way to force the UI for your Add-In to be reinitialized.
I just looked at the programming help and saw that this in not currently
documented in it. You would typically use this option when you've made
changes in the Add-In's UI and want it to reinitialize when the end-user
intalls it on their system.

Below is an example of settings for the various registry values that you
have to supply as part of your Add-In's registration. All but the last one
are documented in the online help for Add-Ins. The version is used for your
Add-In to specify it's user-interface version.

"LoadOnStartUp"="1"
"Type"="Standard"
"SupportedSoftwareVersionGreaterThan"="10.."
"Version" = dword:1

Here are a couple of examples of how this can be used. Let's say there's a
first release of an Add-In (R1) that when installed creates a new toolbar
and adds three buttons to that toolbar. We'll call this version 1 of its
user-interface. For R2 of the Add-In they add additional functionality to
those existing three commands but don't need to add, or remove any buttons
on the toolbar so the version remains version 1 for this R2 release. This
is useful because if the end-user has made any changes to the UI these
changes will stay intact. For the R3 release of the Add-In they decide to
get rid of one of the commands and replace it with two new ones. In this
case they need to change the Inventor UI that's associated with them so
their version will be 2 for R3. When the Add-in is run for the first time
Inventor sees that it's a different version than what was run previously so
Inventor removes all existing UI associated with that Add-In and then calls
the Add-In with FirstTime equal to True so the Add-In can recreate their UI.

Hopefully this makes sense.

--
Brian Ekins
Autodesk Inventor API
0 Likes
Message 29 of 29

Anonymous
Not applicable
Here's the basic algorithm that Inventor uses when working with Add-Ins and
the UI.

1. Inventor looks for registered Add-Ins during start-up.
2. Inventor looks in the registry to see if it that Add-In has been loaded
before.
3. If the Add-In is new it activates the Add-In with the FirstTime argument
equal to True.
4. If the Add-In has been loaded before is compares the version number of
the Add-In last loaded and the version number of the current Add-In. If
they're
different, Inventor deletes all of the existing user-interface that the
Add-In created
and then activates the Add-In with the FirstTime argument equal to True.
If the
version numbers are the same the Add-In is activates with the FirstTime
argument
equal to False.

For the Add-In to behave correctly it should be creating the various
ControlDefinition
objects it uses every time it is activated. It needs to check the value of
the FirstTime
argument and only when it's True should it create and command bars or
controls.
--
Brian Ekins
Autodesk Inventor API
0 Likes