T
tong1998
Hi,
I am trying to use Solidworks API to change the RefPlane selections.
Basically I have a part which includes a RefPlane feature that's of
swRefPlaneAngle type. The definition of this plane includes two
things: a RefPlane, and a SketchLine. I would like to update the
selections with another RefPlane and another SketchLine.
I was trying to achieve this using the Selections property of
RefPlane. But I got the error message "Attempted to read or write
protected memory. This is often in indicator that the other memory is
corrupt." on the line "plane.Selections = New Object() {p, l}".
I am pretty new to vb and solidworks api. I cannot figure out what I
did was wrong. Any suggestion will be greatly appreciated!
The detailed code is as follows.
Dim swModel As ModelDoc2 = iSwApp.ActiveDoc
Dim swPart As PartDoc = swModel
Dim feature As Feature
Dim ret As Boolean
' get the plane that is to be modified
Dim planeFea As Feature =
swPart.FeatureByName(nameOldPlane)
Dim plane As RefPlaneFeatureData
plane = feature.GetDefinition
' access the selection
plane.AccessSelections(swModel, Nothing)
' check that the plane is of the correct type
If plane.Type <> swRefPlaneType_e.swRefPlaneAngle Then
Throw New Exception("Incorrect plane type")
End If
' modify the selections
Dim ents As Object = plane.Selections
If UBound(ents) <> 1 Then
Throw New Exception("Incorrect # of plane entities")
End If
' get the new RefPlane and SketchLine
p = ... ' get the new RefPlane
l = .... ' get the new SketchLine
plane.Selections = New Object() {p, l}
ret = feature.ModifyDefinition(plane, swPart, Nothing)
plane = Nothing
I am trying to use Solidworks API to change the RefPlane selections.
Basically I have a part which includes a RefPlane feature that's of
swRefPlaneAngle type. The definition of this plane includes two
things: a RefPlane, and a SketchLine. I would like to update the
selections with another RefPlane and another SketchLine.
I was trying to achieve this using the Selections property of
RefPlane. But I got the error message "Attempted to read or write
protected memory. This is often in indicator that the other memory is
corrupt." on the line "plane.Selections = New Object() {p, l}".
I am pretty new to vb and solidworks api. I cannot figure out what I
did was wrong. Any suggestion will be greatly appreciated!
The detailed code is as follows.
Dim swModel As ModelDoc2 = iSwApp.ActiveDoc
Dim swPart As PartDoc = swModel
Dim feature As Feature
Dim ret As Boolean
' get the plane that is to be modified
Dim planeFea As Feature =
swPart.FeatureByName(nameOldPlane)
Dim plane As RefPlaneFeatureData
plane = feature.GetDefinition
' access the selection
plane.AccessSelections(swModel, Nothing)
' check that the plane is of the correct type
If plane.Type <> swRefPlaneType_e.swRefPlaneAngle Then
Throw New Exception("Incorrect plane type")
End If
' modify the selections
Dim ents As Object = plane.Selections
If UBound(ents) <> 1 Then
Throw New Exception("Incorrect # of plane entities")
End If
' get the new RefPlane and SketchLine
p = ... ' get the new RefPlane
l = .... ' get the new SketchLine
plane.Selections = New Object() {p, l}
ret = feature.ModifyDefinition(plane, swPart, Nothing)
plane = Nothing