Checkin DWG plus XRefs
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I am still working on my app to migrate several tens of thousands autocad dwg files into a Vault.
Not 100% certain if the sample code I used is correct in using CheckinFile twice, first to stream the file data into the Vault and then a second time to check in that FileIteration that was created by the first call.
A more pressing problem for me though is that I can find no information, at all, on how to check in not only a dwg file but also the xrefs that it uses. I am running a process before checking in that verifies all xrefs and either fixes or removes unsolved xrefs, so the vault check in only has to deal with valid xrefs. This process also gives me a list of xrefs for each of the dwg file that it will have to check in.
From the information I could find I think that I have to use the FileAssocParam[] parameter of the CheckinFile method to set the links between dwg and xrefs in Vault. I can check in the XRef dwg files before checking in the main file, but the problem I am running into is that CheckinFile returns a FileIteration object and FileAssocParam has a lot of obscurely named Properties that do not appear to map to FileIteration objects.
The only sample code I could find here, or in e.g. the sample projects of the SDK, all assume that you use a function to query for already existing associations.
This has me wondering if I am trying to solve my problem (of checking in both a new dwg and its new xrefs into a vault) in the correct way. Or if there is some obscurely documented way of going from FileIteration to FileAssocParam.
(for what it is worth, this is the current, untested, version of the method to check in dwg files that I am trying to get to work)
internal FileIteration CheckIn(string fname, List<KeyAndValue> values, Folder rootFolder) { if (string.IsNullOrEmpty(fname)) return null; if (!File.Exists(fname)) return null; string path = Path.GetDirectoryName(fname); if (null == rootFolder) return null; List<FileAssocParam> associations = new List<FileAssocParam>(); FileAssocParam[] assocs = null;
// XRefAssociation is a Dictionary that keeps track of the xrefs associated with every main dwg file if (XRefAssociations.ContainsKey(fname)) { foreach (string xrefPath in XRefAssociations[fname]) {
// recursively CheckIn each XRef dwg file that is necessary for this main file FileIteration ci = CheckIn(xrefPath, values, rootFolder);
// we need a FileAssocParam. I think FileAssocParam param = new FileAssocParam() { CldFileId = ci.EntityIterationId, ComponentIds = null, ExpectedVaultPath = "", RefId = null, Source = null, Typ = AssociationType.Attachment }; associations.Add(param); } } if (associations.Count > 0) assocs = associations.ToArray(); // this gets the subfolders that are required for the vault folder structure to check in dwg files in the correct location string g1 = GetValueFor("Groep1", values); string g2 = GetValueFor("Groep2", values); string g3 = GetValueFor("Groep4", values); // they are used to construct the complete folder path Folder fldr = GetFolder(g1, g2, g3); if (string.IsNullOrEmpty(path)) return null; // stream the file data into vault FileIteration fileIteration = null; using (Stream sr = new FileStream(fname, FileMode.Open, FileAccess.Read)) { try { fileIteration = Conn.FileManager.AddFile(fldr, path, "Added by Tata Steel Migration", DateTime.Now, null, null, FileClassification.None, false, sr); } catch (Exception ex) { // failed. Report to the user that this particular file was not added to the vault } } if (null == fileIteration) return null; // The sample code I found called CheckinFile a secod time to, presumably actually check in the file. I put the associations array here FileIteration res = Conn.FileManager.CheckinFile(fileIteration, "Added by Tata Steel Migration", false, assocs, null, false, fname, FileClassification.None, false, new FilePathAbsolute(path)); return res; }
So I guess there are three related question.
Do I need to use the FileAssocParam[] parameter to link xref files to the main dwg file or is there another method to achieve that goal.
Assuming I need to get FileAssocParam objects, how do I create them, given that I only have the FileIteration data of a file that was just checked in?
Do I need to call CheckinFile twice, or is the sample code I found in error on that and can I combine both calls into one?