×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Visual Basic: Adding custom property to file with macro

Visual Basic: Adding custom property to file with macro

Visual Basic: Adding custom property to file with macro

(OP)
All I'm trying to do (as that famous line goes) is run a macro that will automatically add a custom property to a file. I'm going to be running it multiple times after I get this working. The property is LibraryChecked and the value is going to be "Yes" of type Text. Not a YesOrNo type.

Here's the code I have to start. If its confusing its because I'm confused. Can anyone help me with this?

Code:
Dim swApp          As Object
Dim Part           As Object
Dim boolstatus     As Boolean
Dim longstatus     As Long, longwarnings As Long
Dim FeatureData    As Object
Dim Feature        As Object
Dim Component      As Object
Dim blnRetval      As Boolean


Sub main()

Set swApp = Application.SldWorks

Set Part = swApp.ActiveDoc

Part.FileSummaryInfo



'blnRetval = ModelDoc.AddCustomInfo3("", "LibraryChecked", swCustomInfoText, "Yes")

'blnRetval = Part.AddCustomInfo3("", "LibraryChecked", swCustomInfoText, "Yes")

'blnRetval = ModelDoc.Save3(swSaveAsOptions_Silent, lngErr, lngWarn)

End Sub
__________________
Jeremy (VB 6.0)
Every man dies, but not every man lives. - William Wallace

RE: Visual Basic: Adding custom property to file with macro

It looks like the code is already there, but you don't need the 'blnretval=modelDoc.addcustominfo3' line, since you've already declared Part as your ModelDoc2 object.

The last line would also read:

blnRetval = Part.Save3(swSaveAsOptions_Silent, lngErr, lngWarn)

RE: Visual Basic: Adding custom property to file with macro

(OP)
Thanks for the advice, following is the code that I have now.  Can I just do a Part.Save2?  What is the difference between that and the longer line I'm using?

Somehow, it actually works.  I don't understand what the variable blnRetval is doing, but anyway, I run the macro and it just goes to an error.  I click cancel, stop, whatever and when I run it a second time, that's when it enters this information into the property list.  How can I do it cleanly?

Dim swApp          As Object
Dim Part           As Object
Dim boolstatus     As Boolean
Dim longstatus     As Long, longwarnings As Long
Dim FeatureData    As Object
Dim Feature        As Object
Dim Component      As Object
Dim blnRetval      As Boolean


Sub main()

Set swApp = Application.SldWorks

Set Part = swApp.ActiveDoc

Part.FileSummaryInfo


blnRetval = Part.AddCustomInfo3("", "LibraryChecked", swCustomInfoText, "Yes")

blnRetval = Part.Save3(swSaveAsOptions_Silent, lngErr, lngWarn)

End Sub

RE: Visual Basic: Adding custom property to file with macro

(OP)
Okay, I don't know how, but I figured out how to make it work.  I didn't need that line of loading the summaryinfo as I first thought.  It's ridiculously simple and I'm glad I stumbled across a solution.  Thanks for the help!

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources