New to Api. My code worked eariler until I restarted. Now I recieve a "runtime error 91 with block variable not set" I suspected a reference is not selected but, it seems all the same libraries are set. The model is set up as before. A sketch is selected. I checked the syntax it looks nothing has changed. Thsi is just an example I modified that is simular to what I need in my project. Here is the code. Thanks is advance.
Line of code with problem I think. Set selMgr=swModel.SelectionManager Holding curser over the value "selMgr = nothing"
Option Explicit
Dim swApp As SldWorks.SldWorks
Dim selMgr As SldWorks.SelectionMgr
Dim swModel As SldWorks.ModelDoc2
Dim SketchPoints As Variant
Dim SketchFeature As SldWorks.Feature
Dim PointCoords(2) As Double
Dim MathUtil As SldWorks.MathUtility
Dim MathTrans As SldWorks.MathTransform
Dim MathP As SldWorks.MathPoint
Dim ModelSketchTransform As Variant
Sub main()
'Connect the program to SolidWorks
Set swApp = CreateObject("SldWorks.Application")
Set swModel = swApp.ActiveDoc
'Prepare the MathUtility
Set MathUtil = swApp.GetMathUtility
'Get the SelectionMgr
Set selMgr = swModel.SelectionManager
'Get the sketch from the SelectionMgr
Set SketchFeature = selMgr.GetSelectedObject6(1, 0)
Set SketchFeature = SketchFeature.GetSpecificFeature2
'Get the sketch points
SketchPoints = SketchFeature.GetSketchPoints2
'Build a coordinate array from the first point in the sketch
PointCoords(0) = SketchPoints(0).X
PointCoords(1) = SketchPoints(0).Y
PointCoords(2) = SketchPoints(0).Z
'Create the new MathPoint from the sketch point data.
'MathP refers to the point location in the sketch coordinates
Set MathP = MathUtil.CreatePoint(PointCoords)
'Display the point coordinates in relation to the sketch origin
SketchPoints = MathP.ArrayData
MsgBox SketchPoints(0) & ", " & SketchPoints(1) & ", " & SketchPoints(2)
'Get the model-to-sketch transform for this sketch
Set MathTrans = SketchFeature.ModelToSketchTransform
'Get the inversion of the transform
Set MathTrans = MathTrans.Inverse
'Multiply the point by the inverse transform
'MathP now refers to the point location in the model coordinates
Set MathP = MathP.MultiplyTransform(MathTrans)
'Display the point coordinates in relation to the model origin
SketchPoints = MathP.ArrayData
MsgBox SketchPoints(0) & ", " & SketchPoints(1) & ", " & SketchPoints(2)
End Sub
SolidworksApi macros