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: 

vba Read revision number from drawing not model

2 REPLIES 2
SOLVED
Reply
Message 1 of 3
CAD-e-Shack
2625 Views, 2 Replies

vba Read revision number from drawing not model

I'm writing a macro that exports .idw's to .dxf's. For each new revision we save a new copy with the revision number tagged onto the part number ( Example I00-001234 revision 1 becomes I00-001234R1).

 

The problem comes when i try to extract the revision number from the drawing. Because the drawing updates the revision from the model, the titleblock shows the model revision. However, when I pull the revision number, the code pulls the data from the sheet iproperties rather than the model iproperties.

 

Is there a way to pull the model revision, or a way to pull the data from the titleblock on the drawing?

Private SaveasDXF_Click()


Dim FSO As Scripting.FileSystemObject
Dim InvDocuments, Path As Documents
Dim invDocument As Document
Dim InvDoc, oDoc As Document
Dim FilePath As String
Dim newDXF As String
Dim PopUp As String
Dim Ans As String

Dim InvRevision As Property
Dim Revision As String


Set InvDoc = ThisApplication.ActiveDocument
Set Path = ThisApplication.Documents
Set InvRevision = InvDoc.PropertySets.Item("Inventor Summary Information").Item("Revision Number")

'^^^ This line reads the sheet revision (which is 0) but the model revision is 1

    Set FSO = New Scripting.FileSystemObject
            FilePath = "C:\TEMP" + newDXF
            MsgBox "Revision Number: " & InvRevision.Value
            If FSO.FileExists(FilePath) = False Then
                If InvRevision.Value = Null Or 0 Then
                    Revision = ""
                Else
                    Revision = "R" + CStr(InvRevision.Value)
                    newDXF = newDXF + Revision
                End If

    ' Here I call the function to save copy as DXF
 
            Else
                PopUp = "Do you wish to overwrite the file" & vbNewLine & _
                newDXF & "?"
                Ans = MsgBox(PopUp, vbOKCancel, "Overwrite File?")
                    If Ans = vbOK Then
                'Delete old file
                    With New FileSystemObject
                        .DeleteFile "C:\TEMP" & newDXF
                        End With
                        If InvRevision.Value = Null Or 0 Then
                            Revision = ""
                        Else
                            Revision = "R" + CStr(InvRevision.Value)
                            newDXF = newDXF + Revision
                        End If
      ' Here I call the code to save a copy as DXF
                    Else
                    End If
            End If
 
End Sub

 

2 REPLIES 2
Message 2 of 3
GVDB
in reply to: CAD-e-Shack

I presume that you are in a idw when you call SaveasDXF

 

If so you must change:

Set InvRevision = InvDoc.PropertySets.Item("Inventor Summary Information").Item("Revision Number")

 

into this:

Dim InvModelDoc as Inventor.Document

Set InvModelDoc = InvDoc..ReferencedDocuments(1)

Set InvRevision = InvModelDoc.PropertySets.Item("Inventor Summary Information").Item("Revision Number")

 

This gives you the revision of the model which belongs by the iDW

Message 3 of 3
CAD-e-Shack
in reply to: GVDB

Thanks a lot. It works perfectly now.

The .idw wasn't the open document, but I solved this by changing:

 

Set InvDoc = ThisApplication.ActiveDocument

to

Set InvDoc = Path.Item(j) (and of course moving this below the point where j is defined as the correct integer.)

 

 

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

Post to forums  

Autodesk Design & Make Report