Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

VBA - Load a Project from inside of Inventors Default.ivb

31 REPLIES 31
Reply
Message 1 of 32
Anonymous
1173 Views, 31 Replies

VBA - Load a Project from inside of Inventors Default.ivb

Hi
I am looking for the function for loading a project inside of the
default.ivb.
Every time a user starts up Inventor I want it to load a bunch of
projects.
This way they will be exposed to the user by either pressing Alt-F8 or
picking the menu Tools->Macro->Macros...

I do not want to have to put all my code into the Default.idv so it will
be
available to the user. I might want some code locked down at the module
level.

I typed this code but it does not work.
Where am I going wrong?


Public Sub Load_Module()
Dim AppPath as Object
set AppPath = "C:\Mypath\MyVBProgram.ivb"
VBA.Load(AppPath)
End Sub

Thank You
Dan Davison
31 REPLIES 31
Message 2 of 32
Anonymous
in reply to: Anonymous

Try something like this

Thisapplication.VBAProjects.Open "C:\Mypath\MyVBProgram.ivb"

--
Kent Keller
Autodesk Discussion Forum Facilitator


"Daniel Davison" wrote in message
news:5006169@discussion.autodesk.com...



Public Sub Load_Module()
Dim AppPath as Object
set AppPath = "C:\Mypath\MyVBProgram.ivb"
VBA.Load(AppPath)
End Sub

Thank You
Dan Davison
Message 3 of 32
bkline1
in reply to: Anonymous

I completed something similar to what you are looking for. My actual working applications are saved out on our network, the only thing in my default.ivb file is the attached code. The code loads my application "myapplication.ivb" file. The second part of the code fires a user form with in the newly loaded "myapplication.ivb" file. Any new applications that I create, I create them within the "myapplication.ivb" file on the network and change my initial user form to accommodate the new application. I'm sorry, I would attach visual images to clarify this but I'm afraid this would not be in the best interests of the company I work for. This is my code (modified for content):

Option Explicit
Public Sub LoadComponents()
Dim oIvVBAProjects As Inventor.InventorVBAProjects
Set oIvVBAProjects = ThisApplication.VBAProjects

Dim i As Integer
For i = 1 To ThisApplication.VBAProjects.Count
Dim cc As Object
Set cc = ThisApplication.VBAProjects.Item(i)
If cc.Name = "myapplication" Then
Exit For
End If
Next

'this part of the code checks to see if my myapplication is already loaded

If Not cc.Name = "myapplication" then

oIvVBAProjects.Open ("path to the location of the saved myapplication.ivb file")

