Vault General Discussion

Reply
Active Member
Craig_Schuler
Posts: 8
Registered: ‎03-26-2004
Message 1 of 7 (281 Views)

API File id get command

281 Views, 6 Replies
07-17-2009 03:25 AM
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
*Doug Redmond \(Autodesk\)
Message 2 of 7 (281 Views)

Re: API File id get command

07-17-2009 04:42 AM 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.
Active Member
Craig_Schuler
Posts: 8
Registered: ‎03-26-2004
Message 3 of 7 (281 Views)

Re: API File id get command

07-17-2009 06:05 AM in reply to: Craig_Schuler
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
*Doug Redmond \(Autodesk\)
Message 4 of 7 (281 Views)

Re: API File id get command

07-17-2009 10:04 AM 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.
Active Member
Craig_Schuler
Posts: 8
Registered: ‎03-26-2004
Message 5 of 7 (281 Views)

Re: API File id get command

07-21-2009 04:36 AM in reply to: Craig_Schuler
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
Valued Contributor
joerituijn
Posts: 65
Registered: ‎09-20-2009
Message 6 of 7 (281 Views)

Re: API File id get command

09-20-2009 02:38 AM 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(){""}
Mentor
amitk_189
Posts: 234
Registered: ‎12-15-2011
Message 7 of 7 (105 Views)

Re: API File id get command

12-17-2012 01:29 AM in reply to: Craig_Schuler

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

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Announcements
New button for Platinum & Gold Subscription customers
Gold & Platinum Subscription customers can alert Autodesk if they require assistance with their forum post

Manufacturing Community
The Manufacturing Community provides additional access to tips, tutorials, blogs and networking with peers.

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Ask the Community