VBA Project - Help Understanding the Process

VBA Project - Help Understanding the Process

eric.frissell26WKQ
Advocate Advocate
2,230 Views
11 Replies
Message 1 of 12

VBA Project - Help Understanding the Process

eric.frissell26WKQ
Advocate
Advocate

Hi guys, I was a Solidworks user of 10 years before taking a position where we exclusively use Inventor, and am working on bringing my VBA skills over.  While I miss how straightforward Solidworks is (from beginning to end), I imagine Inventor must be somewhat similar except with a few extra options.  My question is when starting a project, what is the difference between ApplicationProject, DocumentProject, UserProject, and when would you use each one?  Another question regarding ApplicationProject I have is the ApplicationProject (Default.ivb) in the header.  How is that designed to be used?  Are we just supposed to create new modules under ApplicationProject and each module is designed to be treated as a separate macro rather than each macro having it's own file?

 

Secondly I write a lot of code that gets shared amongst the users.  At the minute I haven't seen a good way of sharing VBA.  The process in SW was simply save the .swb to the vault and then it's immediately visible to all users and can be attached to the ribbon as a button.  Is there a way to do something similar with Inventor to easily share macros amongst users?

0 Likes
Accepted solutions (1)
2,231 Views
11 Replies
  • VBA
Replies (11)
Message 2 of 12

Ray_Feiler
Advisor
Advisor

You will get a better response over here.

https://forums.autodesk.com/t5/inventor-customization/bd-p/120


Product Design & Manufacturing Collection 2024
Sometimes you just need a good old reboot.
0 Likes
Message 3 of 12

jtylerbc
Mentor
Mentor

@eric.frissell26WKQ wrote:

My question is when starting a project, what is the difference between ApplicationProject, DocumentProject, UserProject, and when would you use each one?


 

ApplicationProject is the one to use.  DocumentProject embeds the code in the Inventor file.  It is rarely (if ever) used now, since that functionality is mostly replaced by iLogic rules.  There may be special exceptions, but mostly, if you find yourself thinking about using DocumentProject you should probably be writing that code in iLogic instead of VBA.

 

Are we just supposed to create new modules under ApplicationProject and each module is designed to be treated as a separate macro rather than each macro having it's own file?

 

Correct, which actually greatly simplifies the answer to your last question.

 


Secondly I write a lot of code that gets shared amongst the users.  At the minute I haven't seen a good way of sharing VBA.  The process in SW was simply save the .swb to the vault and then it's immediately visible to all users and can be attached to the ribbon as a button.  Is there a way to do something similar with Inventor to easily share macros amongst users?


 

Since all the modules are stored in a single .ivb file, it is very easy to distribute your macros to other users.  Just give them a copy of the .ivb file (along with the image files for custom icons, if you make any), and change their Application Options to reference your file instead of the default one.  There is no need to save out individual macros to share them.

0 Likes
Message 4 of 12

eric.frissell26WKQ
Advocate
Advocate

Thanks @jtylerbc, this may be a really simple question but how do you save a .ivb file under a different name than default.ivb?  Using save-as prompts the error "This command is not valid for the application or document projects."  My fear is that if I were to use the default.ivb file name it would create a lot of confusion amongst users trying to change between the same file name in different file locations.

0 Likes
Message 5 of 12

jtylerbc
Mentor
Mentor

I would just rename the file in Windows (with Inventor closed).  Then go into Application Options and change the "Default VBA Project" setting on the "File" tab to reference the new name.

0 Likes
Message 6 of 12

CadUser46
Collaborator
Collaborator

To expand on your last question i would not and do not email the default.ivb to users.  Assuming you're all in the same physical location (working from home is different), or at least have speedy enough access to the same server;

- I personally keep a master copy of the default.ivb which i work on so i always have write access.

- Tested code gets copied to the 'public' default.ivb on the network share.

- All users point their app options to the same network share so they inherit updates on next restart.

- Ensure network share has read only access to everyone except you.  Very occasionally you'll be prevented from overwriting this file by the first person who opened Inventor in any day, or the last person to leave theirs running.

- The same principle can be achieved in Vault, we just don't use it.

- Buttons are easy to add but it's usually better you also export the UserCustomization.xml file each time you want to add a new button, and you just tell them to import it.  Gives you control over layout and button mapping etc.

 

https://modthemachine.typepad.com/my_weblog/2016/02/creating-a-button-for-a-vba-macro.html


