10-30-2019
05:39 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
10-30-2019
05:39 AM
Hi all,
v: Inventor Professional 2019
I'm trying to automate the hole command in the given fashion :
1 - select face
2 - project face
3 - offset projected lines
4 - Apply hole command to the hole centers
The code I have come up with works (more or less).
However on Step 3, the orientation of the projected line seem to alternate between inwards and outwards (should always be inwards)..
You will find a commented out section in my code trying to deal with the matter but it is not working as expected (that is, it does nothing..)
Can someone help me define the proper way to always offset a geometry inwards ?
Dim oDoc As Document = ThisApplication.ActiveDocument
Dim oCD As ComponentDefinition = oDoc.ComponentDefinition
Dim TG As TransientGeometry = ThisApplication.TransientGeometry
Dim oFace As Face
Dim oOffsetDir As Boolean = False
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
'Define the offset direction
' Dim Params(0 To 1) As Double
' Dim Normals(0 To 2) As Double
' Params(0) = 0
' Params(1) = 0
' oFace.Evaluator.GetNormal(Params, Normals)
' Dim oNormalVector As UnitVector = TG.CreateUnitVector(Normals(0), Normals(1), Normals(2))
' Dim oLineVector As UnitVector = TG.CreateUnitVector(oLineCollection.Item(1).Geometry.Direction.X,oLineCollection.Item(1).Geometry.Direction.Y,0)
' Dim oOffsetVector = oLineVector.CrossProduct(oNormalVector)
' If oOffsetVector.IsEqualTo(oDesiredVector) = True Then
' oOffsetDir = True
' Else
' oOffsetDir = False
' End If
oSketch.OffsetSketchEntitiesUsingDistance(oLineCollection,40,oOffsetDir,False,True)
For Each oLine As SketchLine In oSketch.SketchLines
If oLine.Construction = False Then
oPointCollection.Add(oLine.EndSketchPoint)
oPointCollection.Add(oLine.StartSketchPoint)
End If
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
Solved! Go to Solution.