Inventor General Discussion

Reply
Active Member
jjkoz78
Posts: 8
Registered: ‎01-05-2012
Message 1 of 5 (1,456 Views)

Macro for Inserting text and current date

1456 Views, 4 Replies
01-05-2012 11:43 AM

Hi,

I'm completely new to VBA, so I really don't know anything about the code, and it seems like everywhere I look for help it's assumed that I should already know a lot about it.  I'm trying to find a macro that will insert text into a certain spot on my drawing.  I want to put it on a button so that when I click the button it inserts "REVISION - 12/5/12", or whatever the current date is, into my title block.  Does anything like this exist?

 

Thanks

*Expert Elite*
Curtis_Waguespack
Posts: 2,815
Registered: ‎03-08-2006
Message 2 of 5 (1,446 Views)

Re: Macro for Inserting text and current date

01-05-2012 01:28 PM in reply to: jjkoz78

Hi jjkoz78, 

 

Here's a basic step-by-step to do this with iLogic code:

http://inventortrenches.blogspot.com/2012/01/creating-basic-ilogic-rule-with-event.html

 

I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com

 

 



  solution.png  Did you find this reply helpful ? If so please use the Accept as Solution or  Kudos button below.





Active Member
jjkoz78
Posts: 8
Registered: ‎01-05-2012
Message 3 of 5 (1,426 Views)

Re: Macro for Inserting text and current date

01-06-2012 05:50 AM in reply to: Curtis_Waguespack

It looks like it would probably help (if I can get everything in place first).  I'm using Inventor 2008 and don't have iLogic.  I've tried to download it, but I have to link up my subscription to my user account on Autodesk's website, and it's telling me that my account has been closed or canceled or something like that.  Isn't there just some simple VBA code out there somewhere that can do what I'm wanting?  I can't believe it's this complicated.

*Expert Elite*
Curtis_Waguespack
Posts: 2,815
Registered: ‎03-08-2006
Message 4 of 5 (1,423 Views)

Re: Macro for Inserting text and current date

01-06-2012 05:59 AM in reply to: jjkoz78

Hi jjkoz78,

 

I do have a VBA sample that will do what you want also. I'll try to post it in a hour or so. Are you familiar with setting the code up to run?

 

I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com

 

 



  solution.png  Did you find this reply helpful ? If so please use the Accept as Solution or  Kudos button below.





*Expert Elite*
Curtis_Waguespack
Posts: 2,815
Registered: ‎03-08-2006
Message 5 of 5 (1,410 Views)

Re: Macro for Inserting text and current date

01-06-2012 08:06 AM in reply to: jjkoz78

Hi jjkoz78,

 

Here is the VBA code for the time and date, as well as an attached sample file. The sample file is an Inventor 2010 file, sorry that's as far back as I can go.

 

I found this on the Customization Forum some time ago (thanks to whom ever wrote it originally). This code is set up to write the system time and date to custom iProperties when the file is saved, so you need to have the text fields set up to look at the custom iProperties in the file ahead of time (such as in the titleblock or border).

 

I've had some issues with 64 bit systems and other VBA code, but I think this works okay. However, it's been a while since I've used it.

 

To place this in your Inventor drawing file, open the file and then Press ALT + F11 to open the VBA editor. Locate the file you want to add the code to in the project browser and then set the ThisDocument node for that file active and paste in the code as shown in the attached image.

 

I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com

 

 

 

Option Explicit


Public Sub AutoSave()


Call AddSysDateTime


End Sub

Public Sub AddSysDateTime()

Dim oPropSet

On Error Resume Next



'Check if the active document is a Drawing

If ThisApplication.ActiveDocumentType = kDrawingDocumentObject Then



'Add a custom property "SysDate" with system date

Set oPropSet = ThisApplication.ActiveDocument.PropertySets("{D5CDD505-2E9C-101B-9397-08002B2CF9AE}")

'As a workaround the property must be delete because it can not be changed

oPropSet.Item("SysDate").Delete

Call oPropSet.Add(Format(Date, "mm/dd/yyyy"), "SysDate")



'Add a custom property "SysTime" with system time

Set oPropSet = ThisApplication.ActiveDocument.PropertySets("{D5CDD505-2E9C-101B-9397-08002B2CF9AE}")

'As a workaround the property must be delete because it can not be changed

oPropSet.Item("SysTime").Delete

Call oPropSet.Add(Format(Time, "h:mm:ss am/pm"), "SysTime")



'Still having some problems that the last property does not update correct

Call RefreshProperties



End If


End Sub

Private Sub RefreshProperties()

Dim oPropSet

Set oPropSet = ThisApplication.ActiveDocument.PropertySets("{D5CDD505-2E9C-101B-9397-08002B2CF9AE}")

Call oPropSet.Add("", "MyDummy")

oPropSet.Item("MyDummy").Delete


End Sub

 



  solution.png  Did you find this reply helpful ? If so please use the Accept as Solution or  Kudos button below.





You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Ask the Community


Inventor Exchange Apps

Created by the community for the community, Autodesk Exchange Apps for Autodesk Inventor helps you achieve greater speed, accuracy, and automation from concept to manufacturing.

Connect with Inventor

Twitter

Facebook

Blogs

Pinterest

Youtube