Add a button

Add a button

Anonymous
Not applicable
1,024 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,025 Views
28 Replies
Replies (28)
Message 2 of 29

Anonymous
Not applicable
Never mind, Everyone. Nothing wrong with the code.
I opened control panel - add/remove program to remove the the old addin.
Made .dll again and run IV then I saw 2 buttons in the command bar
My question is: Every time making a modification to the code, do I have to

1) Go to Control Panel and remove the old addin
2) Uninstall the .exe file ( I used Inventor Addin Scrip builder from Mr.
Bliss)
3) Remake the .dll
4) Run the Scrip builder again
5) Lauch IV to see to the code working not not ????
Thx, Chris


"Chris (IV11 Pro. SP1 (uninstall)" wrote in message
news:5269010@discussion.autodesk.com...
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
Message 3 of 29

Anonymous
Not applicable
Sounds like you MIGHT have your VB6? project set to generate
a new UUID everytime it's compiled. I believe the correct option
for this is from the Project Properties dialog, Component tab,
Version Compatibility, make sure it's set to "Project Compatibility",
then be sure to specify your output dll file in the file box immediately
below the 3 option buttons.


Chris wrote:
0 Likes
Message 4 of 29

Anonymous
Not applicable
Yes, I have VB6 and the setup is exactly as what you describe
Seems like I have to go thru steps each time I modify the code
Chris

"Bob S." wrote in message
news:5269118@discussion.autodesk.com...
Sounds like you MIGHT have your VB6? project set to generate
a new UUID everytime it's compiled. I believe the correct option
for this is from the Project Properties dialog, Component tab,
Version Compatibility, make sure it's set to "Project Compatibility",
then be sure to specify your output dll file in the file box immediately
below the 3 option buttons.


Chris wrote:
0 Likes
Message 5 of 29

Anonymous
Not applicable
I have been just editing the code, compile it and save over the old dll. My edits seem to be there..
Wayne
0 Likes
Message 6 of 29

Anonymous
Not applicable
Are you running the .reg file after recompiling? I know I have
to do that, but that is all.

My steps:

Before compiling, exit Inventor.
Compile
Run .reg file
Run Inventor

Bob

Chris wrote:
0 Likes
Message 7 of 29

Anonymous
Not applicable
I have been just:

Before compiling, exit Inventor.
Compile
Run Inventor

Is this wrong?
0 Likes
Message 8 of 29

Anonymous
Not applicable
It is for me!

I need the following
Exit IV
Compile
Run reg file
Restart IV
0 Likes
Message 9 of 29

Anonymous
Not applicable
I use scrip builder from Mr. Bliss and skip runing reg file
just
Exit IV
make .dll.
Run scrip builder
restart IV

wrote in message news:5269295@discussion.autodesk.com...
It is for me!

I need the following
Exit IV
Compile
Run reg file
Restart IV
0 Likes
Message 10 of 29

Anonymous
Not applicable
What happened to:

1) Go to Control Panel and remove the old addin
2) Uninstall the .exe file ( I used Inventor Addin Scrip builder from Mr.
Bliss)
3) Remake the .dll
4) Run the Scrip builder again
5) Lauch IV to see to the code working not not ????
Thx, Chris

? If you are having to uninstall before using the script builder,
just try running the .reg file next time.

Bob S.

Chris wrote:
> I use scrip builder from Mr. Bliss and skip runing reg file
> just
> Exit IV
> make .dll.
> Run scrip builder
> restart IV
>
0 Likes
Message 11 of 29

Anonymous
Not applicable
I think the problem may be that your user-interface has already been created
so the FirstTime argument being passed into your add-in in the Activate
method is False. If your code is correct it should be checking this
argument and only creating your user-interface when this is True.

The idea is that the first time your add-in is loaded for a particular user,
your add-in creates its user-interface the way it wants. Inventor remembers
what has been created and restores it automatically for the next session.
This is done so that any edits to the user-interface that the end-user does
will be maintained. For example, let's say your add-in creates a new
toolbar with three buttons. The end-user might decide he doesn't want
another toolbar and decides to move those three buttons to the part panel
bar and delete your toolbar. That's ok because Inventor remembers these
changes and hooks up your ButtonDefinition objects to these button controls.

