Reading "SW-File Name" using VB6
Reading "SW-File Name" using VB6
(OP)
Using SW 2005 & VB6 I am trying to read "$PRP:" & Chr(34) & "SW-File Name" & Chr(34) as a value that I can compare to our BOMnumber. What I get in the text box is "$PRP:" & Chr(34) & "SW-File Name" & Chr(34). What I am looking for is the value for SW-File Name. It shows up in the model properties just fine as:
Property Name Type Value / Text Expression Evaluated Value
PartNo1 Text $PRP:"SW-File Name" 645998
Anyone have an idea how I can set PartNo1 equal to the file name?
Property Name Type Value / Text Expression Evaluated Value
PartNo1 Text $PRP:"SW-File Name" 645998
Anyone have an idea how I can set PartNo1 equal to the file name?
CODE
Option Explicit
Const swDocPART = 1
Const swDocASSEMBLY = 2
Const swDocDRAWING = 3
Dim PartNo1 As String
Dim PartNoUpdate As String
Private Part As Object
Private Sub Form_Load()
Dim swApp As Object
Dim Model As Object
Dim Part As Object
Dim RetVal As Boolean
Dim PartNo1 As String
Set swApp = CreateObject("SldWorks.Application")
Set Part = swApp.ActiveDoc
Set Model = swApp.ActiveDoc
PartNo1 = "$PRP:" & Chr(34) & "SW-File Name" & Chr(34)
txtPartNo1.Text = PartNo1
End Sub
Const swDocPART = 1
Const swDocASSEMBLY = 2
Const swDocDRAWING = 3
Dim PartNo1 As String
Dim PartNoUpdate As String
Private Part As Object
Private Sub Form_Load()
Dim swApp As Object
Dim Model As Object
Dim Part As Object
Dim RetVal As Boolean
Dim PartNo1 As String
Set swApp = CreateObject("SldWorks.Application")
Set Part = swApp.ActiveDoc
Set Model = swApp.ActiveDoc
PartNo1 = "$PRP:" & Chr(34) & "SW-File Name" & Chr(34)
txtPartNo1.Text = PartNo1
End Sub
Bradley






RE: Reading "SW-File Name" using VB6
Try using retval = ModelDoc2.GetPathName and then stripping off the directory and .sld*** suffix.
How does one remove the directory from the full path? Here's one of my favorite bits of VB kung fu:
CODE
'divides a string on either side of a specified character
'FromEnd: =-1: first ParseChar from left; =1: first ParseChar from right
'ParsePath(1)=left side of dividing character from ParseChar
'ParsePath(2)=dividing character
'ParsePath(3)=right side
'returns all vbNullstrings if ParseChar not found
If Len(ParseChar) < 1 Then Exit Function
Dim ParseParams(1 To 3) As String
Dim ParseString As String 'working copy of FullString
Dim ParseCharString As String 'working copy of ParseChar
Dim ParseCharPos As Long
Dim iParse As Integer 'index for loop
Dim TempString As String 'for swapping positions
For iParse = 1 To 3
ParseParams(iParse) = vbNullString
Next
'reverse string if parsing from right
If Sgn(FromEnd) = -1 Or Val(FromEnd) = 0 Then 'from LEFT
ParseString = FullString
ParseCharString = ParseChar
Else 'from RIGHT
ParseString = StrReverse(FullString)
ParseCharString = StrReverse(ParseChar)
End If
ParseCharPos = InStr(1, ParseString, ParseCharString, vbTextCompare)
If ParseCharPos > 0 Then
ParseParams(1) = Left(ParseString, (ParseCharPos - 1))
ParseParams(2) = ParseChar
ParseParams(3) = Right(ParseString, Len(FullString) - (Len(ParseParams(1)) + Len(ParseCharString)))
If Sgn(Val(FromEnd)) = 1 Then
TempString = StrReverse(ParseParams(1))
ParseParams(1) = StrReverse(ParseParams(3))
ParseParams(3) = TempString
End If
End If
http://www.EsoxRepublic.com
RE: Reading "SW-File Name" using VB6
I will give it a go.
Bradley
RE: Reading "SW-File Name" using VB6
CODE
RE: Reading "SW-File Name" using VB6
The whole thing, from the top:
CODE
'divides a string on either side of a specified character
'FromEnd: =-1: first ParseChar from left; =1: first ParseChar from right
'ParsePath(1)=left side of dividing character from ParseChar
'ParsePath(2)=dividing character
'ParsePath(3)=right side
'returns all vbNullstrings if ParseChar not found
If Len(ParseChar) < 1 Then Exit Function
Dim ParseParams(1 To 3) As String
Dim ParseString As String 'working copy of FullString
Dim ParseCharString As String 'working copy of ParseChar
Dim ParseCharPos As Long
Dim iParse As Integer 'index for loop
Dim TempString As String 'for swapping positions
For iParse = 1 To 3
ParseParams(iParse) = vbNullString
Next
'reverse string if parsing from right
If Sgn(FromEnd) = -1 Or Val(FromEnd) = 0 Then 'from LEFT
ParseString = FullString
ParseCharString = ParseChar
Else 'from RIGHT
ParseString = StrReverse(FullString)
ParseCharString = StrReverse(ParseChar)
End If
ParseCharPos = InStr(1, ParseString, ParseCharString, vbTextCompare)
If ParseCharPos > 0 Then
ParseParams(1) = Left(ParseString, (ParseCharPos - 1))
ParseParams(2) = ParseChar
ParseParams(3) = Right(ParseString, Len(FullString) - (Len(ParseParams(1)) + Len(ParseCharString)))
If Sgn(Val(FromEnd)) = 1 Then
TempString = StrReverse(ParseParams(1))
ParseParams(1) = StrReverse(ParseParams(3))
ParseParams(3) = TempString
End If
End If
ParsePath = ParseParams
End Function
RE: Reading "SW-File Name" using VB6
Bradley