Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TugboatEng 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
Joined
Jan 21, 2004
Messages
164
Location
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
 
'----------------------------------------------------

'

' 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