SolidWorks custom props question

We are using SolidWorks 2007 SP2.2 and we are trying to write some custom code to be able to change the material codes we use in custom
props. In our part models, we currently have a custom prop called 'matl'. In the value / text expression field we have code with a text prefix and then a link to a dimension or two. An example would be: MFB"D2@ snipped-for-privacy@A300107.SLDPRT"x"D1@ snipped-for-privacy@A300107.SLDPRT" We want to change this to B-SFB-304-"D2@ snipped-for-privacy@A300107.SLDPRT"x"D1@ snipped-for-privacy@A300107.SLDPRT"
We need to be able to maintain the parametric links to the dimensions and replace the text prefix. Any ideas on how we get to this field of the custom prop so we can copy it? As far as we can see, we can only read the evaluated value through the API.
Using VB6 and a dll called DSOfile.dll, we have managed to write a string with a parametric link string back to a custom prop, but we have to open the file in SW to get the evaluated field to update. Is it possible to update the evaluated field without opening the file in SW? We got DSOfile from here: http://support.microsoft.com/kb/224351
Another problem we are having is once the string has been written in and the file is opened in SW to update it, the name field that is read through DSOfile.dll dissappears! If you try and read any custom prop with a parametric link in it with DSOfile.dll, the name field is not available.
We need to be able to automate this process because we have approximately 140 000 files to change.
Any ideas?
Add pictures here
<% if( /^image/.test(type) ){ %>
<% } %>
<%-name%>
Add image file
Upload
Hi,
The SW API allows you to read and write custom properties in any SW document. Here's some code that gets the MATL property from the model, replaces MFB with B-SFB-304 and saves it back. Parametric links are maintained as well. It's a crude example (not much error checking) but it should get you started down the right path. Once the macro is fully developed you should be able to batch update groups of models with it via "Run Custom Task" inside SW Task Scheduler.
Cut and paste the sample code into a new macro or email me for the file.
best regards, go
Option Explicit
Sub main() Dim swApp As SldWorks.SldWorks Dim swDoc As SldWorks.ModelDoc2 Dim swCPM As SldWorks.CustomPropertyManager Dim sVal As String Dim sEval As String Dim sNewVal As String Dim uRv As Long
On Error Resume Next
Set swApp = Application.SldWorks Set swDoc = swApp.ActiveDoc Set swCPM = swDoc.Extension.CustomPropertyManager("")
' get the custom prop by name swCPM.Get2 "matl", sVal, sEval
If sVal = "" Then MsgBox "MATL property doesn't exist.", vbInformation Else MsgBox "Current Material = " & sVal
' replace material designation sNewVal = Replace$(sVal, "MFB", "B-SFB-304", 1, , vbTextCompare)
' if the original and new values aren't equal then replace found a match ' so now we need to save it If sNewVal <> sVal Then
' update the value uRv = swCPM.Set("matl", sNewVal) If uRv = 0 Then MsgBox "Value Updated : " & sNewVal, vbExclamation Else MsgBox "Update failed.", vbCritical End If Else MsgBox "Material wasn't updated, MFB not found.", vbInformation End If End If
Set swCPM = Nothing Set swDoc = Nothing Set swApp = Nothing End Sub
Add pictures here
<% if( /^image/.test(type) ){ %>
<% } %>
<%-name%>
Add image file
Upload
Perhaps try "Propagator", available at <http://www.customsolids.com
Add pictures here
<% if( /^image/.test(type) ){ %>
<% } %>
<%-name%>
Add image file
Upload
Looks like Propagator will do the job for them. The trial version doesn't appear to let you substitute words (that feature is disabled), I assume it's enabled on a purchased version. Thanks for the tip, I wasn't aware of the program.
Add pictures here
<% if( /^image/.test(type) ){ %>
<% } %>
<%-name%>
Add image file
Upload

Polytechforum.com is a website by engineers for engineers. It is not affiliated with any of manufacturers or vendors discussed here. All logos and trade names are the property of their respective owners.