×
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 to open DXF as sketch in new part?

Macro to open DXF as sketch in new part?

Macro to open DXF as sketch in new part?

(OP)
Is anybody aware of an existing macro that automates the steps to open a dxf and place it in a sketch in a new part?  We'll have the need to do that frequently, and I'd prefer a pushbutton solution over the multiple screens/options that you're presented with by default.

Perhaps there's a macro that does this with DWG files (or some other file type) that I could alter for my needs?

Thanks,

Brian

RE: Macro to open DXF as sketch in new part?


'----------------------------------------------------

'

' Preconditions:

'          (1) Part is open.

'          (2) Plane or face on which to insert DXF file is selected.

'

' Postconditions:

'          (1) DXF/DWG file is added as sketch.

'          2) Sketch is autodimensioned.

'

'----------------------------------------------------

Option Explicit


Sub main()

    Const sDwgFileName                  As String = "YOURPATH\YourDXF.dxf"

    Dim swApp                           As SldWorks.SldWorks

    Dim swModel                         As SldWorks.modelDoc

    Dim swFeatMgr                       As SldWorks.FeatureManager

    Dim swFeat                          As SldWorks.feature

    Dim swSketch                        As SldWorks.Sketch

    Dim swSelMgr                        As SldWorks.SelectionMgr

    Dim swSelData                       As SldWorks.SelectData

    Dim nRetVal                         As Long

    Set swApp = Application.SldWorks

    Set swModel = swApp.ActiveDoc

    Set swFeatMgr = swModel.FeatureManager

    Set swFeat = swFeatMgr.InsertDwgOrDxfFile(sDwgFileName)

    Set swSketch = swFeat.GetSpecificFeature2

    Set swSelMgr = swModel.SelectionManager

    Set swSelData = swSelMgr.CreateSelectData

    swModel.EditRebuild3

End Sub

'----------------------------------------------------

This should get you what you want.

cheers

Terry Ables
Micro Plastics Inc.
www.microplastics.com

RE: Macro to open DXF as sketch in new part?

This was found in the Solidworks API help file.  You can take this and build on it to meet your needs.

Terry Ables
Micro Plastics Inc.
www.microplastics.com

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