×
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

Reading Custom Properties from a Part

Reading Custom Properties from a Part

Reading Custom Properties from a Part

(OP)
I wrote a macro to automate filling in custom properties.  For example, to make the custom property DESCRIPTION1="Widget"

Set swApp = Application.SldWorks
Set swDoc = swApp.ActiveDoc
swDoc.CustomInfo2("", "DESCRIPTION1") = "Widget"

Now I want to read in an existing description in a part, and if it exists, reuse it.  How can I read it in?

(Sorry if it is obvious, I couldn't find the answer)

Thanks,

Steve

RE: Reading Custom Properties from a Part

You may not need a macro (nor want to use one) for this if you are working with trying to automate drawing creation.  SolidWorks has a built in function to link drawing annotations to custom properties of the part, and it auto-updates those when the part changes.

Matt Lorono
CAD Engineer/ECN Analyst
Silicon Valley, CA
Lorono's SolidWorks Resources
Co-moderator of Solidworks Yahoo! Group
and Mechnical.Engineering Yahoo! Group

RE: Reading Custom Properties from a Part

(OP)
I have a custom macro to put in custom props, and I am modifiying existing parts.  If the description is still valid, I don't want to retype it.  So I just want to read the description in.

RE: Reading Custom Properties from a Part

Steve,

Try this:

Dim swApp as SldWorks.SldWorks
Dim swModeal as SldWorks.ModelDoc2
Dim swCusPropMgr as SldWorks.CustomPropertyManager
Dim AddStatus as Long
Dim Value as String
Dim ResValue as String

'add/create custom property
AddStatus = swCusPropMgr.Add2("Description", swCustomInfoText, "Widget")

'get custom property and...
swCusPropMgr.Get2 "Description", Value, ResValue

'display it
Msgbox "Value for Description is: " & Value

Hope this helps.

Best regards,
 

Chris Gervais
Application Engineer
CSWP, CSWST

RE: Reading Custom Properties from a Part

(OP)
Chris,

I pasted that into a new sub, and got a VB error 91, object variable or With block variable not set on this line

AddStatus = swCusPropMgr.Add2("Description", swCustomInfoText, "Widget")

Any ideas?

Thanks,

Steve

RE: Reading Custom Properties from a Part

I'd say make a UserForm with a TextBox and an OK button.  Link the TextBox to the Description, and if it's there, it will fill it in.  If it's not there, it will be blank.  That way you can change it if needed, or leave it how it is if it's correct.

I've never used the CustomPropertyManager, so this method may be a bit outdated, but it works.

Here are some bits and pieces from something I have already made:

Private Sub UserForm_Initialize()
     TextBox1.Text = swDoc.GetCustomInfoValue("", "DESCRIPTION")

Private Sub CommandButton1_Click()
     swDoc.DeleteCustomInfo2 "", "DESCRIPTION"
     swDoc.AddCustomInfo3 "", "DESCRIPTION", 30, TextBox1.Text

If you don't want to use the UserForm, you can condense it into an If/Then statement.  I just like the UserForm because it shows you the description as is, and you have the option to leave it alone, modify it, or add it if it's blank.

 

RE: Reading Custom Properties from a Part

I assume you are talking about copying a property to a drawing from the part or assembly in the drawing.

The path to get to the part is a bit convoluted, but you can get there.  From the drawing, you need to determine which view is the view from which properties are taken.    Once you have the view, you connect to the part from there.

batHonesty may be the best policy, but insanity is a better defense.bat
http://www.EsoxRepublic.com-SolidWorks API VB programming help

RE: Reading Custom Properties from a Part

(OP)
gopack,

That is what I needed.  I just did

DESC = swDoc.GetCustomInfoValue("", "DESCRIPTION")

and I got what I need.

It's a very straightforward command, but in all my looking I never found it.

Thanks,

Steve

RE: Reading Custom Properties from a Part

I would amend gopack's script just a little.  There is no need to delete the custom info.

First, change the property using swDoc.CustomInfo2, then swDoc.AddCustomInfo3 "", "DESCRIPTION", 30, TextBox1.Text.

Instead of blindly deleting the property, this would simply change the property if it is already there and then add it if is not already there.

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