Hide Table of Contents

Manage Drawing Document Line Styles Example (VB.NET)

This example shows how to manage the line styles of a drawing document.

'-----------------------------------------------------------------------------
' Preconditions:
' 1. Ensure that the specified drawing document template exists.
' 2. Create c:\temp.
' 3. Open an Immediate Window.
' 4. Run this macro.
'
' Postconditions:
' 1. Inspect the Immediate Window.
' 2. Line styles are saved to c:\temp\styles.sldlin.
'------------------------------------

Imports SolidWorks.Interop.sldworks
Imports SolidWorks.Interop.swconst
Imports System
Imports System.Diagnostics

Partial Class SolidWorksMacro

    
Dim Part As DrawingDoc
    
Dim boolstatus As Boolean
    Dim longstatus As Long


    Sub main()

        
Dim def As String
        Dim name As String

        Part = swApp.NewDocument("<SolidWorks_install_dir>\data\Templates\drawing.drwdot", 2, 0.2794, 0.4318)
        swApp.ActivateDoc2(
"Draw1 - Sheet1", False, longstatus)

        printData(
"Line Style Data at Start", "")

        def =
"B,1.2,-0.2,2,-0.1,2"
        name = "NewOne"
        boolstatus = Part.AddLineStyle(name, def)
        printData(
"Line Style Data After Add", "")

        
Dim names As Object
        Dim styleNames(2) As String

        styleNames(0) = "NewOne"
        styleNames(1) = "CHAIN"
        styleNames(2) = "PHANTOM"

        names = styleNames

        
' Save line styles, replacing already saved line styles
        boolstatus = Part.SaveLineStyles("c:\temp\styles", names, True)
        printData(
"Line Style Data saved to file ", "c:\temp\styles")

        
' Delete a line style
        boolstatus = Part.DeleteLineStyle("NewOne", "STITCH")
        printData(
"Line Style Data After Delete", "")

        
' Load saved line styles, replacing existing line styles
        boolstatus = Part.LoadLineStyles("c:\temp\styles", names, True)
        printData(
"Line Style Data Imported from file", "")

    
End Sub

    Sub printData(ByVal title As String, ByVal file As String)

        
Dim names As Object = Nothing
        Dim types As Object = Nothing
        Dim namesArr() As String
        Dim typesArr() As String
        Dim i As Integer
        Dim stat As Boolean

        Debug.Print("-------------------------")
        Debug.Print(title)
        Debug.Print(
"-------------------------")

        
If file = "" Then
            stat = Part.GetLineStyles(names, types)
        
Else
            stat = swApp.GetLineStyles(file, names, types)
        
End If
        namesArr = names
        typesArr = types
        
If stat Then

            For i = 0 To UBound(typesArr)

                Debug.Print(Str$(i) +
" " + namesArr(i) + " " + typesArr(i))
            
Next i
        
Else
            MsgBox("Error in printData")
        
End If


    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:   Manage Drawing Document Line Styles 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.