×
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

Creating or editting properties with a macro

Creating or editting properties with a macro

Creating or editting properties with a macro

(OP)
I have a written a macro to populate the properties table for new parts, I also want to use it to update the table for older parts that weren't created with the correct template.

I'm new to macros and vb so I need something simple. Using some borrowed code from this site I've manage to get something working:

Success = swModel.AddCustomInfo3("", "Finish", swCustomInfoText, "")
swModel.CustomInfo2("", "Finish") = "Natural"

This will populate the property 'finish' with the value 'natural' (our default) but if the property has already been set to something else then it overwrites it.  I don't want that to happen I want it to keep the current value.


 

RE: Creating or editting properties with a macro

(OP)
I've just reread that and it might not be that clear.  I need it to:

1. if the property doesn't exist, create it and populate it with a set value
2. if the property exists then keep the current the value

RE: Creating or editting properties with a macro

Quote (SW API Help):


Description

This property gets and sets the file custom information for the SolidWorks document.

 

Syntax (OLE Automation)

value = ModelDoc2.CustomInfo2 (configuration, fieldName) (VB Get property)

ModelDoc2. CustomInfo2(configuration, fieldName) = value (VB Set property)

 

value = ModelDoc2.GetCustomInfo2(configuration, fieldName) (C++ Get property)

ModelDoc2.SetCustomInfo2(configuration, fieldName, value) (C++ Set property)

 

Input:
 (BSTR) configuration
 Name of the configuration (see Remarks)
 
Input:
 (BSTR) fieldName
 Name of field
 
Property:
 (BSTR) value
 Text in the field
 

If value in the "get" property exist and <> "" then do not change it else delete it and add it with the new value.

Quote (SW API Help):


This method is obsolete and has been superseded by ModelDocExtension::CustomPropertyManager.
Thing get a little bit more complicated with CustomPropertyManager.
 

RE: Creating or editting properties with a macro


Get rid of your second line.  The AddCustomInfo3 function will not overwrite an existing property.  You can verify this by checking the value of the variable "Success" with a message box.  All you need to do to get your desired behavior is put "Natural" in your AddCustomInfo3 line and get rid of the next line.  So you'll have:

CODE

Success = swModel.AddCustomInfo3("", "Finish", swCustomInfoText, "Natural")

-handleman, CSWP (The new, easy test)

RE: Creating or editting properties with a macro

(OP)
Thanks Handleman, that's got it

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