- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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 ?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi thnx for the input.
This is indeed a clever hack. Drawing both and keeping the shortest one.
However it doesn't work... which is weird.
I get the same behaviour with both pieces of code.
Does it work right on your machine ? Maybe I've got some obscure configuration wrong..
EDIT :
Fixed it, because of the DO WHILE you have to reset the length variables (otherwise it keeps adding itself)
Dim createdTotalLengthOne As Double = 0 Dim createdTotalLengthTwo As Double = 0
Thank you very much !