×
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

MACRO QUESTION -

MACRO QUESTION -

MACRO QUESTION -

(OP)
I can take characters from the sw file NAME and place them in the sw custom properties of the dwg using a macro. Does anybody have a macro that would allow me to take parts of a file PATH and apply them to a sw property?
ex.

file path: J:1234/abcd/567.slddwg.

custom property would read: 1234567.

RE: MACRO QUESTION -

You need to write a function or sub that parses the path string.  Start from one end of the path and chop off the bits you nees every time you come across a "\" or "/".  Use the VB Mid function to examine one character at a time in a loop that goes from 1 to Len (PathString).

batHonesty may be the best policy, but insanity is a better defense.bat
http://www.EsoxRepublic.com-SolidWorks API VB programming help

RE: MACRO QUESTION -

(OP)

      Tempval = LTrim(RTrim(Document.GetCustomInfoValue("", PartNoPropName)))
      ModelName = Mid(NewParseString(UCase(Document.GetTitle), ".SLD", 0, 0), 17, 3)


This is the line in my macro that trims the file name. I'm not sure how to change this into cutting out specific characters from a file path. I know enough about programing to change the 17 and 3 to get what I want, but anything more is a little over my head. If I could apply this part of the macro to the file path and run this part of the macro twice, that would solve my problem. I don't think it would take much effort, but i'm not sure how to do it.

RE: MACRO QUESTION -

my inefficient, slow, simplistic way of doing things.
Enjoy! Chris


Sub main()

s = "C:\123\i need a beer\456A.sldprt" 'your input

L = Len(s) 'length of the string

For X = L To 1 Step -1 'find the leftmost "\"
If Mid(s, X, 1) = "\" Then a = X
Next X

For X = L To a + 1 Step -1 'find the second leftmost \
If Mid(s, X, 1) = "\" Then b = X
Next X

For X = 1 To L 'find the rightmost \
If Mid(s, X, 1) = "\" Then c = X
Next X

For X = 1 To L 'find the .
If Mid(s, X, 1) = "." Then d = X
Next X


s1 = Mid(s, a + 1, (b - a - 1)) 'cutout the first part number
s2 = Mid(s, c + 1, (d - c - 1)) 'cutout the second part number
partno = s1 + s2 'patch them together
MsgBox (partno) 'done

End Sub

RE: MACRO QUESTION -

DO NOT USE GETTITLE, it's output is dependent upon a Windows setting, therefore you could get a different value on different computers.

Enjoy,
Ken

CODE

Sub main()

Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim sFileNameAndPath As String
Dim sFileName As String

Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc

sFileNameAndPath = swModel.GetPathName
sFileName = Right$(swModel.GetPathName, (Len(swModel.GetPathName) - InStrRev(swModel.GetPathName, "\")))

Debug.Print sFileNameAndPath
Debug.Print sFileName

End Sub

RE: MACRO QUESTION -

sirbartoo,

Looks like I didn't read your original post close enough. The macro above will only parse out the filename.

I have something that can do as you requested but I need a little clarification first...is the filename and path actually "J:1234/abcd/567.slddwg". Usually a path is something like "J:\1234\abcd\567.slddwg".

Ken

RE: MACRO QUESTION -

You're close.  Actually, you are working from right to left (usually the safest way to go).

You should test for both "\" and "/", as both can be delimiters for path strings.  You probably want to stage your lops as follows:
For X=L to 1 step -1
For X=a-1 to 1 step -1
For X=b-1 to 1 step -1
etc.

This will parse your path from right to left.

The best thing would be to write this as a function so you can reuse it many times in your code.  Perhaps have your input be the path string, and output be your desired result.

RE: MACRO QUESTION -

(OP)
THE FILE NAME IS ...J:\XXXXX\XXX\XXXX.SLDDWG. AS I READ THROUGH YOUR RESPONSES, I AM QUICKLY REALIZING THAT THIS IS OVER MY HEAD. I WAS HOPING TO REPLACE ONE SPECIFIC LINE OF CODE. I HAVE ATTACHED THE MACRO I AM ATTEMPTING TO ALTER (BORROWED FROM LENNY'S SITE). IF ANYBODY IS GENEROUS ENOUGH TO PEEK AT IT I WOULD BE GREATFUL.

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