Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

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

Visual Basic: Adding custom property to file with macro

Status
Not open for further replies.

aromech

Mechanical
Joined
May 29, 2003
Messages
24
Location
US
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
 
Se also thread559-125139

[cheers]
Making the best use of this Forum. faq559-716
How to get answers to your SW questions. faq559-1091
Helpful SW websites every user should be aware of. faq559-520
 
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)
 
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
 
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!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top