Inventor Customization

Reply
Mentor
mehatfie
Posts: 163
Registered: ‎02-10-2012
Message 11 of 19 (386 Views)

Re: Marco and VBA Programing Help

12-20-2012 06:20 AM in reply to: AJ1227

Hi AJ1227,

 

Why don't you simplly close the drawing after all of your tasks have been done to it and before you move on to the next drawing.

 

Regards

Mitch

Contributor
AJ1227
Posts: 21
Registered: ‎10-20-2011
Message 12 of 19 (380 Views)

Re: Marco and VBA Programing Help

12-20-2012 09:40 AM in reply to: mehatfie

The final step in my Sub is to close the drawing but then my Sub ends.  I have the macro set to a shortcut key so I could simply press the key once the previous drawing automatically closes and let the Sub run again on the next open drawing but I was hoping for the Sub to loop automatically until there are no open drawings remaining; but I don't know how to set up that kind of a loop.  Here is what I ended up with.

 

 

Public Sub TEMPLATE_PDF_CAD_PROGRAM()

 

        Dim oDocument As DrawingDocument

        Set oDocument = ThisApplication.ActiveDocument

   

        ' Open the template drawing to copy the title block from.

        Dim oNewDocument As DrawingDocument

        Set oNewDocument = ThisApplication.Documents.Open("TEMPLATE LOCATION HERE\TEMPLATE.DWG", False)

   

        ' Get the new title block definition.

        Dim oNewTitleBlockDef As TitleBlockDefinition

        Set oNewTitleBlockDef = oNewDocument.ActiveSheet.TitleBlock.Definition

   

        ' Set the new title block definition.

        Dim oTitleBlockDef As TitleBlockDefinition

        Set oTitleBlockDef = oNewTitleBlockDef.CopyTo(oDocument)

   

        ' Iterate through the sheets.

        Dim oSheet As Sheet

        For Each oSheet In oDocument.Sheets

        oSheet.Activate

       

        oSheet.TitleBlock.Delete

        Call oSheet.AddTitleBlock(oTitleBlockDef)

        Next

       

        ' Save Document

        oDocument.Save

   

        ' Pause for save

        Dim PauseTime

 

        PauseTime = 5 ' Set duration.

       

        ' Get the PDF translator Add-In.

        Dim PDFAddIn As TranslatorAddIn

        Set PDFAddIn = ThisApplication.ApplicationAddIns.ItemById("{0AC6FD96-2F4D-42CE-8BE0-8AEA580399E4}")

 

        Dim oContext As TranslationContext

        Set oContext = ThisApplication.TransientObjects.CreateTranslationContext

        oContext.Type = kFileBrowseIOMechanism

 

        ' Create a NameValueMap object

        Dim oOptions As NameValueMap

        Set oOptions = ThisApplication.TransientObjects.CreateNameValueMap

 

        ' Create a DataMedium object

        Dim oDataMedium As DataMedium

        Set oDataMedium = ThisApplication.TransientObjects.CreateDataMedium

 

        ' Check whether the translator has 'SaveCopyAs' options

        If PDFAddIn.HasSaveCopyAsOptions(oDocument, oContext, oOptions) Then

 

            ' Options for drawings...

 

            oOptions.Value("All_Color_AS_Black") = 0

 

            'oOptions.Value("Remove_Line_Weights") = 0

            oOptions.Value("Vector_Resolution") = 720

            oOptions.Value("Sheet_Range") = kPrintAllSheets

            'oOptions.Value("Custom_Begin_Sheet") = 2

            'oOptions.Value("Custom_End_Sheet") = 4

       

        End If

 

        'Set the destination file name

        oDataMedium.FileName = "SAVE LOCATION\" & Left(oDocument.DisplayName, Len(oDocument.DisplayName) - 4) & ".pdf"

 

        'Publish document.

        Call PDFAddIn.SaveCopyAs(oDocument, oContext, oOptions, oDataMedium)

   

        ' Pause for PDF publish

        PauseTime = 1000 ' Set duration.

 

        ' Get the DWG translator Add-In.

        Dim DWGAddIn As TranslatorAddIn

        Set DWGAddIn = ThisApplication.ApplicationAddIns.ItemById("{C24E3AC2-122E-11D5-8E91-0010B541CD80}")

 

        'Set the destination file name

        oDataMedium.FileName = "SAVE LOCATION\" & Left(oDocument.DisplayName, Len(oDocument.DisplayName) - 4) & ".dwg"

 

        'Publish document.

        Call DWGAddIn.SaveCopyAs(oDocument, oContext, oOptions, oDataMedium)

   

        'Pause for Save As DWG

        PauseTime = 5000 ' Set Duration

   

        'Save Document

        oDocument.Save

       

        'Pause for Save

        PauseTime = 5000 ' Set Duration

       

        'Close document

        oDocument.Close

      

       End Sub

Mentor
mehatfie
Posts: 163
Registered: ‎02-10-2012
Message 13 of 19 (376 Views)

Re: Marco and VBA Programing Help

12-20-2012 09:53 AM in reply to: AJ1227

Hi AJ1227,

 

I thought you originally wanted this program to process all drawings related to an assembly. 

 

Do your drawings have the same name as their parts / assembly? Also, where do your drawings exist relative to the models location?

 

Regards

Mitch

Contributor
AJ1227
Posts: 21
Registered: ‎10-20-2011
Message 14 of 19 (372 Views)

