Hide Table of Contents

Get Sketch Segment Names Example (VB.NET)

This example shows how to get the names of selected sketch segments.

'----------------------------------------------------
' Preconditions:
' 1. Verify that the specified part document template exists.
' 2. Open the Immediate window.
'
' Postconditions:
' 1. Opens a new part document.
' 2. Inserts a sketch of a rectangle.
' 3. Selects two sketch segments and prints their names
'    to the Immediate window.
' 4. Examine the Immediate window.
'----------------------------------------------------
Imports SolidWorks.Interop.sldworks
Imports SolidWorks.Interop.swconst
Imports System.Runtime.InteropServices
Imports System
Imports System.Diagnostics
 
Partial Class SolidWorksMacro
 
    Public Sub main()
 
        Dim swModel As ModelDoc2
        Dim swModelDocExt As ModelDocExtension
        Dim swSelMgr As SelectionMgr
        Dim swSketchManager As SketchManager
        Dim sketchLines As Object
        Dim swSketchSegHoriz As SketchSegment
        Dim swSketchSegVert As SketchSegment
        Dim ret As Boolean
 
 
        swModel = swApp.NewDocument("C:\ProgramData\SolidWorks\SolidWorks 2016\templates\Part.prtdot", 0, 0, 0)
        swModelDocExt = swModel.Extension
 
        ret = swModelDocExt.SetUserPreferenceToggle(swUserPreferenceToggle_e.swSketchAddConstToRectEntity, swUserPreferenceOption_e.swDetailingNoOptionSpecified, False)
        ret = swModelDocExt.SetUserPreferenceToggle(swUserPreferenceToggle_e.swSketchAddConstLineDiagonalType, swUserPreferenceOption_e.swDetailingNoOptionSpecified, True)
        swSketchManager = swModel.SketchManager
        sketchLines = swSketchManager.CreateCornerRectangle(0, 0, 0, 0.110951010058045, -0.066328380491143, 0)
        ret = swModelDocExt.SelectByID2("Line3""SKETCHSEGMENT", 0.00443505736694483, -0.012832795562811, 0.00637809258389225, False, 0, Nothing, 0)
        ret = swModelDocExt.SelectByID2("Line4""SKETCHSEGMENT", 0.095835993249203, -0.0306185999393385, -0.0297695225643872, True, 0, Nothing, 0)
        swSelMgr = swModel.SelectionManager
        swSketchSegHoriz = swSelMgr.GetSelectedObject6(1, -1)
        Debug.Print("Name of selected horizontal sketch segment = " & swSketchSegHoriz.GetName)
        swSketchSegVert = swSelMgr.GetSelectedObject6(2, -1)
        Debug.Print("Name of selected vertical sketch segment = " & swSketchSegVert.GetName)
 
        swSketchManager.InsertSketch(True)
 
 
    End Sub
 
    ''' <summary>
    ''' The SldWorks swApp variable is pre-assigned for you.
    ''' </summary>
    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:   Get Sketch Segment Names 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.