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: 

API File id get command

6 REPLIES 6
Reply
Message 1 of 7
Craig_Schuler
1038 Views, 6 Replies

API File id get command

I am working on a Routine with the API that updates File Attachments an Item has. I query and get the item, then I know the Attatchments - giving the needed file ids. When I try to issue the documentsvc.getfilesbyid I always get a error about 1 dimentional array can't be set.

I have tried different ways to make this work. What does the getfilebyid return? What should it be set equal to?

For Each pitem As Item In item_list
Try

Dim Attmt() As ItemSvc.Attmt
Dim id_file() As Long


Attmt = itemSvc.GetAttachmentsByItemId(pitem.Id)

Dim PS_File As DocumentSVC.File

id_file(0) = Attmt(0).FileId

PS_File = document.GetFilesByIds(id_file(0))



Is there a sample that I can refer to or some help somebody can provide??

Thanks
6 REPLIES 6
Message 2 of 7
Anonymous
in reply to: Craig_Schuler

It looks like you are confusing the 2 API functions GetFileById and
GetFilesByIds.

GetFileById takes a single long value and returns a single File object.
GetFilesByIds takes an array of long values and returns an array of File
objects.

Looking at your code, it looks like you want to use GetFileById.


Doug Redmond
Software Engineer, Autodesk Inc.
Message 3 of 7

Doug - I have tried both commands - neither work. Bottom line I want to take the Attachment file id and use it to get documents. I would to use the Getfilesbyid cause that would mean I get all files with one server call.

How do I do that?

Dim Attmt() As ItemSvc.Attmt
Dim Attachments As ArrayList = New ArrayList
Dim id_file() As Long

Attmt = itemSvc.GetAttachmentsByItemId(pitem.Id)

Dim PS_files() As Document.FileArray

PS_Files = document.GetFilesByIds(attmt????????????????????)


I must be missing something

thanks
Message 4 of 7
Anonymous
in reply to: Craig_Schuler

If you are using GetFilesByIds you need to pass in an array of Long values.

So "Dim id_file() As Long" is the correct way to declare the variable. Next
you need to call ReDim to set the size of the array. Then you need to fill
each value of the array.

GetFilesbyIds passed back an array of Files. So you declare it with "Dim
PS_Files() As DocumentSVC.File".
The code you have in the last post is an array of FileArrays, which is
different than an array of Files.

Once you have all that, you call the API function with "PS_Files =
document.GetFilesByIds(id_file)"


Doug Redmond
Software Engineer, Autodesk Inc.
Message 5 of 7

Doug - thanks for your assistance - have gotten past the issue of getting the documents. Now that I have the documents I am doing a check out - update - check in. When I do this with a dwg I also check out the DWF and update it also then check it back in. Problem I have is when checking in the DWG I lose the DWF that is attached to it. I see in the check in command attachfileids() as long - what ID do you put here???

I also used the GetDesignVisualizationAttachmentsByFileMasterIds - thought it would have some ids in it but can't seem to get it to work

'get dwf files from attachments array
Dim ps_file_assc() As Document.FileAssocArray
ps_file_assc = document.GetDesignVisualizationAttachmentsByFileMasterIds(file_mast_ids)

'checkout Parent document
document.CheckoutFile(folders(y).Folders(0).Id, ps_file.MasterId, Environment.MachineName, _
"c:\\temp", "Revision Update", True, True, bytes)

If Right(ps_file.Name, 3) = "DWG" Then
'check out DWF
document.CheckoutFile(folders(y).Folders(0).Id, ps_file_assc(y).FileAssocs(0).CldFile.MasterId, _
Environment.MachineName, "c:\\temp", "Revision Update", True, True, bytes)
'update DWF
Dim filePath As String = "c:\_import\dwf\" & dr_sub_rev(6) & "." & dr_sub_rev(7) & ".DWF"
bytes = System.IO.File.ReadAllBytes(filePath)
document.CheckinFile(ps_file_assc(y).FileAssocs(0).CldFile.MasterId, "Bulk Loading", False, _
System.IO.File.GetLastWriteTime(filePath), Nothing, Nothing, Nothing, Nothing, Nothing, False, _
ps_file_assc(y).FileAssocs(0).CldFile.Name, ps_file_assc(y).FileAssocs(0).CldFile.FileClass, _
ps_file_assc(y).FileAssocs(0).CldFile.Hidden, bytes)

Dim attatch_id() As Long
ReDim attatch_id(0)
attatch_id(0) = ps_file_assc(y).FileAssocs(0).Id

filePath = dr_sub_rev(18) & "\" & dr_sub_rev(6) & "." & dr_sub_rev(7)
bytes = System.IO.File.ReadAllBytes(filePath)
document.CheckinFile(ps_file.MasterId, "Bulk Loading", False, System.IO.File.GetLastWriteTime _
("c:\\temp"), Nothing, Nothing, ??????????, Nothing, Nothing, False, ps_file.Name, ps_file.FileClass, _
ps_file.Hidden, bytes)
Else
filepath = dr_sub_rev(18) & "\" & dr_sub_rev(6) & "." & dr_sub_rev(7)
bytes = System.IO.File.ReadAllBytes(filepath)
document.CheckinFile(ps_file.MasterId, "Bulk Loading", False, System.IO.File.GetLastWriteTime _
("c:\\temp"), Nothing, Nothing, Nothing, Nothing, Nothing, False, ps_file.Name, ps_file.FileClass, _
ps_file.Hidden, bytes)
End If



Thanks

Craig Edited by: Craig_Schuler on Jul 21, 2009 6:37 AM
Message 6 of 7
joerituijn
in reply to: Craig_Schuler

I'm not sure if you're still looking for the answer, it has been a while, but this line :

document.CheckinFile(ps_file.MasterId, "Bulk Loading", False, System.IO.File.GetLastWriteTime _
("c:\\temp"), Nothing, Nothing, ??????????, Nothing, Nothing, False, ps_file.Name, ps_file.FileClass, _
ps_file.Hidden, bytes)

Should contain the fileids array (attatch_id) ANDALSO the attachment source array which is just as long and contains empty strings: new string(){""}
Message 7 of 7

Is the issue resolved. About Checkout-update-Checkin.

Senior Software Engineer

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

Post to forums  

Autodesk Design & Make Report