Hide Table of Contents

Create Linear Pattern Example (VB.NET)

This example shows how to create a linear pattern.

'-------------------------------------------------------------
' Preconditions:
' 1. Create a VB.NET Windows console project.
' 2. Copy and paste this example into the VB.NET IDE.
' 3. Add a reference to:
'    install_dir\APISDK\tlb\DraftSight.Interop.dsAutomation.dll.
' 4. Add references to System and System.Windows.Forms.
' 5. Start DraftSight and open a document.
' 6. Click Start Debugging.
'
' Postconditions:
' 1. Draws a Circle.
' 2. Draws a 2D PolyLine.
' 3. Creates a linear pattern using the Circle and 2D PolyLine
'    entities.
' 4. Zooms the drawing to fit.
' 5. Examine the drawing.
'------------------------------------------------------------
Imports System.Collections.Generic
Imports System.Text
Imports DraftSight.Interop.dsAutomation
Imports System.Runtime.InteropServices
Imports System.Windows.Forms


Module Module1

    
Sub Main()

        
'Connect to DraftSight application
        Dim dsApp = GetObject(, "DraftSight.Application")
        dsApp.AbortRunningCommand() '
abort any command currently running in DraftSight to avoid nested commands

        
'Get active document
        Dim dsDoc As Document = dsApp.GetActiveDocument()
        
If dsDoc Is Nothing Then
            MessageBox.Show("There are no open documents in DraftSight.")
            
Return
        End If


        'Get model space
        Dim dsModel As Model = dsDoc.GetModel()

        
'Get Sketch Manager
        Dim dsSketchMgr As SketchManager = dsModel.GetSketchManager()

        
'Draw a Circle
        Dim centerPoint As Double() = New Double() {5, 5, 0}
        
Dim radius As Double = 3
        
Dim dsCircle As Circle = dsSketchMgr.InsertCircle(centerPoint(0), centerPoint(1), centerPoint(2), radius)

        
'Draw a 2D PolyLine
        Dim coordinatesArray As Double() = New Double() {10, 4, 10, 6, 14, 6, _
         14, 4}
        
Dim closed As Boolean = True
        Dim dsPolyLine As PolyLine = dsSketchMgr.InsertPolyline2D(coordinatesArray, closed)

        
'Linear pattern parameters
        Dim numberElementsOnVerticalAxis As Integer = 4
        
Dim numberElementsOnHorizontalAxis As Integer = 5
        
Dim spacingOnVerticalAxis As Double = 20
        
Dim spacingOnHorizontalAxis As Double = 40
        
Dim patternAngle As Double = Math.PI / 4 'In radians


        'Prepare list of entity types
        Dim dsEntityTypes As Integer() = New Integer() {CInt(dsObjectType_e.dsCircleType), CInt(dsObjectType_e.dsPolyLineType)}

        
'Prepare list of entities
        Dim dsEntities As DispatchWrapper() = New DispatchWrapper() {New DispatchWrapper(dsCircle), New DispatchWrapper(dsPolyLine)}

        
'Create linear pattern
        dsSketchMgr.PatternLinear(numberElementsOnVerticalAxis, numberElementsOnHorizontalAxis, spacingOnVerticalAxis, spacingOnHorizontalAxis, patternAngle, dsEntityTypes, _
         dsEntities)

        
'Zoom to fit
        dsApp.Zoom(dsZoomRange_e.dsZoomRange_Fit, Nothing, Nothing)
    
End Sub
End
Module



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:   Create Linear Pattern 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) 2019 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.