Community
Vault Forum
Welcome to Autodesk’s Vault Forums. Share your knowledge, ask questions, and explore popular Vault topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Code snippets Vault API

8 REPLIES 8
Reply
Message 1 of 9
psaarloos
1769 Views, 8 Replies

Code snippets Vault API

If somebody is willing to share some code snippets of document handling from within Inventor i appriciate it a lot. I can't get my active document connected to the document in the Vault. I can imagine i need some steps like

- check if the document is already in the Vault.
- Get the file.id of the document in the Vault
- Print the status in a msgbox, check out /in the document (for example)

i have a VB project with login script working, so i can get information out of the Vault, but not in combination with documents opened in Inventor.

Kind regards,
Pim Saarloos
Regards,
Pim Saarloos
Product Manager
If my post answers your question, please click the "Accept as Solution" button. Kudos are much appreciated!
8 REPLIES 8
Message 2 of 9
Anonymous
in reply to: psaarloos

Figuring out if a document is in the vault is pretty tricky.
See this thread for a discussion of the issues:
http://discussion.autodesk.com/thread.jspa?messageID=4933634

Regarding code. I have attached the checksum algorithm. You can use it to
get the checksum of a file on your local disk. Then call
FindFilePathsByNameAndChecksum to locate the file in Vault.

The code is in C#, but you can call it from your VB.NET code. You just need
to create a new C# project for it then reference it in your VB.NET project.

Other than the checksum code, I don't have any other samples for you.


Doug Redmond
Software Engineer, Autodesk Inc.
Message 3 of 9
psaarloos
in reply to: psaarloos

Thanks Doug....

I will give it a try with the checksum method, but i doesn't sound easy, as in the other thread you're refering to, another point is discussed. Mappings.... The only way to get that working, is like you said by making the mapping myself.

I would have thought that adding a reference to the VaultAddInLib would give a little exposure to the vault document, like getting variables as Filestatus, Document, etc... Can it not be used at all, or what else the library van be used for?

Kind regards,
Pim Saarloos
Regards,
Pim Saarloos
Product Manager
If my post answers your question, please click the "Accept as Solution" button. Kudos are much appreciated!
Message 4 of 9
Anonymous
in reply to: psaarloos

VaultAddInLib, I'm assuming this is the file that contains the Vault plug-in
for Inventor. There is no API for our Inventor plug-in. The only API we
have is the web service API which lets you communicate directly with the
Vault server. Referencing VaultAddInLib, to my knowledge, won't do anything
for your project.

Your problem is not unique. There are a lot of people writing
Inventor/Vault utilities who end up duplicating features within
VaultAddInLib. It would be nice if you could get at those features, but you
can't. And no, I don't know if that functionality will be available in
future releases.

The closest thing you can do is launch one of the Vault commands... I think.
I'm no expert on the Inventor API. For example, you could launch the check
out command, which would bring up the standard check-out window from
VaultAddInLib. You would need user input at that point, so it's not very
useful for batch operations.


Doug Redmond
Software Engineer, Autodesk Inc.
Message 5 of 9
radishj
in reply to: psaarloos

CheckSum stop working!

I copied the code from the zip file. I believe that it was working when we were using Vault 4 and Inventor 11. Now,we upgrade to Vault2008 and Inventor2008. The Checksum.CalcCRC32() returns wrong values on some files in our Vault.

Was it caused by our upgrading? Do you have a new version for 2008?

Thanks for your help.
Message 6 of 9
radishj
in reply to: psaarloos

Never mind! I loged into a different(wrong) Vault.

How do I delete this post?
Message 7 of 9
Allen_Gager
in reply to: psaarloos

Would you mind walking me thru the steps on how to create my c# project and reference it in my vb.net app?

I have not done any work with c# and my vb.net is still a little weak.

I have googled doing such, and I am still a little confused.

I'm using VS2005.

Thank you for any assistance you can provide.

-AllenG
Message 8 of 9
Anonymous
in reply to: psaarloos

Here is what you need to do...

