10-30-2019
07:40 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
10-30-2019
07:40 AM
Hi Benjamin,
This is quick/dirty hack. Create both side lines and determine which line set is inside by the total length of them.
If the code will be used by just you, this may be enough.
option explicit on
Dim oDoc As Document = ThisApplication.ActiveDocument
Dim oCD As ComponentDefinition = oDoc.ComponentDefinition
Dim TG As TransientGeometry = ThisApplication.TransientGeometry
Dim oFace As Face
Do
oFace = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kPartFacePlanarFilter, "Select Face to Place Sketch")
If Not oFace Is Nothing Then
Dim oSketch As Sketch = oCD.Sketches.Add(oFace, True)
Dim oLineCollection As ObjectCollection = ThisApplication.TransientObjects.CreateObjectCollection
Dim oPointCollection As ObjectCollection = ThisApplication.TransientObjects.CreateObjectCollection
For Each oLine As SketchLine In oSketch.SketchLines
oLine.Construction = True
oLineCollection.Add(oLine)
Next
Dim createdSetOne As ObjectCollection = ThisApplication.TransientObjects.CreateObjectCollection
Dim createdSetTwo As ObjectCollection = ThisApplication.TransientObjects.CreateObjectCollection
Dim createdTotalLengthOne As Double
Dim createdTotalLengthTwo As Double
For Each oLine As SketchLine In oSketch.OffsetSketchEntitiesUsingDistance(oLineCollection,40,True,False,True)
createdTotalLengthOne = createdTotalLengthOne + oLine.Length
createdSetOne.Add(oLine)
Next oLine
For Each oLine As SketchLine In oSketch.OffsetSketchEntitiesUsingDistance(oLineCollection,40,False,False,True)
createdTotalLengthTwo = createdTotalLengthTwo + oLine.Length
createdSetTwo.Add(oLine)
Next oLine
Dim insideSet As ObjectCollection
Dim outsideSet As ObjectCollection
If createdTotalLengthOne < createdTotalLengthTwo Then
insideSet = createdSetOne
outsideSet = createdSetTwo
Else
insideSet = createdSetTwo
outsideSet = createdSetOne
End If
For Each oLine As SketchLine In insideSet
oPointCollection.Add(oLine.EndSketchPoint)
oPointCollection.Add(oLine.StartSketchPoint)
Next
For Each oLine As SketchLine In outsideSet
oLine.Delete()
Next
For Each oPoint As SketchPoint In oPointCollection
oPoint.HoleCenter = True
Next
oCD.Features.HoleFeatures.AddDrilledByThroughAllExtent(oPointCollection, 1, kPositiveExtentDirection)
End If
Loop While Not oFace Is Nothing
=====
Hideo Yamada