Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Viewing an assembly downloaded from Vault using Apprentice

0 REPLIES 0
Reply
Message 1 of 1
TimClift
512 Views, 0 Replies

Viewing an assembly downloaded from Vault using Apprentice

System Information

Inventor Apprentice 2010 API

Windows 7 64 bit

Microsoft Visual Studio Professional 2010

 

I am developing an Apprentice app to view .iam, .idw, and .ipt files.  I have developed a shared library to download all the referenced files in the Vault using a recursive function to insure that all referenced files have been downloaded.  After downloading the files from the Vault, the shared library returns the FullDocumentName of the top level assembly.  I instantiate an ApprenticeServerComponent and define an ApprenticeServerDocument then call the Open method with the FullDocumentName and assign the return value to the ApprenticeServerDocument.   The AllReferencedDocuments property has the correct value but the AllReferencedDocuments property of all assemblies below the top level is set to 0.  Because of this, when I make the call AxInventorViewControl to display the .iam file I get the error message:

 

7 components were not found. It is advised that you place these files in the project's search path.

Would you like to continue and skip files?

 

C:\_Vault_Working_Folder\Design\Autocad\custom\A300-400\A316\225-A316\225-A316-12-01-FM.ipt

C:\_Vault_Working_Folder\Design\Autocad\Parts\325 (fasteners)\325-5446-00.ipt

C:\_Vault_Working_Folder\Design\Autocad\custom\A300-400\A316\225-A316\225-A316-12-02-FM.ipt

C:\_Vault_Working_Folder\Design\Autocad\Parts\325 (fasteners)\325-5171-00.ipt

C:\_Vault_Working_Folder\Design\Autocad\Parts\125 (Tubes)\125-4392-00\125-4392-00.ipt

C:\_Vault_Working_Folder\Design\Autocad\Parts\225 (Sheet Metal)\225-4635-00\225-4635-00.iam

C:\_Vault_Working_Folder\Design\Autocad\Parts\225 (Sheet Metal)\225-4636-00\225-4636-00.ipt

 

 

I have verified that all referenced files have been downloaded and exist in the correct location after the return from the call in my shared library.  I have written a recursive function that takes the top level assembly and opens all referenced documents using the ReferencedDocumentDescriptors property but the AllReferencedDocuments property is still set to 0.  I have also verified that all the referenced files are being hit in my recursive function by stepping through my function in the debugger.  The really interesting part is that after I run my code I can open the top level assembly using the Inventor Viewer with no errors.  Can someone please review the code below to see if I am missing some important call that is causing this problem?

 

This is the function that returns from my shared library

 

private void btnAccept_Click(object sender, EventArgs e)
        {            
            this.Visible = false;
            this.Cursor = Cursors.WaitCursor;
            // Open the top level assembly
            OpenFile();
            m_svrComponent = new ApprenticeServerComponent();

            if (fileName != null)
            {
                m_doc = m_svrComponent.Open(fileName);               
            }

            Open_Assembly(m_doc);
            m_doc.Close();
            m_doc = m_svrComponent.Open(fileName);
            
            CancleOpen.Cancled = false;           
            this.Close();
        }

 This is the code that downloads the top level assembly.

 

private void OpenFile()
        {
            // This funcion downloads the top level assembly from the Vault
            if (m_vaultFilelistView.SelectedItems.Count > 0)
            {
                AnthroVault.DocumentSvc.File selectedFile = (AnthroVault.DocumentSvc.File)m_vaultFilelistView.SelectedItems[0].Tag;
                Folder vaultFileFolder = (Folder)m_vaultFolderTree.SelectedNode.Tag;
                string vaultFilePath = vaultFileFolder.FullName;
                string localFilePath = vaultFilePath.Replace("$", "C:\\_Vault_Working_Folder").Replace("/", "\\");

                AnthroVault.OpenFileCommand.Execute(selectedFile, localFilePath, anthroVault.m_docSvc);
                fileName = localFilePath + "\\" + selectedFile.Name;
            }
        }

This is the code to download all the referenced files from Vault.

 