1. Open your solution (.sln) file.
2. Under the menu, select File->Add->New Project
3. Create a Visual C# Class Library. For this example, I've named it
CSharpProject.
4. Now, in the Solution Explorer, you should see your original VB project
and your new C# project.
5. Copy and paste the code from Checksum.cs into Class1.cs. The code needs
to replace "public class Class1" and the 2 brackets underneith it.
6. At the top of Class1.cs, add the line "using System.IO;"
7. Rename Class1.cs if you want.
8. Do a build just to make sure that everything is working.
9. In the Solution Explorer, right click your VB project and select Add
Reference.
10. Go to the projects tab and select your C# project and click OK.
11. Now you should see your C# project listed under the References in your
VB project.
12. In the top of your .vb file, add the line "Imports CSharpProject" (or
whatever the name of your C# project is)
13. Now you can use the C# code in you VB program. Just call
Checksum.CalcCRC32( .. ) when you want to find the checksum.
14. In the Solution Explorer, right click your VB project and select Set as
Startup Project.
15. Build the solution.
16. Run and enjoy

If you look in your bin directory, you will notice that the C# project has
its own DLL. That DLL must be in the same directory as your EXE or else
your program will not work.


Doug Redmond
Software Engineer, Autodesk Inc.
Message 9 of 9
dajvid
in reply to: psaarloos

Hi,

 

With the help of http://converter.telerik.com/, I've converted Checksum.cs to Checksum.vb. I haven't tested this against the original Checksum.cs, so please perform your own validations on Checksum.vb.

 

Kind regards,

Dave.

Imports System.IO

Public Class Checksum

	' CRC check sum data
	'
	Private Const m_chunkSize As Integer = 16384
	Private Shared m_crc_32_tab As UInteger() =
	{
		&H0, &H77073096, &HEE0E612CUI, &H990951BAUI,
		&H76DC419, &H706AF48F, &HE963A535UI, &H9E6495A3UI,
		&HEDB8832, &H79DCB8A4, &HE0D5E91EUI, &H97D2D988UI,
		&H9B64C2B, &H7EB17CBD, &HE7B82D07UI, &H90BF1D91UI,
		&H1DB71064, &H6AB020F2, &HF3B97148UI, &H84BE41DEUI,
		&H1ADAD47D, &H6DDDE4EB, &HF4D4B551UI, &H83D385C7UI,
		&H136C9856, &H646BA8C0, &HFD62F97AUI, &H8A65C9ECUI,
		&H14015C4F, &H63066CD9, &HFA0F3D63UI, &H8D080DF5UI,
		&H3B6E20C8, &H4C69105E, &HD56041E4UI, &HA2677172UI,
		&H3C03E4D1, &H4B04D447, &HD20D85FDUI, &HA50AB56BUI,
		&H35B5A8FA, &H42B2986C, &HDBBBC9D6UI, &HACBCF940UI,
		&H32D86CE3, &H45DF5C75, &HDCD60DCFUI, &HABD13D59UI,
		&H26D930AC, &H51DE003A, &HC8D75180UI, &HBFD06116UI,
		&H21B4F4B5, &H56B3C423, &HCFBA9599UI, &HB8BDA50FUI,
		&H2802B89E, &H5F058808, &HC60CD9B2UI, &HB10BE924UI,
		&H2F6F7C87, &H58684C11, &HC1611DABUI, &HB6662D3DUI,
		&H76DC4190, &H1DB7106, &H98D220BCUI, &HEFD5102AUI,
		&H71B18589, &H6B6B51F, &H9FBFE4A5UI, &HE8B8D433UI,
		&H7807C9A2, &HF00F934, &H9609A88EUI, &HE10E9818UI,
		&H7F6A0DBB, &H86D3D2D, &H91646C97UI, &HE6635C01UI,
		&H6B6B51F4, &H1C6C6162, &H856530D8UI, &HF262004EUI,
		&H6C0695ED, &H1B01A57B, &H8208F4C1UI, &HF50FC457UI,
		&H65B0D9C6, &H12B7E950, &H8BBEB8EAUI, &HFCB9887CUI,
		&H62DD1DDF, &H15DA2D49, &H8CD37CF3UI, &HFBD44C65UI,
		&H4DB26158, &H3AB551CE, &HA3BC0074UI, &HD4BB30E2UI,
		&H4ADFA541, &H3DD895D7, &HA4D1C46DUI, &HD3D6F4FBUI,
		&H4369E96A, &H346ED9FC, &HAD678846UI, &HDA60B8D0UI,
		&H44042D73, &H33031DE5, &HAA0A4C5FUI, &HDD0D7CC9UI,
		&H5005713C, &H270241AA, &HBE0B1010UI, &HC90C2086UI,
		&H5768B525, &H206F85B3, &HB966D409UI, &HCE61E49FUI,
		&H5EDEF90E, &H29D9C998, &HB0D09822UI, &HC7D7A8B4UI,
		&H59B33D17, &H2EB40D81, &HB7BD5C3BUI, &HC0BA6CADUI,
		&HEDB88320UI, &H9ABFB3B6UI, &H3B6E20C, &H74B1D29A,
		&HEAD54739UI, &H9DD277AFUI, &H4DB2615, &H73DC1683,
		&HE3630B12UI, &H94643B84UI, &HD6D6A3E, &H7A6A5AA8,
		&HE40ECF0BUI, &H9309FF9DUI, &HA00AE27, &H7D079EB1,
		&HF00F9344UI, &H8708A3D2UI, &H1E01F268, &H6906C2FE,
		&HF762575DUI, &H806567CBUI, &H196C3671, &H6E6B06E7,
		&HFED41B76UI, &H89D32BE0UI, &H10DA7A5A, &H67DD4ACC,
		&HF9B9DF6FUI, &H8EBEEFF9UI, &H17B7BE43, &H60B08ED5,
		&HD6D6A3E8UI, &HA1D1937EUI, &H38D8C2C4, &H4FDFF252,
		&HD1BB67F1UI, &HA6BC5767UI, &H3FB506DD, &H48B2364B,
		&HD80D2BDAUI, &HAF0A1B4CUI, &H36034AF6, &H41047A60,
		&HDF60EFC3UI, &HA867DF55UI, &H316E8EEF, &H4669BE79,
		&HCB61B38CUI, &HBC66831AUI, &H256FD2A0, &H5268E236,
		&HCC0C7795UI, &HBB0B4703UI, &H220216B9, &H5505262F,
		&HC5BA3BBEUI, &HB2BD0B28UI, &H2BB45A92, &H5CB36A04,
		&HC2D7FFA7UI, &HB5D0CF31UI, &H2CD99E8B, &H5BDEAE1D,
		&H9B64C2B0UI, &HEC63F226UI, &H756AA39C, &H26D930A,
		&H9C0906A9UI, &HEB0E363FUI, &H72076785, &H5005713,
		&H95BF4A82UI, &HE2B87A14UI, &H7BB12BAE, &HCB61B38,
		&H92D28E9BUI, &HE5D5BE0DUI, &H7CDCEFB7, &HBDBDF21,
		&H86D3D2D4UI, &HF1D4E242UI, &H68DDB3F8, &H1FDA836E,
		&H81BE16CDUI, &HF6B9265BUI, &H6FB077E1, &H18B74777,
		&H88085AE6UI, &HFF0F6A70UI, &H66063BCA, &H11010B5C,
		&H8F659EFFUI, &HF862AE69UI, &H616BFFD3, &H166CCF45,
		&HA00AE278UI, &HD70DD2EEUI, &H4E048354, &H3903B3C2,
		&HA7672661UI, &HD06016F7UI, &H4969474D, &H3E6E77DB,
		&HAED16A4AUI, &HD9D65ADCUI, &H40DF0B66, &H37D83BF0,
		&HA9BCAE53UI, &HDEBB9EC5UI, &H47B2CF7F, &H30B5FFE9,
		&HBDBDF21CUI, &HCABAC28AUI, &H53B39330, &H24B4A3A6,
		&HBAD03605UI, &HCDD70693UI, &H54DE5729, &H23D967BF,
		&HB3667A2EUI, &HC4614AB8UI, &H5D681B02, &H2A6F2B94,
		&HB40BBE37UI, &HC30C8EA1UI, &H5A05DF1B, &H2D02EF8D
	}

	Public Shared Function CalcCRC32(filename As String) As Integer
		Using stream As New FileStream(filename, FileMode.Open, FileAccess.Read, FileShare.Read, m_chunkSize)
			Return CalcCRC32(stream)
		End Using
	End Function

	Public Shared Function CalcCRC32(stream As Stream) As Integer
		If stream Is Nothing Then
			Throw New Exception("Checksum.CalcCRC32() - Invalid stream")  'MSG0
		End If

		If Not stream.CanRead Then
			Throw New Exception("Checksum.CalcCRC32() - Cannot read stream")  'MSG0
		End If

		Dim crc32 As UInteger = &HFFFFFFFFUI

		stream.Position = 0	 ' beginning

		Dim bytesRead As Integer = 0
		Dim streamData As Byte() = New Byte(m_chunkSize - 1) {}
		Do
			bytesRead = stream.Read(streamData, 0, m_chunkSize)

			For i As Integer = 0 To bytesRead - 1
				crc32 = (m_crc_32_tab((crc32 Xor streamData(i)) And &HFF) Xor (crc32 >> 8))
			Next
		Loop While bytesRead > 0

		stream.Position = 0	 ' reset

		crc32 = Not crc32
		Return CInt(crc32)
	End Function
End Class

 

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

Post to forums  

Autodesk Design & Make Report