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

    Autodesk Inventor Customization

    Reply
    Active Contributor
    michmaju
    Posts: 26
    Registered: ‎09-01-2011

    Extract model REV from drawing that only references an ipn using VBA

    68 Views, 2 Replies
    12-07-2012 09:56 AM

    I'm trying to extract the Rev of a model (part or assembly) from a drawing.  Since Inventor has independent revs for the model and idw I am trying to drill down and put the rev from the model referenced.  I got it to work for ipts and many iams using:

     

    Dim oModelDoc As Document
    Set oModelDoc = oDocument.Sheets(1).DrawingViews(1).ReferencedDocumentDescriptor.ReferencedDocument

     

    The problem I have is when the drawing only references an ipn presentation file.  The ipn ALSO has it's own independant rev!  I'm trying access the model the ipn references but cannot get it to work.

     

    BTW, I do know about the ability to sync idw and ipt properties.  I have enable it for our template but we have a lot of legacy drawings that don't have this option selected.  I also haven't tested that method with an drawing that only references an ipn.

     

    Code is below with offending section in bold:

     

    ' Find model (part or assembly) referenced by drawing if active document is a drawing
    If oDocument.DocumentType = kDrawingDocumentObject Then
    Dim oModelDoc As Document
    Set oModelDoc = oDocument.Sheets(1).DrawingViews(1).ReferencedDocumentDescriptor.ReferencedDocument
    If oModelDoc.DocumentType = kPresentationDocumentObject Then
    Dim oModelDoc2 As Document
    Set oModelDoc2 = oModelDoc.AllReferencedDocuments.Item(1) 'oModelDoc..ReferencedDocumentDescriptors.Item(1).ReferencedDocument

    ' debug: test if the correct document type was found
    If oModelDoc2.DocumentType = kAssemblyDocumentObject Then
    MsgBox ("yeah, it's an iam")
    End If

    ' debug: check to see if the correct file has been found by looking at filename
    Set oFMetadata = ThisApplication.TransientObjects.CreateFileMetadata(oModelDoc2.FullFileName)
    PN = oFMetadata.FileName


    'Dim test As PresentationDocument
    'test.AllReferencedDocuments.Item (1)
    'test.ReferencedDocuments.Item(1).ReferencedDocumentDescriptors.Item(1).ReferencedDocument

    Set oDocument = oModelDoc2
    Else
    Set oDocument = oModelDoc
    End If
    End If
    ' END TEST

    ' Get the PropertySets collection object
    Dim oPropertySets As PropertySets
    Set oPropertySets = oDocument.PropertySets

    ' Get Rev if it exists else oRev = ""
    Dim oRev As Variant
    oRev = oPropertySets.Item("{F29F85E0-4FF9-1068-AB91-08002B27B3D9}").ItemByPropId(kRevisionSummaryInformation).Value

    Matthew
    INV 2013
    Please use plain text.
    Active Contributor
    michmaju
    Posts: 26
    Registered: ‎09-01-2011

    Re: Extract model REV from drawing that only references an ipn using VBA

    12-11-2012 01:04 PM in reply to: michmaju

    Any VBA experts have any ideas?

    Matthew
    INV 2013
    Please use plain text.
    ADN Support Specialist
    xiaodong.liang
    Posts: 805
    Registered: ‎06-12-2011

    Re: Extract model REV from drawing that only references an ipn using VBA

    01-08-2013 06:25 PM in reply to: michmaju

    Hi,

     

    I may not get what you meant:  ....the ipn ALSO has it's own independant rev!  I'm trying access the model the ipn references but cannot get it to work.

     

    I created an assembly and used it in a drawing. And I created a presentation document with this assembly. Finally ran your code snippet. this line works well to me.

     

    Set oModelDoc2 = oModelDoc.AllReferencedDocuments.Item(1)

     

    Could you clarify the problem you are having? or any screenshots, or specific documents?



    Xiaodong Liang
    Developer Technical Services
    Autodesk Developer Network

    Please use plain text.