×
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 have this macro I got from this forum that saves a part file to an iges format.  It automatically saves it to the folder location that the part is in.  I am going to be using PDM works so I need to have it save it in a different spot.  What do I need to change to get this to work?

Here is the Macro:

Option Explicit

Dim swApp, Part As Object
Dim BoolStatus As Boolean
Dim LongStatus As Long
Dim e As Long
Dim w As Long

Dim Msg As String
Dim PartName, Rev As String


Sub main()

  Set swApp = CreateObject("SldWorks.Application")
  Set Part = swApp.ActiveDoc
    
    If ((Part Is Nothing) Or (Not (Part.GetType Eqv swDocPART))) Then
        Msg = "A part document must be active to use this command!"
        LongStatus = swApp.SendMsgToUser2(Msg, swMbWarning, swMbOk)
        End

    Else
        PartName = Part.GetPathName
        PartName = Left(PartName, Len(PartName) - 7) & ".igs"

        BoolStatus = Part.SaveAs4(PartName, 0, 0, e, w)
        
        If BoolStatus = False Then
            Msg = "Failed to save IGS document!"
            LongStatus = swApp.SendMsgToUser2(Msg, swMbWarning, swMbOk)
        Else
'            Msg = "Saved part as " & PartName
'            LongStatus = swApp.SendMsgToUser2(Msg, swMbWarning, swMbOk)
        End If
       
    End If
 
    Set Part = Nothing
    Set swApp = Nothing

End Sub


Thanks
Chris

RE: Macro Question

Quote:

PartName = Part.GetPathName
PartName = Left(PartName, Len(PartName) - 7) & ".igs"
These two lines are what take the current part path and swap ".sldprt" for ".igs".  Instead of using "Part.GetPathName" to determine your path, set a new path at this point.

I could be the world's greatest underachiever, if I could just learn to apply myself.
http://www.EsoxRepublic.com-SolidWorks API VB programming help

RE: Macro Question

(OP)
Could you give me an example?  I am not sure I know exactly what I need to do.

Thanks
Chris

RE: Macro Question

you could just replace those two lines with this one:

PartName = "C:\temp.igs"

RE: Macro Question

(OP)
I still want to maintain the parts original name just change the location.  Cab you give me an example of that?

Thanks
Chris

RE: Macro Question

OK, fine.  Try this:
*******
PartName = Part.GetTitle
If Right(PartName, 7) = ".sldprt" Then
    PartName = Left(PartName, Len(PartName) - 7)
End If
PartName = "C:\" & PartName & ".igs"
*******
If you want the file stored somwhere other than the root of your C: drive, just replace C:\ with whatever path you wish.

I'm pretty sure this will work, but I cannot test it right now.  I don't have PDMWorks, either, so that may change something (but I doubt it).

This is really not very difficult...You really should try and learn Visual Basic.  I think VARS give some courses, or you can even take a general VB class.  Also, there are lots of places on the web to help learn VB.

RE: Macro Question

(OP)
Ok, thanks

I have every intention on learning more about VBA.  I already have a book just haven't had any time to look through it yet.

Chris

RE: Macro Question

Definitely start w/ VBA before you get too deep into macros.  It really helps.

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