Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations IDS on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to create a macro to update swSumInfoCreateDate

Status
Not open for further replies.

kreker

Mechanical
Nov 4, 2004
13
I'm trying to create a macro to update the swSumInfoCreateDate field on an open file to today's date. I can get today's date with "Date$" and I can assign a string date to a variable but I cannot get the date into the swSumInfoCreateDate field. Here is my code. Please help. Thanks!!


Option Explicit

Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long
Dim swApp As SldWorks.SldWorks
Dim swmodel As SldWorks.ModelDoc2

Sub main()

On Error Resume Next

Dim UserName As String
UserName = Space(40)

Dim DateCreated As String
'DateCreated = Date$
DateCreated = "5/9/2010 2:19:50 PM"

UserName = "CAS"

Set swApp = Application.SldWorks
Set swmodel = swApp.ActiveDoc
swmodel.SummaryInfo(swSumInfoAuthor) = UserName
swmodel.SummaryInfo(swSumInfoCreateDate) = DateCreated

Debug.Print DateCreated
Debug.Print swmodel.SummaryInfo(swSumInfoCreateDate)
Debug.Print UserName


If Not Err.Number = 0 Then MsgBox "An unexpected error occured.", vbOKOnly + vbCritical, "Setting Author summary fails."


End Sub
 
Replies continue below

Recommended for you

Creation dates are usually not accessible and not writeable.

Curious why one would need to do this?
 
TheTick,

Thanks for the reply. The reason is that we do quite a bit of design copying with pack and go and when we do that the creation date of the original file comes with and we would like to update that to when we did the pack and go. Thanks! Any ideas?
 
I've had some luck changing file create dates by going into the bitses and bytses and changing it there. That's risky hacksmanship, though. You do this by opening the SW file in a text editor like Notepad or Wordpad.

I learned this when I was attempting to play god w/ SW files' internal IDs. I even had a small bit of success, and was able to fool SW into thinking one file was a clone of another when it was not.

[bat]Honesty may be the best policy, but insanity is a better defense.[bat]
-SolidWorks API VB programming help
 
I'll check it out. Does my code look like it would work or is the field just uneditable? Thanks!
 
If you can read the property and you can write to similar properties, it's probably not API accessible.
 
That could be because I can do a debug.print on the field and get a return. The only other thing I can think of is that I'm trying to populate the field with an incorrect format for the date. I used to do quite a bit of SQL and I remember dates and date formats can be fussy. Do you know what format I should be providing the date for the swSumInfoCreateDate? MM/DD/YYYY TIME,ETC....

Please advise. Thanks!
 
Sorry. That last request just bounced right off the outer limits of my knowledge.
 
Thank all of you for all your help, I'm finding out from several spots that this field is read only.
 
Do you really have customers snooping into create dates? Oy! Though you could always tell them that's when the template was created.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor