Hide Table of Contents

Create Sketch Entities with Visual Properties Example (VBA)

This example shows how to create a drawing and add some sketch entities and change the visual properties of a couple of sketch entities.

'------------------------------------------------------------
' Preconditions: None.
'
' Postconditions:
' 1. Opens a new drawing and creates and activates a layer.
' 2. Inserts some sketch entities.
' 3. Examine the drawing, then press F5.
' 4. Changes the visual properties of a couple of sketch entities,
'    which overrides the visual properties of the layer.
' 5. Repaints the graphics area.
' 6. Examine the drawing.
'------------------------------------------------------------
Option Explicit
Dim swApp As SldWorks.SldWorks
Dim pDrawing As SldWorks.DrawingDoc
Dim pLayerMgr As SldWorks.LayerMgr
Dim pSketchSegment1, pSketchSegment2, pSketchSegment3 As Object
Dim pSketchSegment4, pSketchSegment5, pSketchPoint1, pSketchPoint2 As Object
Dim res As Long 
Sub main()
    Set swApp = CreateObject("SldWorks.Application")
    Set pDrawing = swApp.NewDrawing2(13, """", 0, 0.2794, 0.2159)    
    ' Get LayerMgr object
    Set pLayerMgr = pDrawing.GetLayerManager    
    ' Create a layer
    res = pLayerMgr.AddLayer("myLayer", "Desc", 1227327, swLineStyles_e.swLineCONTINUOUS, swLineWeights_e.swLW_THIN)
    If (res = False) Then
        swApp.SendMsgToUser "Error creating layer."
    End If    
    ' Activate the layer
    res = pLayerMgr.SetCurrentLayer("myLayer")
    If (res = False) Then
        swApp.SendMsgToUser "Error activating layer."
    End If    
    ' Create some sketch entities on the active layer
    pDrawing.SetAddToDB True
    Set pSketchPoint1 = pDrawing.CreatePoint2(0.1, 0.14, 0)
    Set pSketchPoint2 = pDrawing.CreatePoint2(0.16, 0.14, 0)
    Set pSketchSegment1 = pDrawing.CreateCircle2(0.13, 0.1, 0, 0.2, 0.099, 0)
    Set pSketchSegment2 = pDrawing.CreateLine2(0.13, 0.1, 0, 0.12, 0.1, 0)
    Set pSketchSegment3 = pDrawing.CreateLine2(0.12, 0.1, 0, 0.13, 0.13, 0)
    Set pSketchSegment4 = pDrawing.CreateArc2(0.13, 0.1, 0, 0.09, 0.07, 0, 0.14, 0.051, 0, 1)
    Set pSketchSegment5 = pDrawing.CreateArc2(0.13, 0.1, 0, 0.195, 0.135, 0, 0.065, 0.135, 0, 1)
    pDrawing.SetAddToDB False    
    pDrawing.ClearSelection    
    Stop
    ' Examine the drawing, then press F5    
    ' Change the visual properties of a couple of sketch entities, which
    ' overrides the visual properties of the layer
    pSketchSegment4.Color = 4227327
    pSketchSegment4.Width = swLineWeights_e.swLW_THICK
    pSketchSegment4.Style = swLineStyles_e.swLinePHANTOM
    pSketchSegment5.Color = 0    
    ' Repaint to see the visual changes
    pDrawing.GraphicsRedraw2
End Sub
 
 


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 Sketch Entities with Visual Properties Example (VBA)
*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.