AnsweredAssumed Answered

Need help to create "SPLIT LINE" by a VBA macro

Question asked by Yehoshua Enuka on Sep 6, 2017
Latest reply on Sep 6, 2017 by Alex Burnett

I wrote a macro in VBA that creates a circle and then selects the circle. Afterwards the macro should project the circle on the surface (faces) and create a split line. My problem is that I cannot use selectbyID2 because I don't know in advance the coordinates of the faces that I need to select! So I thought of a workaround: to select all the faces. However, this doesn't work. When I run the following code the split line is not created. Please note that if I run the code and then just before the last line I click on 'Curves->create line' then the split line is created perfectly!!!

 

Please advise.

 

Thanks and best,

Yehoshua

 

 

boolstatus = Part.Extension.SelectByID2("Circle1@Rolled Circle", "SKETCH", 0, 0, 0, False, 4, Nothing, 0)

 

Dim swFace As SldWorks.Face

Dim swEnt As SldWorks.Entity

Dim bRet As Boolean

Dim swSelMgr As SldWorks.SelectionMgr

Dim swSelData As SldWorks.SelectData

Dim swBody As SldWorks.Body2

Dim vBodies As Variant

Dim swPart As SldWorks.PartDoc

Set swSelMgr = Part.SelectionManager

Set swSelData = swSelMgr.CreateSelectData

vBodies = Part.GetBodies2(swAllBodies, True)

Set swPart = Part

Set swBody = vBodies(0)

Set swFace = swBody.GetFirstFace

Do While Not swFace Is Nothing

      Set swEnt = swFace

      ' Select using IEntity

      bRet = swEnt.Select4(True, swSelData)

      bRet = Part.Extension.SelectByID2("", "FACE", 0, 0, 0, True, 1, Nothing, 0)

      Set swFace = swFace.GetNextFace

  Loop

swPart.InsertSplitLineProject False, False

 

Any idea?

 

Thanks!

Outcomes