ds-blue-logo
Preview  |  SOLIDWORKS USER FORUM
Use your SOLIDWORKS ID or 3DEXPERIENCE ID to log in.
RERob Edwards05/03/2019

I think this is a very similar problem to my previous question -

Editing in the Assembly context seems to make selecting pretty confusing, with some methods working just fine and others not so.

The problem I am having is when I try and keep track of Sketch Segments as I create them to later add relations it just doesn't work.

In the following code it works just fine if I use

2018 SOLIDWORKS API Help - GetSketchSegments Method (ISketch) or 2018 SOLIDWORKS API Help - GetSketchPoints2 Method (ISketch)

but with the Objects returned from Creation Methods

eg

2018 SOLIDWORKS API Help - CreateLine Method (ISketchManager) or 2018 SOLIDWORKS API Help - CreatePoint Method (ISketchManager)

nothing happens. I imagine my code would get too complicated if I have to get all the segments everytime

To illustrate here's a sample of my code that works. The commented out lines don't work.

If Not Haunch1 Is Nothing Then

id = 1

With .SketchManager

.Insert3DSketch True

.AddToDB = True

Set swSketch = .ActiveSketch

With swSketch

.Name = pm.Description("_") & "_Secret_Haunch" & id

.Description = pm.Description & " Secret Haunch" & id

Set swSkRelMgr = .RelationManager

End With

Dim Triangle(1 To 3) As SldWorks.SketchSegment

Set Triangle(1) = .CreateLine(0#, 0#, 0#, 0.1, 0#, 0#)

Set Triangle(2) = .CreateLine(0.1, 0#, 0#, 0.1, 0.1, 0#)

Set Triangle(3) = .CreateLine(0.1, 0.1, 0#, 0#, 0#, 0#)

ReDim EntsArr(1)

Set EntsArr(0) = pm.CheekPlane(1)

'This works!

'Dim vSketchEntities As Variant 'already defined earlier in sub

vSketchEntities = swSketch.GetSketchSegments ‘ <- WORKS!

For i = 1 To 3

'Set EntsArr(1) = Triangle(i) ‘ <-DOESN’T WORK

Set EntsArr(1) = vSketchEntities(i - 1) ‘ <- WORKS!

Call swSkRelMgr.AddRelation(EntsArr, swConstraintType_COINCIDENT)

Next

ReDim EntsArr(2)

Dim swSkPt As SldWorks.SketchPoint

vSketchEntities = swSketch.GetSketchPoints2 ‘ <- WORKS!

For i = 1 To 3

'Set swSkPt = Triangle(i).GetStartPoint2 ‘ <- DOESN’T WORK

'Set EntsArr(2) = swSkPt ' <- DOESN'T WORK

Set EntsArr(2) = vSketchEntities(i - 1) ‘ <- WORKS

Select Case i

Case 1

Set EntsArr(0) = pm.HaunchPlane

Set EntsArr(1) = pm.EndPlane(id)

Case 2

Set EntsArr(0) = pm.StartPlane

Set EntsArr(1) = pm.EndPlane(id)

Case 3

Set EntsArr(0) = pm.StartPlane

Set EntsArr(1) = pm.EdgePlane(id)

End Select

Call swSkRelMgr.AddRelation(EntsArr, swConstraintType_ATINTERSECT)

Next

.AddToDB = False

.Insert3DSketch True

End With

I asked my VAR and the creative solution he proposed was to ignore the returned object but immediately use 2018 SOLIDWORKS API Help - GetSelectedObject6 Method (ISelectionMgr) to capture it.

I've not tested it yet. I wanted to reach out and ask is there a better way/ something I'm doing wrong to keep running into these problems.. or is that just the way it is?