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: 

Title Block - Copyright Year

3 REPLIES 3
SOLVED
Reply
Message 1 of 4
bennywise578
1235 Views, 3 Replies

Title Block - Copyright Year

Hey Everyone,

 

So, I am trying to add a copyright year to a title block in a drawing template file used through out my company. I want to base the year off of the creation date property - I am trying to find a way to truncate this property such that only the year is displayed. Ideally, any time the creation date property is changed, the copyright year will also update.

 

We are currently running Inventor 2010.

 

My thoughts:

 

Normally, I would just write an iLogic rule with an event trigger, but this would require everyone to install the iLogic addin which just won't happen.

 

Even easier, I could make a custom iProperty and just have people manually type in the year when they start a new drawing - this will be worst case scenario as a ton of people will forget and I'll just make more work for myself.

 

I also have VBA code which is pretty simple:

 

Public Sub SetYear()

 

Dim oDoc As Document    

Set oDoc = ThisApplication.ActiveDocument      

  

Dim customPropSet, customPropSet2 As PropertySet    

Set customPropSet2 = oDoc.PropertySets.Item("Design Tracking Properties")    

Set customPropSet = oDoc.PropertySets.Item("Inventor User Defined Properties")       

 

Dim customProp, creationDate As Property    

Set customProp = customPropSet2.Item(1)    

Set creationDate = customPropSet.Item("CreationYear")        

 

Dim year, newYear, newerYear As String    

year = customProp.Value    

 

Dim count As Integer    

count = InStr(year, " ")    

 

newYear = Left(year, count - 1)    

newerYear = Right(newYear, 4)      

    

creationDate.Value = newerYear        

 

oDoc.Update

 

End Sub

 

The issue would be getting this VBA code to trigger and to "stick" to the template file.

 

I can just as easily write this code in VB.NET or C#, and go through the hassle of creating an add-in, but again, how would I get it to trigger and stick to the template file.

 

 

With that being said, if any one can provide suggestions to my current thoughts or any alternatives, it would be greatly appreciated. Thank you!

3 REPLIES 3
Message 2 of 4
VdVeek
in reply to: bennywise578

Have a look at Now. Hope this is the right direction for you. Don't have time now to search better, but this could help you.

 

iProperties.Value(“Project”, “Project”) = Now.ToString(“dd-mm-yyyy”) ‘Set Project to today’s date 04-08-2012
‘hh = 10 HH = 22
‘mm = 53
‘ss = 23
‘dd-mm-yyyy = 04-08-2012
‘d/m/yy = 4/8/12
‘MMMM = augustus

 

Rob.

Autodesk Inventor 2015 Certified Professional & Autodesk Inventor 2012 Certified Professional.
Message 3 of 4
jonbrabbs
in reply to: bennywise578

Hi Bennywise578,

 

To get your code to fire within the template, you need to add it to the template file. To get it to fire at some event, you need to create the ApplicationEvents bits and bobs. This is great if you only have a single template file (stored on a network rather than lots of local templates).

 

Also to get the year, you can simply use VBA.Format(VBA.Date,"yyyy").

 

The code below should update your CreationDate iProp when saved (you can change this it on new if you wish) - i've not had chance to test it...

 

Hope this helps.

 

Regards

 

Jon


Option Explicit

Private WithEvents oApplicationEvents As ApplicationEvents

Private Sub Class_Initialize()
  Set oApplicationEvents = ThisApplication.ApplicationEvents
End Sub

Private Sub Class_Terminate()
  Set oApplicationEvents = Nothing
End Sub

'Then you need to create an instance of this class so that
'the event is reacted to e.g.

Option Explicit
Dim oEventHandler As MyEventHandler

Sub listenToEvents()
  Set oEventHandler = New MyEventHandler
End Sub

Sub stopListening()
  Set oEventHandler = Nothing
End Sub

Private Sub oApplicationEvents_OnSaveDocument(ByVal DocumentObject As Document, _
                                            ByVal BeforeOrAfter As EventTimingEnum, _
                                            ByVal Context As NameValueMap, _
                                            HandlingCode As HandlingCodeEnum)
    Dim oDoc As Document
    Set oDoc = ThisApplication.ActiveDocument

    Dim customPropSet, customPropSet2 As PropertySet
    Set customPropSet2 = oDoc.PropertySets.Item("Design Tracking Properties")
    Set customPropSet = oDoc.PropertySets.Item("Inventor User Defined Properties")

    Dim customProp, creationDate As Property
    Set customProp = customPropSet2.Item(1)
    Set creationDate = customPropSet.Item("CreationYear")
'
'    Dim year, newYear, newerYear As String
'    year = customProp.Value
'
'    Dim count As Integer
'    count = InStr(year, " ")
'
'    newYear = Left(year, count - 1)
'    newerYear = Right(newYear, 4)

    creationDate.Value = Format(VBA.Date, "yyyy")
    oDoc.Update
End Sub

 

 

///////////////////////////////////////////////////////////////////////////////////////////////////
If this post helps you, please give kudos.
\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
Message 4 of 4
bennywise578
in reply to: jonbrabbs

So this is what I ended up doing:

 

In the document project, in the "ThisDocument" file, I put the following code:

 

Public Sub AutoSave()
Call setYear
End Sub

 

And in Module1 file (in the document project), I put the following code:

 

Public Sub setYear()

    Dim oDoc As Document

    Set oDoc = ThisApplication.ActiveDocument       

    Dim customPropSet, customPropSet2 As PropertySet

    Set customPropSet2 = oDoc.PropertySets.Item("Design Tracking Properties")

    Set customPropSet = oDoc.PropertySets.Item("Inventor User Defined Properties")

 

    Dim customProp, creationDate As Property

    Set customProp = customPropSet2.Item(1)

    Set creationDate = customPropSet.Item("CreationYear")

 

    Dim year, newYear, newerYear As String     year = customProp.Value

    Dim count As Integer     count = InStr(year, " ")

    newYear = Left(year, count - 1)

    newerYear = Right(newYear, 4)

    creationDate.Value = newerYear

    oDoc.Update

End Sub

 

Everytime I save the drawing, the custom iProperty "CreationYear" is set to just the year of the Creation Date iProperty. I've heard this might be bad practice, but it's working exceptionally well.

 

Thanks everyone for your time - I appreciate it.

 

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

Post to forums  

Autodesk Design & Make Report