×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Reading "SW-File Name" using VB6

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?

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

RE: Reading "SW-File Name" using VB6

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

'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

"When everyone is thinking alike, no one is thinking very much." --Eckhard Schwarz (1930--2004)
http://www.EsoxRepublic.com

RE: Reading "SW-File Name" using VB6

(OP)
Thanks TheTick
I will give it a go.

Bradley

RE: Reading "SW-File Name" using VB6

Oops, don't forget

CODE

End Function
at the end.

RE: Reading "SW-File Name" using VB6

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

RE: Reading "SW-File Name" using VB6

(OP)
Thanks again TheTick

Bradley

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources