Inventor General Discussion

Inventor General Discussion

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

Macro for Inserting text and current date

1574 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,986
Registered: ‎03-08-2006
Message 2 of 5 (1,564 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,544 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,986
Registered: ‎03-08-2006
Message 4 of 5 (1,541 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,986
Registered: ‎03-08-2006
Message 5 of 5 (1,528 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.





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!