private void Open_Assembly(ApprenticeServerDocument doc)
        {   
            // Open_Assembly is a reecussive function that downloads all required files for an assembly using the
            // ReferencedDocumentDescriptors property.  The parameter to Open_Assembly is an ApprenticeServerDocument.

            // Get the ReferencedDocumentDescriptors property from the ApprenticeServerDocument.
            DocumentDescriptorsEnumerator refDocs = doc.ReferencedDocumentDescriptors;
            
            // Setup to Lists of strings to hold the vault file names and local file paths of the referenced documents.
            List<string> vaultFileNames = new List<string>();
            List<string> localFilePaths = new List<string>();

            // If the referenced documents count is not 0 the ApprenticeServerDocument is an assembly and we need to download
            // all the referenced documents from Vault.
            if (refDocs.Count != 0)
            {    
                // Iterate through all the referenced documents and build two List of strings. One with the Vault file names
                // and one with the local path.  The Vault file names will be passed the Vault web service call FindLatestFilesByPaths
                // to get the DocumentSvc File array.  The local path will be passed to the GetReferencedDocs function with
                // DocumentSvc file array returned from the FindLatestFilesByPaths to download the files from the Vault
                foreach (DocumentDescriptor refDoc in refDocs)
                {
                    if (!vaultFileNames.Contains(refDoc.FullDocumentName.Replace("C:\\_Vault_Working_Folder", "$").Replace("\\", "/")))
                    {
                        vaultFileNames.Add(refDoc.FullDocumentName.Replace("C:\\_Vault_Working_Folder", "$").Replace("\\", "/"));
                        localFilePaths.Add(refDoc.FullDocumentName.Remove(refDoc.FullDocumentName.Length - refDoc.DisplayName.Length - 4));
                    }
                }

                // Instantiate the string arrays to hold the the List of strings Vault file names and the local paths
                // The call to FindLatestFilesByPaths takes a string array.
                string[] svaultFiles = new string[vaultFileNames.Count];
                string[] slocalPaths = new string[localFilePaths.Count];

                // Convert the Vault file names and local files paths to string arrays.
                svaultFiles = convertToStringArray(vaultFileNames);
                slocalPaths = convertToStringArray(localFilePaths);

                // Get the DocumentSvc files array from the Vault.
                AnthroVault.DocumentSvc.File[] vaultFiles = anthroVault.m_docSvc.FindLatestFilesByPaths(svaultFiles);

                // Download the files from the vault.
                GetReferencedDocs(vaultFiles, slocalPaths);

                // Iterate through all the referenced documents.  Open each document and then make the recursive call
                // to open any referenced documents in the document that was opened.  
                // If no referenced documents exist the function returns.
                foreach (DocumentDescriptor refDoc in refDocs)
                {
                    localDoc = m_svrComponent.Open(refDoc.FullDocumentName);
                    Open_Assembly(localDoc);
                }
            }
        }

 

The above code is all from my shared library

 

This is the code that makes the call to my shared library.

 

private void Vault_Click(object sender, RoutedEventArgs e)
        {
            if (m_AppSvr != null)
            {
                m_AppSvr.Close();
                m_AppDoc.Close();
            }

            OpenVaultFile openVaultFile = new OpenVaultFile();
            openVaultFile.ShowDialog();

            if (AnthroVault.CancleOpen.Cancled == true)
            {
                openVaultFile.Dispose();
                AnthroVault.CancleOpen.Cancled = false;
            }
            else
            {
                m_AppSvr = new ApprenticeServerComponent();
                m_Doc = m_AppSvr.Open(openVaultFile.fileName);
                
                OpenRefDocs(m_Doc);                

                m_AppDoc = m_AppSvr.Open(m_Doc.FullDocumentName);
                
                ((WinFormsUserControl)this.windowsFormsHost.Child).LoadInv(m_AppDoc.FullDocumentName);                
            }                                           
        }

  This is the recursive function that opens all the referenced files.

 

private void OpenRefDocs(ApprenticeServerDocument doc)
        {
            ApprenticeServerDocument tmpDoc;

            if (doc.ReferencedDocumentDescriptors.Count != 0)
            {
                foreach (DocumentDescriptor refDoc in doc.ReferencedDocumentDescriptors)
                {                   
                    tmpDoc = m_AppSvr.Open(refDoc.FullDocumentName);                    
                    OpenRefDocs(tmpDoc);
                }                
            }
        }

 

I hope this is not too much to ask.  I know it is a lot of code.

 

Any help would be greatly appriciated.

 

 

0 REPLIES 0

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

Post to forums  

Autodesk Design & Make Report