The problem with the approach we've decided to take is that it's a bit of a
pain for the developer when you're developing the user-interface portion of
your program. You're probably making changes frequently to the
user-interface and want that code to be executed each time. What I do is
just delete the portion of the registry where Inventor remembers which
add-ins have been loaded and what changes have been made to the
user-interface. By deleting this the next time you run Inventor it will
reset the user-interface to the default state and call all add-in's as if
its the first time they've been loaded.

The registry key is:

HKEY_CURRENT_USER\Software\Autodesk\Inventor\RegistryVersion11.0\UI
Customization V4

As always, be careful when deleting anything from the registry. When you
delete it make sure Inventor is not running.
--
Brian Ekins
Autodesk Inventor API
0 Likes
Message 12 of 29

Anonymous
Not applicable
Brian,
I am creating my very first addin. I did not try to move the icon around to
another IV toolbar or delete the new toolbar
I used scrip builder from Mr. Bliss to add and remove register file each
time I compile the .dll - it works great so far.
I still have trouble to load the .ico file and show it in IV
I tried SampleAddin (included with IV) many times and never got the 2 icons
shown up.

I replaced this line

Set oButtonDefPrimary =
oInventorApp.CommandManager.ControlDefinitions.AddButtonDefinition("Primary",
"Primary2", _
kQueryOnlyCmdType,
"{0E2365C9-C7A2-4304-9B1C-29285781218A}", "Primary", "Primary2")

With

Dim oPriIcon As IPictureDisp
Set oPriIcon = LoadPicture(App.Path & "\Primary.ico")

Set oButtonDefPrimary =
oInventorApp.CommandManager.ControlDefinitions.AddButtonDefinition("Primary",
"Primary2", _
kShapeEditCmdType,
"{DB59D9A7-EE4C-434A-BB5A-F93E8866E872}", "Primary", "Primary2", oPriIcon,
oPriIcon)

The first line works but the second one with Primary.ico doesn't

Thx, chris


"Brian Ekins (Autodesk)" wrote in message
news:5270971@discussion.autodesk.com...
I think the problem may be that your user-interface has already been created
so the FirstTime argument being passed into your add-in in the Activate
method is False. If your code is correct it should be checking this
argument and only creating your user-interface when this is True.

The idea is that the first time your add-in is loaded for a particular user,
your add-in creates its user-interface the way it wants. Inventor remembers
what has been created and restores it automatically for the next session.
This is done so that any edits to the user-interface that the end-user does
will be maintained. For example, let's say your add-in creates a new
toolbar with three buttons. The end-user might decide he doesn't want
another toolbar and decides to move those three buttons to the part panel
bar and delete your toolbar. That's ok because Inventor remembers these
changes and hooks up your ButtonDefinition objects to these button controls.

The problem with the approach we've decided to take is that it's a bit of a
pain for the developer when you're developing the user-interface portion of
your program. You're probably making changes frequently to the
user-interface and want that code to be executed each time. What I do is
just delete the portion of the registry where Inventor remembers which
add-ins have been loaded and what changes have been made to the
user-interface. By deleting this the next time you run Inventor it will
reset the user-interface to the default state and call all add-in's as if
its the first time they've been loaded.

The registry key is:

HKEY_CURRENT_USER\Software\Autodesk\Inventor\RegistryVersion11.0\UI
Customization V4

As always, be careful when deleting anything from the registry. When you
delete it make sure Inventor is not running.
--
Brian Ekins
Autodesk Inventor API
0 Likes
Message 13 of 29

Anonymous
Not applicable
Chris,

You should look into compiling the icon file into your addin by
putting it in a resource file (.res), then use LoadResPicture
instead of LoadPicture. Also make sure the icons are the right
size and format (256 color).

Bob

Chris wrote:
0 Likes
Message 14 of 29

Anonymous
Not applicable
Bob,
How you create a icon file? I've been using IconArt to create all my icons
and it works fine for all my VBA codes
Now I'm trying it in AddIn and it seems to have trouble
Chris

"Bob S." wrote in message
news:5271705@discussion.autodesk.com...
Chris,

You should look into compiling the icon file into your addin by
putting it in a resource file (.res), then use LoadResPicture
instead of LoadPicture. Also make sure the icons are the right
size and format (256 color).

Bob

Chris wrote:
0 Likes
Message 15 of 29

Anonymous
Not applicable
Chris,

In VB6, pick the Project Menu->Add New Resource File
to create an empty resource file, then from the Tools
menu you can access the Resource Editor. Or you can
create the resource file right from the Resource Editor.
From there you should be able to figure out how to add
the icons into the resource file, and the help for
LoadResPicture().

Bob

