Get Value By Name? (SWAPI)
Get Value By Name? (SWAPI)
(OP)
You can set properties and other values, such as dimensions, to notes via SW Addressing, For example:
DWG Number: $PRP:"SW-File Name"
Scale: $PRP:"SW-Sheet Scale"
Current Sheet: $PRP:"SW-Current Sheet"
Total Sheets: $PRP:"SW-Total Sheets"
Weight: "SW-Mass@@Default@partnum.SLDASM" LBS
But is it possible to set these values to Variables in VB...
Such as:
Where Y() is the qualified function that retrieves the values from SolidWorks, and assigns to X...?
If this is confusing, please say so, and I will try to clairify...
Thanks in advance,
-Josh
DWG Number: $PRP:"SW-File Name"
Scale: $PRP:"SW-Sheet Scale"
Current Sheet: $PRP:"SW-Current Sheet"
Total Sheets: $PRP:"SW-Total Sheets"
Weight: "SW-Mass@@Default@partnum.SLDASM" LBS
But is it possible to set these values to Variables in VB...
Such as:
CODE
Dim X as String
X = Y("SW-Mass@@Default@partnum.SLDASM")
X = Y("SW-Mass@@Default@partnum.SLDASM")
Where Y() is the qualified function that retrieves the values from SolidWorks, and assigns to X...?
If this is confusing, please say so, and I will try to clairify...
Thanks in advance,
-Josh
When dealing with computers, there are 10 things you need to know: one, zero, and the rest is Binary.
-Josh S






RE: Get Value By Name? (SWAPI)
:)
Evan T. Basalik, MCSD
--------------------------------
It's all about prioritization...
RE: Get Value By Name? (SWAPI)
you can make a reference to other values by using strings to reference them...
such as...
If your File is named "12345.123.slddrw", and you place:
$PRP:"SW-File Name"
in a note, the note will display: "12345.123"
If an assembly (12345.123.sldasm) weighs 123.5 lbs, and you place:
"SW-Mass@@Default@12345.123.SLDASM" LBS
in a note, the note will display: "123.5 LBS"
My question is if there is a way to get these values the same way via VB, to set them to a variable rather than display them in a note...
For use with a Form, or exporting them to a text file, etc...
When dealing with computers, there are 10 things you need to know: one, zero, and the rest is Binary.
-Josh S
RE: Get Value By Name? (SWAPI)
Evan T. Basalik, MCSD
--------------------------------
It's all about prioritization...
RE: Get Value By Name? (SWAPI)
In the drawing template, under the Custom tab in Summary Info (accessed from File->Properties), add a File Name (or whatever you want to call it) property which links to the SolidWorks file name property using $PRP:"SW-File Name".
In the VBA code you can then just access the file name value by setting a variable equal to swModel.GetCustomInfoValue("", "File Name").
This seems like a bass-ackwards way of doing it, since that file name property should already be available somewhere already, but it does work.
RE: Get Value By Name? (SWAPI)
Evan T. Basalik, MCSD
--------------------------------
It's all about prioritization...
RE: Get Value By Name? (SWAPI)
CODE
Dim swModel As Object
Dim swDraw As Object
Dim sFileName As String
Dim sPathName As String
Dim nErrors As Long
Dim nWarnings As Long
Dim nRetval As Long
Dim bShowMap As Boolean
Dim bRet As Boolean
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
Set swDraw = swModel
sPathName = swModel.GetPathName
sPathName = Left(sPathName, Len(sPathName) - 6)
sFileName = swModel.GetTitle
sFileName = Left(sFileName, Len(sFileName) - 9)
RE: Get Value By Name? (SWAPI)
Throgh this in a macro and run it...
CODE
Dim FullName As String, FileName As String, FilePath As String
With Application.SldWorks
FullName = .ActiveDoc.GetPathName
FileName = Split(FullName, "\")(UBound(Split(FullName, "\")))
FilePath = Replace(FullName, FileName, "")
End With
MsgBox "Full Name: " & FullName & vbCrLf & _
"File Name: " & FileName & vbCrLf & _
"File Path: " & FilePath & vbCrLf
End Sub
Minimum variable useage... No objects declared
Enjoy,
-Josh
When dealing with computers, there are 10 things you need to know: one, zero, and the rest is Binary.
-Josh S
RE: Get Value By Name? (SWAPI)
CODE
Dim FullName As String, FileName As String, FilePath As String
Dim FileExt As String, DrawName As String
With Application.SldWorks.ActiveDoc
FullName = .GetPathName
FileName = Split(FullName, "\")(UBound(Split(FullName, "\")))
FilePath = Replace(FullName, FileName, "")
FileExt = Split(FileName, ".")(UBound(Split(FileName, ".")))
DrawName = Replace(FileName, "." & FileExt, "")
MsgBox "Full Name: " & FullName & vbCrLf & _
"File Name: " & FileName & vbCrLf & _
"File Path: " & FilePath & vbCrLf & _
"File Ext: " & FileExt & vbCrLf & _
"Model Name: " & DrawName & vbCrLf & _
"Title: " & .GetTitle
End With
End Sub
Note that you can also use ModelDoc.GetTitle but for drawings, it will return the sheet name as well...
So, if you just want the Drawing name, Do this...
DrawingName = Split(ModelDoc.GetTitle & " - ", " - ")(0)
When dealing with computers, there are 10 things you need to know: one, zero, and the rest is Binary.
-Josh S