Re: Marco and VBA Programing Help

12-20-2012 10:24 AM in reply to: mehatfie

I do want it to process all drawings related to an assembly but it is a little complicated; let me see if I can explain.

 

We break our save locations into Assembly, Subassembly, and Part folders.  The models and drawings do have the same name and model/drawing are in the same folder.  But these are not the drawings that I am modifying.

 

We take all drawings associated with an assembly and save a copy of them all with _CAD at the end so that when they are saved with the customer title block we do not screw up our drawings.  We save the _CAD in the same folder as the model/our drawing.  (While testing this macro I have been using design assistant to accomplish this, then opening all _CAD drawings and testing the macro).

 

It would be nice to setup this macro so that I open the top level model or drawing (our version) and start the macro to (current macro steps are in red):

 

1. Saves drawing as "current name_CAD" in same location

2. Replace title block

3. Save

4. Publish PDF (separate specified location)

5. Save As AutoCAD (separate specified location)

6. ReSave file

7. Close file

8. Open next drawing associated with assembly, repeat process until all drawings complete.

 

Can you help walk me through setting this up?

 

Thanks

Mentor
mehatfie
Posts: 163
Registered: ‎02-10-2012
Message 15 of 19 (365 Views)

Re: Marco and VBA Programing Help

12-20-2012 12:09 PM in reply to: AJ1227

AJ1227,

 

Attached you'll find a quick code that I through together with some other pieces I had. I've added some other things as well but I believe this is what you'd like to do.

 

The code would be run from an Assembly Model and iterates through all of the parts checking if a drawing exists in the same location with the same name. It then opens this drawing and saves a copy with "_CAD" next to it.

 

After this insert your current code and perform the tasks on "DrawDocNew"

 

save and close both documents.

 

 

 

Note that this code is NOT tested and was developed to be placed directly into an iLogic Rule. Changes may be needed to work directly in VBA.

 

This should be a good template to work with for what you're looking to do.

 

Regards

Mitch

 

Let me know if it helps... Kudos if it works!!!

Contributor
AJ1227
Posts: 21
Registered: ‎10-20-2011
Message 16 of 19 (348 Views)

Re: Marco and VBA Programing Help

12-21-2012 11:03 AM in reply to: mehatfie

Well, after much modifying I've got it working!  Two issues that I'm having:

 

1. The Sub starts with the first assembly within the model; it does not pull the drawing for the open assembly model that I begin with.  I need it to start with the drawing for the model that I have open then work through the referenced documents.

 

2. I'm getting the occasional "Save?" prompt for some of the drawings while the macro is running.  We just switched from Inventor 2010 to 2013 and part of this is because the data needs to be migrated; part of it is because Inventor is too sensative and even though nothing has been changed or updated it wants to prompt you to "Save" as if it was modified.  Is there any way to autorespond "NO" to any save prompts?

 

I'm giving Kudos to all replies in this post for all the help.  I couldn't have done it without you!

Mentor
mehatfie
Posts: 163
Registered: ‎02-10-2012
Message 17 of 19 (344 Views)

Re: Marco and VBA Programing Help

12-21-2012 11:22 AM in reply to: AJ1227

Hi AJ1227,

 

I would recommend you create a seperate sub in order to not increase the length of your code.

 

Create a sub that contains all of the information in between the "For" loop. Make this sub simply recieve a document, and place it inside the "For" loop instead of all the other code while inputting the DocFile into the code on each loop.

 

This way you can send your assembly file into this same sub prior to the For loop, avoiding copying and pasting the exact same code twice just to run the assembly document

 

Regards

Mitch

 

Let me know if it helps... Kudos if it works!!!

Contributor
AJ1227
Posts: 21
Registered: ‎10-20-2011
Message 18 of 19 (330 Views)

Re: Marco and VBA Programing Help

01-03-2013 12:30 PM in reply to: mehatfie

Used copy and paste rather than integrating a sub within a sub (wasn't sure where to start, it was faster to copy/paste).  It's doing everything I want it to and more; I have it deleting the revision tables as it replaces the borders and title blocks on each of the sheets within the drawings.  For the life of me I can't figure out how to delete the revision tags with VBA (I can't find a word within VBA to describe the revision tag and delete it).  Is there at least an option to link revision tags to the revision table so that when the table is deleted the tags are removed also?

 

Thanks,

ADN Support Specialist
xiaodong.liang
Posts: 1,305
Registered: ‎06-12-2011
Message 19 of 19 (302 Views)

Re: Marco and VBA Programing Help

01-13-2013 07:34 PM in reply to: AJ1227

Hi AJ1227,

 

It looks the original question in this thread is about priting PDF but your newest question is not relevant. Could you log a new post with the new question ' Is there at least an option to link revision tags to the revision table so that when the table is deleted the tags are removed also' ? It will be more clear for the peers here to jump into.

 

In addition, please remember to attach a snapshot to show what you meant by "revision tags". 



Xiaodong Liang
Developer Technical Services
Autodesk Developer Network

Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Are You Going To Be @ AU 2014? Feel free to drop by our AU topic post and share your plans, plug a class that you're teaching, or simply check out who else from the community might be in attendance. Ohh and don't forgot to stop by the Autodesk Help | Learn | Collaborate booths in the Exhibit Hall and meet our community team if you get a chance!