Hi, it is now one continuous line and I have added the constrains in the rule. However, the last point of the last line is NOT grounded, so you still have to do it manualy. I couldn't find the right way to add the constrain to the point. I have aslo modifed the scale ratio, so it could fit in the area a bit better.
You can adjust the ratio by changing the number "2.8". Highter number means less lines.
Currenty it is runnig by one round of the "shape" per one loop (it will create 4 lines per loop).
It might be possible to change it so it would run e.g. 1,5 rounds of the "shape" if it would fit better (create 1 line per loop).
It should lead to tighter fit. Let me know if cuting the "shape" on parts is an option and I'll rewrite it.
Sub Main()
Dim oDoc As Document = ThisApplication.ActiveDocument
Dim oCD As ComponentDefinition = oDoc.ComponentDefinition
If TypeOf ThisApplication.ActiveEditObject Is Sketch Then
oSketch = ThisApplication.ActiveEditObject
Else
MsgBox("Run this rule from an open sketch, please.")
Exit Sub
End If
Try
oArea = InputBox("Please enter the size of the area to be filed.", "Area input", 100)
If oArea = 0 Then
Exit Sub
End If
OrigSize = InputBox("Please enter the size of the base (first, smallest) line.", "Area input", 23.813)
If OrigSize = 0 Then
Exit Sub
End If
Catch
Exit Sub
End Try
CreateLines()
oSketch.ExitEdit
InventorVb.DocumentUpdate()
End Sub
Private Amount As Integer
Private oArea As Double
Private oLine As SketchLine
Private OrigSize As Double
Private oSketch As Sketch
Private Sub CreateLines()
Dim PI As Double = 4 * Atan(1)
Dim TG As TransientGeometry = ThisApplication.TransientGeometry
oArea = oArea * 0.1 'cm to mm
OrigSize = OrigSize * 0.1 'cm to mm
oSize = OrigSize
Dim PosX As Double = oSize
Dim PosY As Double = 0
Dim Amount As Integer = Floor(oArea / (oSize * 2.8))
Dim Point1 As Point2D = TG.CreatePoint2d(0, 0)
Dim Point2 As Point2D
For i = 1 To Amount
Point2 = TG.CreatePoint2d(PosX, PosY)
Try
oLine = oSketch.SketchLines.AddByTwoPoints(oLine.EndSketchPoint, Point2)
Catch
oLine = oSketch.SketchLines.AddByTwoPoints(Point1, Point2)
End Try
oSketch.GeometricConstraints.AddGround(oLine)
PosX = PosX - (oSize * Sin(PI * 0.16667))
PosY = PosY + (oSize * Cos(PI * 0.16667))
Point2 = TG.CreatePoint2d(PosX, PosY)
AddLine(Point2)
oSize = oSize + OrigSize
PosX = PosX - oSize
PosY = PosY
Point2 = TG.CreatePoint2d(PosX, PosY)
AddLine(Point2)
PosX = PosX + (oSize * Sin(PI * 0.16667))
PosY = PosY - (oSize * Cos(PI * 0.16667))
Point2 = TG.CreatePoint2d(PosX, PosY)
AddLine(Point2)
oSize = oSize + OrigSize
PosX = PosX + oSize
PosY = PosY
Next
End Sub
Private Sub AddLine(PointB As Point2D)
oLine = oSketch.SketchLines.AddByTwoPoints(oLine.EndSketchPoint, PointB)
oSketch.GeometricConstraints.AddGround(oLine)
End Sub
Consider using "Accept as Solution" / "Kudos" if you find this helpful.
- - - - - - - - - - - - - - -
Regards,
Mike
"Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live." - John F. Woods