Require a macro to open drawings and save, close, then move to next.

Require a macro to open drawings and save, close, then move to next.

D_Kennington
Explorer Explorer
1,747 Views
7 Replies
Message 1 of 8

Require a macro to open drawings and save, close, then move to next.

D_Kennington
Explorer
Explorer

Hello, In my company quite regularly we will have small changes to drawings (for example a change in issue date), but then this may apply to 200 drawings, which means opening all 200 drawings manually then saving the changes then closing the drawings every time this happens.

 

I was wondering if anyone has a macro, or could write a macro to open drawings, save changes, then close the drawing and move onto the next drawing in the folder until they're all done please?

 

Many thanks in advance.

0 Likes
Accepted solutions (1)
1,748 Views
7 Replies
Replies (7)
Message 2 of 8

Anonymous
Not applicable

I would do the following:

 

1) Create an EXTERNAL rule that will handle the updates

2) Set an  event trigger to run "On Open" for drawing files

3) Use Inventor's task scheduler. Create a task (an "Update" task should work), this will open each drawing in a folder in turn and update it using your rule.

0 Likes
Message 3 of 8

D_Kennington
Explorer
Explorer

Hi Clint,

 

Thanks for the reply, apologies but I'm not clued up enough on writing rules and creating tasks. could you elaborate please?

0 Likes
Message 4 of 8

ChristianAndersenIsmyname
Advocate
Advocate

This is something I've written for myself to open all part drawings from an assembly. Maybe this is something you can use.

 


 

            Dim invapp As Inventor.Application
            invapp = GetObject(, "Inventor.Application")
            Dim asmDoc As AssemblyDocument
            asmDoc = invapp.ActiveDocument
            If asmDoc.DocumentType = DocumentTypeEnum.kAssemblyDocumentObject Then
                For Each Doc In asmDoc.AllReferencedDocuments
                    If Doc.DocumentType = DocumentTypeEnum.kPartDocumentObject Then
                        Try
                            Dim drawing As String = Doc.FullFileName
                            drawing = drawing.Substring(0, drawing.Length - 3)
                            If System.IO.File.Exists(drawing & "idw") Then
                                invapp.Documents.Open(drawing & "idw")

                                'WRITE YOUR CODE HERE

                            End If
                        Catch ex As Exception
                        End Try
                    End If
                Next​

 

0 Likes
Message 5 of 8

Anonymous
Not applicable
Accepted solution

I knocked a quick video together for you (apologies about the sound interference), hopefully, this will point you in the right direction.

 

https://screencast.autodesk.com/Embed/Timeline/8493311b-258a-43b3-846a-91991c5e8c1d

 

Code in the blog post can be found here: https://clintbrown.co.uk/2019/02/02/ilogic-title-block/

0 Likes
Message 6 of 8

D_Kennington
Explorer
Explorer

Clint, that is brilliant. Many thanks for your help!

0 Likes
Message 7 of 8

D_Kennington
Explorer
Explorer

Thanks for the reply! That's not what I was looking for but it's something I will definitely use. Thankyou.

0 Likes
Message 8 of 8

D_Kennington
Explorer
Explorer

Hi again Clint, you're solution works great, the only issue is that I've had a few errors pop up because my drawing doesn't have a view 1 (for example I've created it but then deleted it when I've made a mistake). Is there a bit of code that I could add at the start that would reset the view names so they start from view 1 again?

 

Many thanks

0 Likes