Did you find this reply helpful ? If so please use the Accept as Solution or Kudos button below.

---------------------------------------------------------------------------------------------------------------------------
Inventor 2010 Certified Professional
Currently using 2023 Pro
0 Likes
Message 7 of 12

eric.frissell26WKQ
Advocate
Advocate

@CadUser46  This is great information to have!  I'm not at the point yet where I'm worried about people touching the macros but more where I'm worried about actually distributing them to the group.

 

Currently I had to write up a work instructions and it's kind of frustrating because I imagined it would be so much easier.

As of now I have a few macros saved into one .ivb file in our vault, so our users have to run a get on the file, then open VBA editor, load the project, create modules under ApplicationProject, copy the code from the .ivb file modules, then paste it into the ApplicationProject module.  It's incredibly irritating because I want the application to just point to one file.  If I edit the code, the users can run a get on the file and it updates.  It should be that simple but I can't find out how to do it

0 Likes
Message 8 of 12

CadUser46
Collaborator
Collaborator
Accepted solution

Yes it sounds like you’ve got extra steps you don’t require. 

Why should they need to edit the application project? 
Just upload the new application project, have them pull it down and point their app options to that location. 

deploying the usercustomization file along with it (so they get two files) handles the buttons you’ve created if any. 

They do not need to copy paste modules. 

Personally I’d ditch the Vault and stick both files on a share. The permissions aren’t so much to prevent users editing (you can password protect the project in the IDE), it’s to make sure you can overwrite it. 

That way your works instruction has a one time path change in App Options and an occasional reimport of usercustomization.xml each time you add a new button (not all macros require buttons).  

I have literally dozens of macros, modules, forms, classes all in a single default.ivb. Users never edit the ivb. 

Sure it takes a wee minute to wrap your head round it buts it’s way easier than your describing. 


Did you find this reply helpful ? If so please use the Accept as Solution or Kudos button below.

---------------------------------------------------------------------------------------------------------------------------
Inventor 2010 Certified Professional
Currently using 2023 Pro
0 Likes
Message 9 of 12

eric.frissell26WKQ
Advocate
Advocate

How do you upload the new ApplicationProject?  I thought that was supposed to be handled by "Load Project" and any loaded project would stay in the application.  Just opened VBA editor and turns Inventor has removed the project that all the macros are in. 

 

I appreciate the help, I'm just really disappointed that Inventor doesn't have much information regarding loading macros, sharing macro's amongst a group, and it's not very straightforward.

0 Likes
Message 10 of 12

CadUser46
Collaborator
Collaborator

Sent you a pm

 

Only the project referenced in app options stays loaded after restart. 


Did you find this reply helpful ? If so please use the Accept as Solution or Kudos button below.

---------------------------------------------------------------------------------------------------------------------------
Inventor 2010 Certified Professional
Currently using 2023 Pro
0 Likes
Message 11 of 12

jtylerbc
Mentor
Mentor

@eric.frissell26WKQ wrote:

As of now I have a few macros saved into one .ivb file in our vault, so our users have to run a get on the file, then open VBA editor, load the project, create modules under ApplicationProject, copy the code from the .ivb file modules, then paste it into the ApplicationProject module.  It's incredibly irritating because I want the application to just point to one file.  If I edit the code, the users can run a get on the file and it updates.  It should be that simple but I can't find out how to do it


 

@CadUser46 may have already explained this to you in his PM, but I think you're overcomplicating this.  What you're describing that you want is already exactly what it does.

 

  1. Make one file with your macros in it (all modules and forms in the same file).  Rename that file to whatever you want (I typically use the software version, Ex. "Macros 2020").
  2. In Inventor's Application Options, set the Default VBA Project to use that file.
  3. Distribute that file to other users however you choose to do so, and set their Application Options to point to it.

 

The actual distribution can be done several different ways:

  • Manually copying and pasting.
  • Batch file
  • Vault "Get"
  • Shared location on a network drive (everyone points to the same copy).

 

There is no need to copy modules to each user's ApplicationProject.  There is also no need to tell Inventor to load the project each time.  Depending on how you do the file naming, there is likely no need for the individual users to do anything when you make a change, other than possibly restarting Inventor.

0 Likes
Message 12 of 12

eric.frissell26WKQ
Advocate
Advocate

Thanks JTyler, it was setting the default macro in the Application Options that I was missing.  Thanks for your help!

0 Likes