Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

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

Macro to open DXF as sketch in new part?

Status
Not open for further replies.

brrian

Mechanical
Jan 21, 2004
164
US
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
 
Replies continue below

Recommended for you

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

'

' 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.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top