I want to insert a sketch with a circle on a selected drawing view at selected point. first step select point then run macro to add circle...
I fail to do this with a drawing view...
Uses IMeasure to get the x,y,z coordinates.
' JLILI Amen
' QA Engineer / SolidWorks API Developer
Dim swApp As SldWorks.SldWorks
On Error GoTo Handler:
Set swApp = Application.SldWorks
Dim swModel As ModelDoc2
Set swModel = swApp.ActiveDoc
Dim R As Double
R = CDbl(InputBox("Enter radius in mm", "Create circle by radius macro by JLILI Amen firstname.lastname@example.org"))
Dim swMeasure As Measure
Set swMeasure = swModel.Extension.CreateMeasure
Dim Result As Boolean
Result = swMeasure.Calculate(Nothing)
Dim swSketchManager As SketchManager
Set swSketchManager = swModel.SketchManager
Dim swSketchResult As SketchSegment
Set swSketchResult = swSketchManager.CreateCircleByRadius(.X, .Y, .Z, R / 1000)
MsgBox ("Error occured:" + Err.Message)
...I want the circle to appear where I clicked before running the macro.
Oh? I thought you wanted to click on a defined point in a drawing view and insert it there?
In your example, the center does not have a pre-defined center point that can retrieved with one of the API interferences (or at least that's my knowledge). You would need an event handler that listens to mouse clicks and retrieves the X, Y, Z before inserting the circle. By then you're basically mimicking SolidWorks inbuilt sketch circle button which defeats the point of the API.
Retrieving data ...