RunComponents (this runs a specific module within the myapplication.ivb file loaded previously

Else

'runs the "RunComponents" subroutine when the application is found to have already been loaded
'starting the "RunComponents" UI.
RunComponents

End If

Set oIvVBAProjects = Nothing
Set cc = Nothing

End Sub

Private Sub RunComponents()

'this sets a reference to the current application VBAProjects
Dim oIvVBAProjects As Inventor.InventorVBAProjects
Set oIvVBAProjects = ThisApplication.VBAProjects

'this starts the loop to check to see if the RunComponents
'application is already loaded
Dim j As Integer
For j = 1 To ThisApplication.VBAProjects.Count

'this sets the variable "dd" to the references encountered in the
'loop being represented as "j"
Dim dd As Object
Set dd = ThisApplication.VBAProjects.Item(j)

'this statment checks to see if myapplication is already
'loaded or not
If dd.Name = "myapplication" Then
Exit For
End If
Next

'this sets an object reference to all of the applications in the active window
Dim oIvVBAComps As InventorVBAComponents
Set oIvVBAComps = oIvVBAProjects.Item(j).InventorVBAComponents

'this sets a reference to the vbamembers detected in the loop
Dim oIvVBAMembers As InventorVBAMembers
Set oIvVBAMembers = oIvVBAComps.Item("myapplication").InventorVBAMembers

'this sets a reference to the specific vbamember being looked for
Dim oIvVBAMember As InventorVBAMember
Set oIvVBAMember = oIvVBAMembers.Item("RunComponents")

'this exicutes the specific vbamember after it has been found
oIvVBAMember.Execute

'this unloads all the set variables
Set oIvVBAProjects = Nothing
Set oIvVBAComps = Nothing
Set oIvVBAMembers = Nothing
Set oIvVBAMember = Nothing

End Sub
Message 4 of 32
matthijs.van.lunsen
in reply to: Anonymous

This seems to be the thing I am looking for. I too want a "simple" macro which directs the user to other, more complicated projects. But when I insert the published piece of code, I encounter a run-time error with this line:
Set oIvVBAMembers = oIvVBAComps.Item("myapplication").InventorVBAMembers
Subscript out of range.

What do I have done wrong, I copied it one on one.

Matthijs van Lunsen
Tebulo Engineering, Holland
Message 5 of 32
bkline1
in reply to: Anonymous

Matthijs,

Just to cover some basics. I used "myapplication" as a fictitious application name, anywhere in the code you come across "myapplication", the code need changed to call your application name... For example...

The name of your application--- RunApp

in every line of code that states "myapplication" replace it with "RunApp"

If cc.Name = "myapplication" Then

replace with
If cc.Name = "RunApp" Then

If Not cc.Name = "myapplication" then

replace with
If Not cc.Name = "RunApp" then

If you do have the name properly replaced with your application name. check to make sure your application is in the correct location and make sure it is spelled properly... Try this, if it doesn't work for you post your code so that we can have a look...

Post how it turns out...
Bill
Message 6 of 32
matthijs.van.lunsen
in reply to: Anonymous

Bill, thanks for your reply.

I have covered the basics. What if have done is as follows:
I copied your code (both Public Sub LoadComponents() and Private Sub RunComponents()) in the Inventor Default.ivb. I have changed the link to the ivb file I want to open with inside the macro I want to run (oIvVBAProjects.Open ("path to the location of the saved myapplication.ivb file")). I replaced every "myapplication" by my own application name and the file I am referring to exists on the specified location.
But it still doesn't work correctly, a run time error appears by the following line of code:
Set oIvVBAComps = oIvVBAProjects.Item(j).InventorVBAComponents

Depending on the application I want to open the error message changes, but always at the same line.

My (your) code:

Option Explicit

Public Sub LoadComponents()
Dim oIvVBAProjects As Inventor.InventorVBAProjects
Set oIvVBAProjects = ThisApplication.VBAProjects

Dim i As Integer
For i = 1 To ThisApplication.VBAProjects.Count
Dim cc As Object
Set cc = ThisApplication.VBAProjects.Item(i)
If cc.Name = "Test_Case" Then
Exit For
End If
Next

'this part of the code checks to see if my myapplication is already loaded
If Not cc.Name = "Test_Case" Then
oIvVBAProjects.Open ("I:\Inventor Support\Property manager\Test.ivb")
RunComponents 'this runs a specific module within the myapplication.ivb file loaded previously
Else
'runs the "RunComponents" subroutine when the application is found to have already been loaded
'starting the "RunComponents" UI.
RunComponents
End If

Set oIvVBAProjects = Nothing
Set cc = Nothing

End Sub

Private Sub RunComponents()

'this sets a reference to the current application VBAProjects
Dim oIvVBAProjects As Inventor.InventorVBAProjects
Set oIvVBAProjects = ThisApplication.VBAProjects

'this starts the loop to check to see if the RunComponents application is already loaded
Dim j As Integer
For j = 1 To ThisApplication.VBAProjects.Count

'this sets the variable "dd" to the references encountered in the loop being represented as "j"
Dim dd As Object
Set dd = ThisApplication.VBAProjects.Item(j)

'this statment checks to see if myapplication is already loaded or not
If dd.Name = "Test_Case" Then
Exit For
End If
Next

'this sets an object reference to all of the applications in the active window
Dim oIvVBAComps As InventorVBAComponents
Set oIvVBAComps = oIvVBAProjects.Item(j).InventorVBAComponents

'this sets a reference to the vbamembers detected in the loop
Dim oIvVBAMembers As InventorVBAMembers
Set oIvVBAMembers = oIvVBAComps.Item("myapplication").InventorVBAMembers

'this sets a reference to the specific vbamember being looked for
Dim oIvVBAMember As InventorVBAMember
Set oIvVBAMember = oIvVBAMembers.Item("RunComponents")

'this exicutes the specific vbamember after it has been found
oIvVBAMember.Execute

'this unloads all the set variables
Set oIvVBAProjects = Nothing
Set oIvVBAComps = Nothing
Set oIvVBAMembers = Nothing
Set oIvVBAMember = Nothing

End Sub
Message 7 of 32
bkline1
in reply to: Anonymous

mvlunsen,

What is happening is after the first part of the code loads the *.ivb file it is trying to go on to run an application. To show you what I mean do the following. In your "Test.ivb" file on your network create another module within it call it "Test_Case_1"

Inside the "Test_Case_1" module type this code:

Public Sub Testing()

frmUserFormTesting.show

End Sub

also while in the same "Test.ivb" create a userform and call it "frmUserFormTesting". Close the file, export it and place it on the network. (at your specified location). Now, what I do is close IV all together and start over... Open IV, start up the Visual Basic environment. Open the Module in the default *.ivb file. Starting at the first line of code use F8 to step thru the code. I've re-attached your/my code that I modified to pick up the new module and the new user form.


Option Explicit

Public Sub LoadComponents()
Dim oIvVBAProjects As Inventor.InventorVBAProjects
Set oIvVBAProjects = ThisApplication.VBAProjects

Dim i As Integer
For i = 1 To ThisApplication.VBAProjects.Count
Dim cc As Object
Set cc = ThisApplication.VBAProjects.Item(i)
If cc.Name = "Test_Case" Then
Exit For
End If
Next

'this part of the code checks to see if my myapplication is already loaded
If Not cc.Name = "Test_Case" Then
oIvVBAProjects.Open ("O:\drafting\Inventor Projects\Standard Inventor Parts\VBA Part Path Location\VBA Application For Robinson Inventor\Test Case.ivb")
RunComponents 'this runs a specific module within the myapplication.ivb file loaded previously
Else
'runs the "RunComponents" subroutine when the application is found to have already been loaded
'starting the "RunComponents" UI.
RunComponents
End If

Set oIvVBAProjects = Nothing
Set cc = Nothing

End Sub

Private Sub RunComponents()

'this sets a reference to the current application VBAProjects
Dim oIvVBAProjects As Inventor.InventorVBAProjects
Set oIvVBAProjects = ThisApplication.VBAProjects

'this starts the loop to check to see if the RunComponents application is already loaded
Dim j As Integer
For j = 1 To ThisApplication.VBAProjects.Count

'this sets the variable "dd" to the references encountered in the loop being represented as "j"
Dim dd As Object
Set dd = ThisApplication.VBAProjects.Item(j)

'this statment checks to see if myapplication is already loaded or not
If dd.Name = "Test" Then
Exit For
End If
Next

'this sets an object reference to all of the applications in the active window
Dim oIvVBAComps As InventorVBAComponents
Set oIvVBAComps = oIvVBAProjects.Item(j).InventorVBAComponents

'this sets a reference to the vbamembers detected in the loop
Dim oIvVBAMembers As InventorVBAMembers
Set oIvVBAMembers = oIvVBAComps.Item("Test_Case_1").InventorVBAMembers

'this sets a reference to the specific vbamember being looked for
Dim oIvVBAMember As InventorVBAMember
Set oIvVBAMember = oIvVBAMembers.Item("Testing")

'this exicutes the specific vbamember after it has been found
oIvVBAMember.Execute

'this unloads all the set variables
Set oIvVBAProjects = Nothing
Set oIvVBAComps = Nothing
Set oIvVBAMembers = Nothing
Set oIvVBAMember = Nothing

End Sub
Message 8 of 32
matthijs.van.lunsen
in reply to: Anonymous

I have finally got the problem,
My major screw-up lies in the naming of my module and public sub. My module was still named module1 instead of Test_Case, and my sub was called Test_Case. On top of that I didn't correctly refer to them in my default.ivb.
The only problem I have still got is that my Test.ivb is reloading every single time, but that's a problem I should manage.

Bill, thanks for your advice.
P.S. Your code was still a bit off. Looks like I am not the only one making mistakes with coping 😉
Message 9 of 32
bkline1
in reply to: Anonymous

Not a problem, this is the first time I really tried to help someone else (due to not feeling knowledgeable enough). I now have a real respect for those, on this board who are able and willing to continually help others due to how difficult it is to explain. My loading does not reload every time due to the checking loop in the code, I would imagine the problem lies there somewhere. (renaming something).

Good Luck
Bill
Message 10 of 32
matthijs.van.lunsen
in reply to: Anonymous

Well hole-in-one I would say.
Furthermore know the feeling. I have had answered a lot of questions, but I don't feel knowledgeable enough to answer someone else's.
The reloading problem is solved. Like I said it was a problem of correctly referring the projects, modules and code.

Thanks again.
Matthijs
Message 11 of 32
Anonymous
in reply to: Anonymous

Hi Bill,
It has been a while and I don't expect this mesg would reach you. However,
it you do then here is my question:
I run your code on my computer and got problem as Matt had.
I'm not sure if you already came up with something to solve this problem.
Thanks
By the way, what the Test_Case_1 and testing sub do with the error for this
case.

wrote in message news:5073838@discussion.autodesk.com...
Matthijs,

Just to cover some basics. I used "myapplication" as a fictitious
application name, anywhere in the code you come across "myapplication", the
code need changed to call your application name... For example...

The name of your application--- RunApp

in every line of code that states "myapplication" replace it with "RunApp"

If cc.Name = "myapplication" Then

replace with
If cc.Name = "RunApp" Then

If Not cc.Name = "myapplication" then

replace with
If Not cc.Name = "RunApp" then

If you do have the name properly replaced with your application name. check
to make sure your application is in the correct location and make sure it is
spelled properly... Try this, if it doesn't work for you post your code so
that we can have a look...

Post how it turns out...
Bill
Message 12 of 32
matthijs.van.lunsen
in reply to: Anonymous

Chris,
The solution Bill gave was a bit confusing because he probably did it a bit hasty. When you do a bit digging in the code, the solution is not so hard to find. The only problem is that we used name which looked a bit to similar.
Here is the working code, for a new macro. Just fill in your names.

Good luck, Matthijs

Option Explicit

Public Sub LoadPM()

Dim oIvVBAProjects As Inventor.InventorVBAProjects
Set oIvVBAProjects = ThisApplication.VBAProjects

Dim FileLocation As String
FileLocation = "Yourdrive:\Yourfilelocation\yourfilename.ivb"

Dim i As Integer
For i = 1 To ThisApplication.VBAProjects.Count
Dim cc As Object
Set cc = ThisApplication.VBAProjects.Item(i)
If cc.Name = "UserProject1" Then ' <===== Name of the project
Exit For
End If
Next

' this part of the code checks to see if my UserProject1 is already loaded
If Not cc.Name = "UserProject1" Then
oIvVBAProjects.Open (FileLocation) ' Location of the project
RunComponents ' this runs a specific module within the LoadPM.ivb file loaded previously
Else
RunComponents
End If

Set oIvVBAProjects = Nothing
Set cc = Nothing

End Sub

Private Sub RunComponents()

' this sets a reference to the current application VBAProjects
Dim oIvVBAProjects As Inventor.InventorVBAProjects
Set oIvVBAProjects = ThisApplication.VBAProjects

' this starts the loop to check to see if the RunComponents application is already loaded
Dim j As Integer
For j = 1 To ThisApplication.VBAProjects.Count
' this sets the variable "dd" to the references encountered in the loop being represented as "j"
Dim dd As Object
Set dd = ThisApplication.VBAProjects.Item(j)
' this statment checks to see if myapplication is already loaded or not
If dd.Name = "UserProject1" Then ' <===== Name of the project
Exit For
End If
Next

' this sets an object reference to all of the applications in the active window
Dim oIvVBAComps As InventorVBAComponents
Set oIvVBAComps = oIvVBAProjects.Item(j).InventorVBAComponents

' this sets a reference to the vbamembers detected in the loop
Dim oIvVBAMembers As InventorVBAMembers
Set oIvVBAMembers = oIvVBAComps.Item("Module1").InventorVBAMembers ' <===== Name of the module

' this sets a reference to the specific vbamember being looked for
Dim oIvVBAMember As InventorVBAMember
Set oIvVBAMember = oIvVBAMembers.Item("test") ' <===== Name of the Private sub

' this exicutes the specific vbamember after it has been found
oIvVBAMember.Execute

' this unloads all the set variables
Set oIvVBAProjects = Nothing
Set oIvVBAComps = Nothing
Set oIvVBAMembers = Nothing
Set oIvVBAMember = Nothing

End Sub
Message 13 of 32
Anonymous
in reply to: Anonymous

Thx for a quick response, Matt.
I'd give it a try and let you know the result.

wrote in message news:5086922@discussion.autodesk.com...
Chris,
The solution Bill gave was a bit confusing because he probably did it a bit
hasty. When you do a bit digging in the code, the solution is not so hard to
find. The only problem is that we used name which looked a bit to similar.
Here is the working code, for a new macro. Just fill in your names.

Good luck, Matthijs

Option Explicit

Public Sub LoadPM()

Dim oIvVBAProjects As Inventor.InventorVBAProjects
Set oIvVBAProjects = ThisApplication.VBAProjects

Dim FileLocation As String
FileLocation = "Yourdrive:\Yourfilelocation\yourfilename.ivb"

Dim i As Integer
For i = 1 To ThisApplication.VBAProjects.Count
Dim cc As Object
Set cc = ThisApplication.VBAProjects.Item(i)
If cc.Name = "UserProject1" Then ' <===== Name of the project
Exit For
End If
Next

' this part of the code checks to see if my UserProject1 is already loaded
If Not cc.Name = "UserProject1" Then
oIvVBAProjects.Open (FileLocation) ' Location of the project
RunComponents ' this runs a specific module within the LoadPM.ivb file
loaded previously
Else
RunComponents
End If

Set oIvVBAProjects = Nothing
Set cc = Nothing

End Sub

Private Sub RunComponents()

' this sets a reference to the current application VBAProjects
Dim oIvVBAProjects As Inventor.InventorVBAProjects
Set oIvVBAProjects = ThisApplication.VBAProjects

' this starts the loop to check to see if the RunComponents application is
already loaded
Dim j As Integer
For j = 1 To ThisApplication.VBAProjects.Count
' this sets the variable "dd" to the references encountered in the loop
being represented as "j"
Dim dd As Object
Set dd = ThisApplication.VBAProjects.Item(j)
' this statment checks to see if myapplication is already loaded or not
If dd.Name = "UserProject1" Then ' <===== Name of the project
Exit For
End If
Next

' this sets an object reference to all of the applications in the active
window
Dim oIvVBAComps As InventorVBAComponents
Set oIvVBAComps = oIvVBAProjects.Item(j).InventorVBAComponents

' this sets a reference to the vbamembers detected in the loop
Dim oIvVBAMembers As InventorVBAMembers
Set oIvVBAMembers = oIvVBAComps.Item("Module1").InventorVBAMembers '
<===== Name of the module

' this sets a reference to the specific vbamember being looked for
Dim oIvVBAMember As InventorVBAMember
Set oIvVBAMember = oIvVBAMembers.Item("test") ' <===== Name of the
Private sub

' this exicutes the specific vbamember after it has been found
oIvVBAMember.Execute

' this unloads all the set variables
Set oIvVBAProjects = Nothing
Set oIvVBAComps = Nothing
Set oIvVBAMembers = Nothing
Set oIvVBAMember = Nothing

End Sub
Message 14 of 32
Anonymous
in reply to: Anonymous

I read over your code and it's much better to understand.
I have couple of questions: what is the private sub "Test"?
Thx

wrote in message news:5086922@discussion.autodesk.com...
Chris,
The solution Bill gave was a bit confusing because he probably did it a bit
hasty. When you do a bit digging in the code, the solution is not so hard to
find. The only problem is that we used name which looked a bit to similar.
Here is the working code, for a new macro. Just fill in your names.

Good luck, Matthijs

Option Explicit

Public Sub LoadPM()

Dim oIvVBAProjects As Inventor.InventorVBAProjects
Set oIvVBAProjects = ThisApplication.VBAProjects

Dim FileLocation As String
FileLocation = "Yourdrive:\Yourfilelocation\yourfilename.ivb"

Dim i As Integer
For i = 1 To ThisApplication.VBAProjects.Count
Dim cc As Object
Set cc = ThisApplication.VBAProjects.Item(i)
If cc.Name = "UserProject1" Then ' <===== Name of the project
Exit For
End If
Next

' this part of the code checks to see if my UserProject1 is already loaded
If Not cc.Name = "UserProject1" Then
oIvVBAProjects.Open (FileLocation) ' Location of the project
RunComponents ' this runs a specific module within the LoadPM.ivb file
loaded previously
Else
RunComponents
End If

Set oIvVBAProjects = Nothing
Set cc = Nothing

End Sub

Private Sub RunComponents()

' this sets a reference to the current application VBAProjects
Dim oIvVBAProjects As Inventor.InventorVBAProjects
Set oIvVBAProjects = ThisApplication.VBAProjects

' this starts the loop to check to see if the RunComponents application is
already loaded
Dim j As Integer
For j = 1 To ThisApplication.VBAProjects.Count
' this sets the variable "dd" to the references encountered in the loop
being represented as "j"
Dim dd As Object
Set dd = ThisApplication.VBAProjects.Item(j)
' this statment checks to see if myapplication is already loaded or not
If dd.Name = "UserProject1" Then ' <===== Name of the project
Exit For
End If
Next

' this sets an object reference to all of the applications in the active
window
Dim oIvVBAComps As InventorVBAComponents
Set oIvVBAComps = oIvVBAProjects.Item(j).InventorVBAComponents

' this sets a reference to the vbamembers detected in the loop
Dim oIvVBAMembers As InventorVBAMembers
Set oIvVBAMembers = oIvVBAComps.Item("Module1").InventorVBAMembers '
<===== Name of the module

' this sets a reference to the specific vbamember being looked for
Dim oIvVBAMember As InventorVBAMember
Set oIvVBAMember = oIvVBAMembers.Item("test") ' <===== Name of the
Private sub

' this exicutes the specific vbamember after it has been found
oIvVBAMember.Execute

' this unloads all the set variables
Set oIvVBAProjects = Nothing
Set oIvVBAComps = Nothing
Set oIvVBAMembers = Nothing
Set oIvVBAMember = Nothing

End Sub
Message 15 of 32
Anonymous
in reply to: Anonymous

Here is my situation:
I have a ivb file (say Mydefault.ivb) including 15 modules - one of them
named Master. I used this Master module to call the others. Of course there
are 15 forms associated with these 15 modules. Now I use Mydefault as IV's
default.ivb.
in your code, what is "module1" and "test"
Thx
wrote in message news:5086922@discussion.autodesk.com...
Chris,
The solution Bill gave was a bit confusing because he probably did it a bit
hasty. When you do a bit digging in the code, the solution is not so hard to
find. The only problem is that we used name which looked a bit to similar.
Here is the working code, for a new macro. Just fill in your names.

Good luck, Matthijs

Option Explicit

Public Sub LoadPM()

Dim oIvVBAProjects As Inventor.InventorVBAProjects
Set oIvVBAProjects = ThisApplication.VBAProjects

Dim FileLocation As String
FileLocation = "Yourdrive:\Yourfilelocation\yourfilename.ivb"

Dim i As Integer
For i = 1 To ThisApplication.VBAProjects.Count
Dim cc As Object
Set cc = ThisApplication.VBAProjects.Item(i)
If cc.Name = "UserProject1" Then ' <===== Name of the project
Exit For
End If
Next

' this part of the code checks to see if my UserProject1 is already loaded
If Not cc.Name = "UserProject1" Then
oIvVBAProjects.Open (FileLocation) ' Location of the project
RunComponents ' this runs a specific module within the LoadPM.ivb file
loaded previously
Else
RunComponents
End If

Set oIvVBAProjects = Nothing
Set cc = Nothing

End Sub

Private Sub RunComponents()

' this sets a reference to the current application VBAProjects
Dim oIvVBAProjects As Inventor.InventorVBAProjects
Set oIvVBAProjects = ThisApplication.VBAProjects

' this starts the loop to check to see if the RunComponents application is
already loaded
Dim j As Integer
For j = 1 To ThisApplication.VBAProjects.Count
' this sets the variable "dd" to the references encountered in the loop
being represented as "j"
Dim dd As Object
Set dd = ThisApplication.VBAProjects.Item(j)
' this statment checks to see if myapplication is already loaded or not
If dd.Name = "UserProject1" Then ' <===== Name of the project
Exit For
End If
Next

' this sets an object reference to all of the applications in the active
window
Dim oIvVBAComps As InventorVBAComponents
Set oIvVBAComps = oIvVBAProjects.Item(j).InventorVBAComponents

' this sets a reference to the vbamembers detected in the loop
Dim oIvVBAMembers As InventorVBAMembers
Set oIvVBAMembers = oIvVBAComps.Item("Module1").InventorVBAMembers '
<===== Name of the module

' this sets a reference to the specific vbamember being looked for
Dim oIvVBAMember As InventorVBAMember
Set oIvVBAMember = oIvVBAMembers.Item("test") ' <===== Name of the
Private sub

' this exicutes the specific vbamember after it has been found
oIvVBAMember.Execute

' this unloads all the set variables
Set oIvVBAProjects = Nothing
Set oIvVBAComps = Nothing
Set oIvVBAMembers = Nothing
Set oIvVBAMember = Nothing

End Sub
Message 16 of 32
bkline1
in reply to: Anonymous

Chris,

In my application, I have the code automatically open the userform that I intend to use. The end result of my code is that I want a userform to pop up so that I can input information into a userform to manipulate my model. To fire a userform you need a module within a VBA application with the appropriate code. So to automate it (and not have to hit alt+F8 to find the userform that I want to run) I have the code do it for me. To sum up all this, the basic flow of the code goes...

1. check this application to see if the specified VBA application is loaded. If it is then go on if not load it.

2. Once loaded. check the newly loaded VBA application for a module by the name of "Test". When found, fire the "Test" module. The "Test" module has simple code in it to fire a user form that is also inside of the newly loaded VBA application.

Example of code in "Test"

Public Sub FireMyUserForm()

'loads the specified User form
frmManipulateInventorModel.Show vbModeless

End Sub

So If this is what you are looking to do. Simply save a userform in your VBA application called frmManipulateInventorModel (you do not need anything in or on the form for a trial run). Have a module named "Test" with the above mentioned code and run your load VBA application. If done right all you should see is the userform pop-up...

Good Luck
Bill
Message 17 of 32
Anonymous
in reply to: Anonymous

Hi Matt,
Your "Test" is exactly what I have in my Master Module. Just wondering what
is your "module1" ???
and one more problem: when I close and open IV, it won't automatically load
MyDefault.ivb
Thx


bkline> wrote in message news:5087093@discussion.autodesk.com...
Chris,

In my application, I have the code automatically open the userform that I
intend to use. The end result of my code is that I want a userform to pop up
so that I can input information into a userform to manipulate my model. To
fire a userform you need a module within a VBA application with the
appropriate code. So to automate it (and not have to hit alt+F8 to find the
userform that I want to run) I have the code do it for me. To sum up all
this, the basic flow of the code goes...

1. check this application to see if the specified VBA application is loaded.
If it is then go on if not load it.

2. Once loaded. check the newly loaded VBA application for a module by the
name of "Test". When found, fire the "Test" module. The "Test" module has
simple code in it to fire a user form that is also inside of the newly
loaded VBA application.

Example of code in "Test"

Public Sub FireMyUserForm()

'loads the specified User form
frmManipulateInventorModel.Show vbModeless

End Sub

So If this is what you are looking to do. Simply save a userform in your VBA
application called frmManipulateInventorModel (you do not need anything in
or on the form for a trial run). Have a module named "Test" with the above
mentioned code and run your load VBA application. If done right all you
should see is the userform pop-up...

Good Luck
Bill
Message 18 of 32
bkline1
in reply to: Anonymous

Chris,

In my code "module1" is the name of the module I am gaining access to. "test" is the name of the Sub within the Module. To reel this all in, what I would do is create a userform (call it "MasterUserForm") that your master module fires alone... on that userform use command buttons (yours would have 15 or as many as you want) to fire the other userforms. See a screen shot of my userform (attached). My personal application loads this form, from here, I pick a command button associated with what I want to manipulate (I pictorially illustrated my command buttons). Once picked the command button fires an additional userform that is more specific to the item chosen... So in your case, you would replace "module1" with "Master" and test with "MasterUserForm". In setting your code up this way you are better streamlining the flow of information. In my case I have other users that do not understand many things associated with IV. So in an attempt to make IV more user friendly I have made it almost remedial...

Let me know how it turns out...

Bill
Message 19 of 32
bkline1
in reply to: Anonymous

Chris,

Sorry... Forgot attachment...

Bill
Message 20 of 32
Anonymous
in reply to: Anonymous

Thx for you help, Bill.
What I did with MyDefault is exactly what you described here.
Everthing works fine . The only problem is: when I open and close IV, I
still have to run LoadPM manually (Alt + F8)
Anyway, IV can load it automatically???
Thanks.


wrote in message news:5087209@discussion.autodesk.com...
Chris,

In my code "module1" is the name of the module I am gaining access to.
"test" is the name of the Sub within the Module. To reel this all in, what I
would do is create a userform (call it "MasterUserForm") that your master
module fires alone... on that userform use command buttons (yours would have
15 or as many as you want) to fire the other userforms. See a screen shot of
my userform (attached). My personal application loads this form, from here,
I pick a command button associated with what I want to manipulate (I
pictorially illustrated my command buttons). Once picked the command button
fires an additional userform that is more specific to the item chosen... So
in your case, you would replace "module1" with "Master" and test with
"MasterUserForm". In setting your code up this way you are better
streamlining the flow of information. In my case I have other users that do
not understand many things associated with IV. So in an attempt to make IV
more user friendly I have made it almost remedial...

Let me know how it turns out...

Bill

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report