SW Custom Property API
SW Custom Property API
(OP)
All,
I was hoping someone could assist me in figuring this out. I have limited knowledge in API. What I was trying to do is this. We have Custom Properties in our part files like: "Release/ECO # Date" or "New Rev". I wanted to run a macro where I could grab the existing Value we have in "Release/ECO # Date", assign a new property called "ReleaseDate" and write that info to it. Would anyone have any examples or ideas??
Thank You
I was hoping someone could assist me in figuring this out. I have limited knowledge in API. What I was trying to do is this. We have Custom Properties in our part files like: "Release/ECO # Date" or "New Rev". I wanted to run a macro where I could grab the existing Value we have in "Release/ECO # Date", assign a new property called "ReleaseDate" and write that info to it. Would anyone have any examples or ideas??
Thank You






RE: SW Custom Property API
Bradley
RE: SW Custom Property API
CODE
Public Enum swUserPreferenceIntegerValue_e
swAutoSaveInterval = 3
End Enum
Sub main()
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim nStart As Single
Dim i As Long
Dim bRet As Boolean
Dim propRet As Boolean
Dim runTime As String
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
' Turn off automatic save
bRet = swApp.SetUserPreferenceIntegerValue(swAutoSaveInterval, 0)
nStart = Timer
bRet = swModel.ForceRebuild3(False)
runTime = Timer - nStart & " seconds"
propRet = swModel.AddCustomInfo3("", "LastRebuildTime", swCustomInfoText, runTime)
End Sub
This code is almost straight from the solidworks API help, so send SW your thanks if you can make use of the code!
Stefan Hamminga
EngIT Solutions
CSWP/Mechanical designer/AI student
RE: SW Custom Property API
RE: SW Custom Property API
Please, people who have use it to read and update custom properties without opening files, post some of your code.
RE: SW Custom Property API
Of course, for this to work you have do download and register the dll first, and include it in the references.
Hope this helps!
-Josh
Sub DoTheSwap()
Dim PropReader As DSOleFile.PropertyReader
Dim DocProps As DSOleFile.DocumentProperties
Dim CustProp As DSOleFile.CustomProperty
Dim PropVal As String
Dim fso As Scripting.FileSystemObject
Dim sFile As String
Dim sFilesPath As String
Dim sFilesList As Scripting.TextStream
Dim CurPath As String
Dim OldJobNo As String
Dim NewJobNo As String
Dim OldProjName As String
Dim NewProjName As String
Dim OldMcNo As String
Dim NewMcNo As String
Dim OldDrawn As String
Dim NewDrawn As String
Dim CurRow As Long
sFilesPath = "C:\Documents and Settings\tnjbrady\Desktop\out.txt"
Set fso = CreateObject("Scripting.FileSystemObject")
Set sFilesList = fso.OpenTextFile(sFilesPath, ForReading)
Set PropReader = New DSOleFile.PropertyReader
OldJobNo = "TC04152"
NewJobNo = "TC05083"
OldMcNo = "AS134"
NewMcNo = "AS144"
OldProjName = "STEPPER SUB-ASSY CELL"
NewProjName = "STEPPER SUB-ASSY #2"
OldDrawn = "John Doe"
NewDrawn = "Jim Smith"
CurRow = 1
While Not sFilesList.AtEndOfStream
CurPath = sFilesList.ReadLine
Set DocProps = PropReader.GetDocumentProperties(CurPath)
For Each CustProp In DocProps.CustomProperties
On Error GoTo SKIP
PropVal = CustProp.Value
ActiveSheet.Cells(CurRow, 1).Value = CustProp.Name
ActiveSheet.Cells(CurRow, 2).Value = PropVal
PropVal = Replace(PropVal, OldJobNo, NewJobNo)
PropVal = Replace(PropVal, OldProjName, NewProjName)
PropVal = Replace(PropVal, OldMcNo, NewMcNo)
PropVal = Replace(PropVal, OldDrawn, NewDrawn)
CustProp.Value = PropVal
ActiveSheet.Cells(CurRow, 3).Value = PropVal
CurRow = CurRow + 1
SKIP:
Next
Wend
End Sub
RE: SW Custom Property API
areco = Part.GetCustomInfoValue("", "Release/ECO # Next")
ar = Part.GetCustomInfoValue("", "Release/ECO #")
arecodate = Part.GetCustomInfoValue("", "Release/ECO # Date Next")
aBool = Part.AddCustomInfo3("", "AR-ECO #", 30, areco)
aBool = Part.AddCustomInfo3("", "AR #", 30, ar)
aBool = Part.AddCustomInfo3("", "AR-ECO Date", 30, arecodate)
What this is doing is pulling the existing part custom property info "Release/ECO # Next", then writing a new property "AR-ECO #" and placing the existing info into that new property.
Now what I would like to do is, if there is no value in "Release/ECO # Next" field, then have it look to another existing field, "AR" and place that information in "AR-ECO #". Any ideas??
Thanks Again.
RE: SW Custom Property API
areco = Part.GetCustomInfoValue("", "Release/ECO # Next")
put
if areco = "" then
areco = Part.GetCustomInfoValue("", "AR")
end if
RE: SW Custom Property API
Thank You!! You just made my day. Appreciate the help!
RE: SW Custom Property API
ht
-Shaggy
RE: SW Custom Property API