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
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?
Terry Ables
Micro Plastics Inc.
www.microplastics.com