Hide Table of Contents

Create Sketch Entities with Visual Properties Example (VBA)

This example shows how to create a drawing and add a sketched line using IModelDoc2::CreateLine2. Then, it uses the object returned from IModelDoc2::CreateLine2 to change the visual properties of the sketch entity.

 

'------------------------------------------------------------

Dim swApp As Object

Dim pDrawing As Object

Dim pLayerMgr As Object

Dim pSketchSegment1, pSketchSegment2, pSketchSegment3 As Object

Dim pSketchSegment4, pSketchSegment5, pSketchPoint1, pSketchPoint2 As Object

 

Sub main()

Set swApp = CreateObject ("SldWorks.Application")

Set pDrawing = swApp.NewDrawing2 (13, """", 0, 0.279400, 0.215900)

 

' Get LayerMgr object

Set pLayerMgr = pDrawing.GetLayerManager     

' Create a layer

res = pLayerMgr.AddLayer ( "myLayer", "Desc", 1227327, 0, 0) 

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 a few 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.20, 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

 

' Change the visual properties of the second line. This will override the visual properties of the layer.

pSketchSegment4.Color = 4227327

pSketchSegment4.Width = 3

pSketchSegment4.Style = 2

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) 2014 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.