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
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
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
RE: Reading Custom Properties from a Part
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
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'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
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.
http://www.EsoxRepublic.com-SolidWorks API VB programming help
RE: Reading Custom Properties from a Part
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
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
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.