I can't reach to sketch in a drawing view. Below is a macro that creates a view and draws 10 random lines, but they appear on the background, not in the desired view. Any idea ? (Macro recording & playback doesn't work...) Thanks!
Option Explicit Dim app As SldWorks.SldWorks Dim doc As SldWorks.DrawingDoc
Public Sub main() Set app = Application.SldWorks Set doc = app.NewDrawing2(swDwgTemplateA3size, "", 0, 0, 0) Dim l, h As Double l = 0.3 h = 0.2 Dim viewname As String viewname = doc.CreateViewport2(0, 0, l, h, 0, 1) Dim view As SldWorks.view Set view = doc.GetFirstView Call doc.SelectByID(viewname, "DRAWINGVIEW", 0, 0, 0) Dim sketch As SldWorks.sketch Set sketch = view.GetSketch sketch.Select (False) Call doc.EditSketch Set sketch = doc.GetActiveSketch Dim i As Integer For i = 1 To 10 Call doc.CreateLine2(l * Rnd(), h * Rnd(), 0, l * Rnd(), h * Rnd(),
0) Next i End Sub