Hide Table of Contents

Insert and Position DXF/DWG File in Drawing Example (VB.NET)

This example shows how to insert and position a DXF/DWG file in a drawing.

'---------------------------------------------------------------------------
' Preconditions:
' 1. Open a drawing.
' 2.
Replace DXF_file_path with the pathname of an existing DXF/DWG file.
'
' Postconditions:
' 1. Inspect the Immediate window.
' 2. The DXF/DWG file is inserted as per the specified import data.
' 3. The drawing is moved to the right.
'---------------------------------------------------------------------------
Imports SolidWorks.Interop.sldworks
Imports SolidWorks.Interop.swconst
Imports System
Imports System.Diagnostics

Partial Class SolidWorksMacro

    
Sub main()

        
Const sDwgFileName As String = "DXF_file_path"

        Dim swModel As ModelDoc2
        
Dim swModelView As ModelView
        
Dim swDraw As DrawingDoc
        
Dim swFeatMgr As FeatureManager
        
Dim swFeat As Feature
        
Dim swSketch As Sketch
        
Dim swView As View
        
Dim vPos As Object
        Dim bRet As Boolean
        Dim importData As ImportDxfDwgData

        swModel = swApp.ActiveDoc
        swModelView = swModel.ActiveView

        bRet = swModel.Extension.SelectByID2(
"Sheet1", "SHEET", 0.0#, 0.0#, 0, False, 0, Nothing, 0)

        swDraw = swModel
        swFeatMgr = swModel.FeatureManager
        importData = swApp.GetImportFileData(sDwgFileName)

        
'Unit
        importData.LengthUnit("") = swLengthUnit_e.swINCHES

        
'Position
        bRet = importData.SetPosition("", swDwgImportEntitiesPositioning_e.swDwgEntitiesCentered, 0, 0)

        
'Sheet scale
        bRet = importData.SetSheetScale("", 1.0#, 2.0#)

        
'Paper size
        bRet = importData.SetPaperSize("", swDwgPaperSizes_e.swDwgPaperAsize, 0.0#, 0.0#)

        
'Import method
        importData.ImportMethod("") = swImportDxfDwg_ImportMethod_e.swImportDxfDwg_ImportToExistingDrawing

        
'Import file with importData
        swFeat = swFeatMgr.InsertDwgOrDxfFile2(sDwgFileName, importData)
        swSketch = swFeat.GetSpecificFeature2

        swView = swDraw.GetFirstView

        
Do While Not swView Is Nothing
            If swSketch Is swView.GetSketch Then
                Exit Do
            End If
            swView = swView.GetNextView
        
Loop

        vPos = swView.Position

        Debug.Print(
"File = " & swModel.GetPathName)
        Debug.Print(
"  Sketch       = " & swFeat.Name)
        Debug.Print(
"  View         = " & swView.Name)
        Debug.Print(
"    Old Pos    = (" & vPos(0) * 1000.0# & ", " & vPos(1) * 1000.0# & ") mm")

        
' Move to right
        vPos(0) = vPos(0) + 0.01
        swView.Position = vPos

        vPos = swView.Position
        Debug.Print(
"    New Pos    = (" & vPos(0) * 1000.0# & ", " & vPos(1) * 1000.0# & ") mm")

        
' Redraw
        Dim rect() As Double
        rect = Nothing
        swModelView.GraphicsRedraw(rect)

    
End Sub


    Public swApp As SldWorks


End Class
 



Provide feedback on this topic

SOLIDWORKS welcomes your feedback concerning the presentation, accuracy, and thoroughness of the documentation. Use the form below to send your comments and suggestions about this topic directly to our documentation team. The documentation team cannot answer technical support questions. Click here for information about technical support.

* Required

 
*Email:  
Subject:   Feedback on Help Topics
Page:   Insert and Position DXF/DWG File in Drawing Example (VB.NET)
*Comment:  
*   I acknowledge I have read and I hereby accept the privacy policy under which my Personal Data will be used by Dassault Systèmes

Print Topic

Select the scope of content to print:



x

We have detected you are using a browser version older than Internet Explorer 7. For optimized display, we suggest upgrading your browser to Internet Explorer 7 or newer.

 Never show this message again
x

Web Help Content Version: API Help (English only) 2013 SP05

To disable Web help from within SOLIDWORKS and use local help instead, click Help > Use SOLIDWORKS Web Help.

To report problems encountered with the Web help interface and search, contact your local support representative. To provide feedback on individual help topics, use the “Feedback on this topic” link on the individual topic page.