Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations MintJulep on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Reading "SW-File Name" using VB6

Status
Not open for further replies.

Standing

Mechanical
Jan 14, 2002
1,578
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?

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

Bradley
 
Replies continue below

Recommended for you

That shorthand only works within the SW custom property context, no within VB.

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:
Public Function ParsePath(FullString As String, ParseChar As String, FromEnd As Long) As Variant
[COLOR=green]
'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
[/color]
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

[COLOR=green]'reverse string if parsing from right[/color]
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

[bat]"When everyone is thinking alike, no one is thinking very much." --Eckhard Schwarz (1930--2004)[bat]
 
Thanks TheTick
I will give it a go.

Bradley
 
Oops, don't forget
Code:
End Function
at the end.
 
Just noticed some other lines at the end were missing!
The whole thing, from the top:
Code:
Public Function ParsePath(FullString As String, ParseChar As String, FromEnd As Long) As Variant
'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
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor