Using VB.Net 2008 with IV 11.

Using VB.Net 2008 with IV 11.

Anonymous
Not applicable
498 Views
16 Replies
Message 1 of 17

Using VB.Net 2008 with IV 11.

Anonymous
Not applicable
I am trying to create an add-in for inventor that calculates part weights, creates a custom iproperty for the weight, and does this everytime the part file is saved. I have found some code, but I can't seem to get it to work with IV 11 as there seems to be no wizard or working template to get VB express 2008 to recognize the inventor objects.
I am pretty new to this but this functionality would be quite valuable.
I have done some searching but havnt found anything close enough to what i'm trying to do to pull enough usefull information from it.
Any guides or help available that I am just not finding and someone can point me to?
0 Likes
499 Views
16 Replies
Replies (16)
Message 2 of 17

Anonymous
Not applicable
I found something just after i posted. I needed to add a reference to Autodesk Inventor Objects library. This seems to have made my code look like it will work. I am still in over my head though. Any help would still be appreciated.

I am following this guide here
http://modthemachine.typepad.com/my_weblog/2008/10/converting-vba-auto-macros-to-an-add-in.html
which is for IV 2009 and vb express 2008. I am using IV11 SP 4 and vb express 2008.

What i want it to do is - On save, check if document is a part file, if it is, then calculate the mass property. Create a custom iproperty called "weight" and set it equal to the mass value in lbs with 1 decimal place.
I had code for vb that worked as an automacro however i have found out it is bad news to have an automacro in every part file.
Here is the code that i have.
I dont know what silentoperation is for, but i presume it serves some purpose for this application.
I also am not sure if my document object is correct.
Here is the code.
#End Region

Private Sub m_appEvents_OnSaveDocument(ByVal DocumentObject As Inventor._Document, ByVal BeforeOrAfter As Inventor.EventTimingEnum, ByVal Context As Inventor.NameValueMap, ByRef HandlingCode As Inventor.HandlingCodeEnum) Handles m_appEvents.OnSaveDocument
If BeforeOrAfter = EventTimingEnum.kAfter Then
If DocumentObject.DocumentType = DocumentTypeEnum.kPartComponentDefinitionObject Then
' Get the filename minus the extension.
' Dim filename As String
' filename = DocumentObject.FullFileName
' filename = Left(filename, Len(filename) - 4)

' Save the current SilentOperation and then turn it on.
' This will suppress the dwf viewer from being displayed.
Dim currentSetting As Boolean
currentSetting = m_inventorApplication.SilentOperation
m_inventorApplication.SilentOperation = True

' Save the file as dwf.
'DocumentObject.SaveAs(filename & ".dwf", True)

' Save the file as pdf.
'DocumentObject.SaveAs(filename & ".pdf", True)

' Reset SilentOperation back to its previous value.
m_inventorApplication.SilentOperation = currentSetting
End If
End If
End Sub
End Class

All other code is taken verbatim from the guide. Edited by: travm on Jun 5, 2009 10:08 AM
0 Likes
Message 3 of 17

Anonymous
Not applicable


Brian Elkins has an excellent tutorial on modthemachine.typepad.com



I recently moved to Add-ins with VB.NET 2008 and the key is first install the template projects for VB.NET. However, since you are using an older version of IV, it won't come with templates for 2008. You could try downloading the 2010 SDK here:



http://usa.autodesk.com/adsk/servlet/index?siteID=123112&id=1079044



This comes with the template projects, but I don't know how it will work with an older version of Inventor.

0 Likes
Message 4 of 17

Anonymous
Not applicable
Yeah his article actually got me started trying to do this. Without it i wouldnt have even tried.
I am strugling with VB object names and other basic stuff too. sometimes the help is short on help, and huge on tables of data.
What exactly does silentoperation do?
0 Likes
Message 5 of 17

Anonymous
Not applicable
The SilentOperation basically stops IV from opening any secondary windows (such as error windows that might pop up). If you are doing stuff thru the API, often you'll not want the windows to appear and then just handle the error in your code.
0 Likes
Message 6 of 17

Anonymous
Not applicable
attached is a VB Express 2008 solution with one project "AutoProps". Check out the StandardAddInServer.vb file for the "guts" of this addin. This was made with the default Inventor Add-In template in VB.NET. I added an m_events variable to the addin class, then handled the OnSave event with the custom code. Enjoy!
0 Likes
Message 7 of 17

Anonymous
Not applicable
I can't seem to open that file. I can unzip it fine, but it doesnt open anything when i try to open it in VB Express.
0 Likes
Message 8 of 17

Anonymous
Not applicable
hmm, what did you try to open? Did you try opening the Autoprops.sln file? I included the whole solution. Please let me know if you get this to work, I'm interested in knowing how best to distribute the source for add-ins to others.
0 Likes
Message 9 of 17

Anonymous
Not applicable
I tried to open everything. It just left me at the start page every time.
I was able to open standardaddinserver.vb if i went directly to open file. But I am not sure how to use that properly if i cant open the project. It would appear to be "doing something" but it would not open at all.
0 Likes
Message 10 of 17

Anonymous
Not applicable
ok, I got it to open. It was opening, just not opening the required files.
I had to manually open the two vb files Assemblyinfo.vb and standardaddinserver.vb
When i got to debug the code i get the following error.

A project with an Output Type of Class Library cannot be started directly.
In order to edbug this project, add an executable project to this solution which references the library project. Set the executable project as the startup project.
0 Likes
Message 11 of 17

Anonymous
Not applicable


(silly question but) did you look in the Solution Explorer for files? I also have had this occur where I'll open the solution, but it still shows the start page. In the Solution Explorer, you can then open each file associated w/ the solution. I used the Express Edition to create these files, I don't know if this makes a difference. It would seem like you could open an Express solution with the full edition of VB.NET? Also, have you tried creating a new solution, then adding the existing project file?

0 Likes
Message 12 of 17

Anonymous
Not applicable


did you get the solution to open? AFAIK, you'll have to open the solution or import the project into a solution to get it to work.

0 Likes
Message 13 of 17

Anonymous
Not applicable
I got it to open, i had to manually open the files. The solution would open, it just didnt bring its files with it.
I had a problem with a reference to inventor.interop not being found.
I manually added a reference to Autodesk Inventor Objects Library, and removed the inventor.interop.
This allowed the project to build, however it does not appear in my add-ins list when i open inventor. Where did it go? Does it need the inventor.interop reference?
0 Likes
Message 14 of 17

Anonymous
Not applicable
"Autodesk Inventor Objects Library, and removed the inventor.interop"



Maybe this a the difference between IV11 and IV2010? Did the .dll build and is it in the bin folder? With VB.NET and 2010 the Add-in will automatically register itself (very nice). With IV11 maybe you have to register the add-in yourself? I think Brian's tutorial talked about this, but I don't know the specifics since I didn't have to do it 🙂
0 Likes
Message 15 of 17

Anonymous
Not applicable
maybe an expert (Sanjay or Brian) will chime in and give some pointers
0 Likes
Message 16 of 17

Anonymous
Not applicable
yep, i have some files in the bin folder,
AutoProps.dll
Interop.Inventor.dll
AutoProps.pdb
AutoProps.tlb
.xml

I will try messing around with registering the add-in manually. I expect it is something like that.
If that doesnt work hopefully an expert does chime in 🙂

Thanks for your help
0 Likes
Message 17 of 17

Anonymous
Not applicable
Anyone have some advice on how to register the add-in? Presently I havnt fully understood much of what I have done, but i did recieve some code, look it over, solve an error, and get it to build sucessfully. It does not seem to have been registered with IV 11 however.
0 Likes