Chris wrote:
> Bob,
> How you create a icon file? I've been using IconArt to create all my icons
> and it works fine for all my VBA codes
> Now I'm trying it in AddIn and it seems to have trouble
> Chris
>
> "Bob S." wrote in message
> news:5271705@discussion.autodesk.com...
> Chris,
>
> You should look into compiling the icon file into your addin by
> putting it in a resource file (.res), then use LoadResPicture
> instead of LoadPicture. Also make sure the icons are the right
> size and format (256 color).
>
> Bob
>
> Chris wrote:
0 Likes
Message 16 of 29

Anonymous
Not applicable
The point I was trying to make is that it's likely that your code to create
the button is never being called because the FirstTime argument of the
Active method is False. If you've run your Add-In before then the FirstTime
will be False. Editing the user-interface has nothing to do with this,
except this is done so that editing of the user-interface behaves correctly.
Deleting the registry key will reset this so that FirstTime will return True
the next time your Add-In is loaded.
--
Brian Ekins
Autodesk Inventor API
0 Likes
Message 17 of 29

Anonymous
Not applicable
Brian,

I wasn't trying to take away from your registry tip, but just wanted to
add that I think storing the icons in a resource file that gets compiled
into the addin usually works better than trying to access one from disk.

Bob

Brian Ekins (Autodesk) wrote:
> The point I was trying to make is that it's likely that your code to create
> the button is never being called because the FirstTime argument of the
> Active method is False. If you've run your Add-In before then the FirstTime
> will be False. Editing the user-interface has nothing to do with this,
> except this is done so that editing of the user-interface behaves correctly.
> Deleting the registry key will reset this so that FirstTime will return True
> the next time your Add-In is loaded.
0 Likes
Message 18 of 29

Anonymous
Not applicable
I think I've done something very funny here. As a result, my help files are
disappeared.
Do you have any idea how to get it back
Thx, Chris

"Bob S." wrote in message
news:5271824@discussion.autodesk.com...
Chris,

In VB6, pick the Project Menu->Add New Resource File
to create an empty resource file, then from the Tools
menu you can access the Resource Editor. Or you can
create the resource file right from the Resource Editor.
From there you should be able to figure out how to add
the icons into the resource file, and the help for
LoadResPicture().

Bob

Chris wrote:
> Bob,
> How you create a icon file? I've been using IconArt to create all my icons
> and it works fine for all my VBA codes
> Now I'm trying it in AddIn and it seems to have trouble
> Chris
>
> "Bob S." wrote in message
> news:5271705@discussion.autodesk.com...
> Chris,
>
> You should look into compiling the icon file into your addin by
> putting it in a resource file (.res), then use LoadResPicture
> instead of LoadPicture. Also make sure the icons are the right
> size and format (256 color).
>
> Bob
>
> Chris wrote:
0 Likes
Message 19 of 29

Anonymous
Not applicable
You can probably access online help files at
http://msdn.microsoft.com or there are several good information
sites on the internet. Simply try a search on LoadResPicture
or VB6 Resource Files. For instance, my first item in Google
search was:

http://msdn.microsoft.com/library/en-us/vb98/html/vbmthLoadResPicture.asp?frame=true

Start there.

Bob

Chris wrote:
> I think I've done something very funny here. As a result, my help files are
> disappeared.
> Do you have any idea how to get it back
> Thx, Chris
>
> "Bob S." wrote in message
> news:5271824@discussion.autodesk.com...
> Chris,
>
0 Likes
Message 20 of 29

Anonymous
Not applicable
I understand Bob and I appreciate you taking time to provide help in this
newsgroup. It just seemed that Chris missed the point of that post and I
just wanted to clarify.
--
Brian Ekins
Autodesk Inventor API

"Bob S." wrote in message
news:5271909@discussion.autodesk.com...
Brian,

I wasn't trying to take away from your registry tip, but just wanted to
add that I think storing the icons in a resource file that gets compiled
into the addin usually works better than trying to access one from disk.

Bob

Brian Ekins (Autodesk) wrote:
> The point I was trying to make is that it's likely that your code to
> create
> the button is never being called because the FirstTime argument of the
> Active method is False. If you've run your Add-In before then the
> FirstTime
> will be False. Editing the user-interface has nothing to do with this,
> except this is done so that editing of the user-interface behaves
> correctly.
> Deleting the registry key will reset this so that FirstTime will return
> True
> the next time your Add-In is loaded.
0 Likes