• Industries
  • Products
  • Buy
  • Services & Support
  • Communities
  • Discussion Groups

    Autodesk Vault Customization

    Reply
    Active Contributor
    g.heeley
    Posts: 31
    Registered: ‎06-08-2011
    Accepted Solution

    Remove tertiary links

    211 Views, 2 Replies
    10-09-2012 06:51 PM

    Historically we have included views of parts on our assembly drawings. Now when we come to itemise the parts we are getting 100+ drawings referenced to the item as tertiary links. I want to write a little routine to do this but can't get the UpdateandCommitItem action to work. I am asusming its something to do with the last parameter (active inputs)

     

    here's the function. I have used active input values of 0,1,2 and 4 to no avail

           /// <summary>
            /// Remove the unwanted tertiary linked files. These are extracted when a part is explicitly referenced in a Drawing 
            /// </summary>
            /// <param name="itemId"></param>
            public void RemoveUnwantedTertiaryLinks(long itemId)
            {
                Item selItem = m_itemSvc.GetItemsByIds(new long[] { itemId })[0];
    
                //Get the primary linked file
                ItemFileAssoc primaryFile = m_itemSvc.GetItemFileAssociationsByItemIds(new long[] { selItem.Id }, ItemFileLnkTypOpt.Primary)[0];
    
                //Get all the tertiary assocs for the item
                ItemFileAssoc[] itemFileAssocs = m_itemSvc.GetItemFileAssociationsByItemIds(new long[] { selItem.Id }, ItemFileLnkTypOpt.Tertiary);
    
                IEnumerable<long> fileIds = from fileassoc in itemFileAssocs select fileassoc.CldFileId;
                File[] files = m_docSvc.GetFilesByIds(fileIds.ToArray<long>());
    
                File drawingFile = null;
                //now match the drawing name to the primary fiule name and remove all the others
                foreach (File fle in files)
                {
                    //If the filename matches either the item number or the primary linked filename then keep it
                    if (System.IO.Path.GetFileNameWithoutExtension(fle.Name).ToLower() == System.IO.Path.GetFileNameWithoutExtension(primaryFile.FileName).ToLower() || System.IO.Path.GetFileNameWithoutExtension(fle.Name).ToLower() == selItem.ItemNum.ToLower())
                    {
                        drawingFile = fle;
                        break;
                    }
                    if (drawingFile != null) break;
                }
    
                //now edit the item to update links
                Item editItem = m_itemSvc.EditItem(selItem.RevId);
                Item updateItem = m_itemSvc.UpdateAndCommitItem(editItem, primaryFile.CldFileId, false, null, null, null, null, null, new long[] { drawingFile.Id }, 1);
            }

     Any one got any pointers?

    Thanks
    Greg

    Greg Heeley
    CAD Administrator
    temperzone Ltd
    Inventor Pro, Vault Pro, ACADE
    Please use plain text.
    Employee
    Posts: 646
    Registered: ‎12-12-2006

    Re: Remove tertiary links

    10-10-2012 04:57 AM in reply to: g.heeley

    You are correct, it's related to the "active inputs" parameter.  Unfortunately, you have run into another documentation bug.  The CHM doesn't mention that 8 is the bit value for making the 'tertLinks' input active.

     

    In the code you showed, 'secondary' is the only active field because you pass in 1.  If you want both 'secondary' and 'tertLinks' to be active, pass in 9.

     



    Doug Redmond
    Software Engineer
    Autodesk, Inc.
    http://justonesandzeros.typepad.com/

    Please use plain text.
    Distinguished Contributor uma
    Distinguished Contributor
    Posts: 162
    Registered: ‎01-14-2010

    Re: Remove tertiary links

    12-16-2012 02:32 AM in reply to: g.heeley

    After you have deleted those links don't you have problem that they return on each Item update?

    Please use plain text.