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: 

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

2 REPLIES 2
Reply
Message 1 of 3
michmaju
342 Views, 2 Replies

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

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
2 REPLIES 2
Message 2 of 3
michmaju
in reply to: michmaju

Any VBA experts have any ideas?

Matthew
INV 2013
Message 3 of 3
xiaodong_liang
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?

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

Post to forums  

Autodesk Design & Make Report