Message 1 of 4
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi all!
I have a rule that creates holes on a part that is alreay created. My problem is that I get an error after running the rule and filling all the user inputs. Also I can see that points are created but the holes are never created. This is the error I receive. Translated to Invalid parameter/argument. I can't seem to find my error 😞 Help would be appreciated! Thanks in advance.
Also, here's the code:
Public Module InputFunction Public Function GetUserInput(prompt As String, defaultValue As Object) As Object Dim input As String = InputBox(prompt, "User Input", defaultValue) If input <> "" Then Return input Else Return Nothing End If End Function End Module Sub Main() Dim oPartDoc As PartDocument oPartDoc = ThisDoc.Document Dim oCompDef As PartComponentDefinition oCompDef = oPartDoc.ComponentDefinition ' Input parameters Dim n As Integer = CInt(GetUserInput("Enter number of holes", 0)) Dim diameter As Double = CDbl(GetUserInput("Enter diameter of holes", 0)) Dim xCoords(n - 1) As Double Dim yCoords(n - 1) As Double Debug.Print(n) Debug.Print(diameter) ' Loop to get hole coordinates For i As Integer = 0 To n - 1 xCoords(i) = CDbl(GetUserInput("Enter X-coordinate for hole " & i + 1, 0)) yCoords(i) = CDbl(GetUserInput("Enter Y-coordinate for hole " & i + 1, 0)) Next ' Create sketch and holes Dim oSketch As PlanarSketch For Each oSketch In oCompDef.Sketches ' delete any previous test sketch If oSketch.Name = "Points Sketch" Then oSketch.Delete() Next Dim oWorkPlane As WorkPlane = oCompDef.WorkPlanes.Item("XY Plane") oSketch = oCompDef.Sketches.Add(oWorkPlane) oSketch.Name = "Points Sketch" Dim holeCount As Integer = n Dim oHoleDiameter As Double = diameter Dim holeX(n - 1) As Double Dim holeY(n - 1) As Double For i As Integer = 0 To n - 1 holeX(i) = xCoords(i) holeY(i) = yCoords(i) Dim oPoint As Point2d oPoint = ThisApplication.TransientGeometry.CreatePoint2d(holeX(i), holeY(i)) oSketch.SketchPoints.Add(oPoint) Next Dim oHoleFeatures As HoleFeatures oHoleFeatures = oCompDef.Features.HoleFeatures For i As Integer = 1 To n Dim oHoleFeature As HoleFeature LINE 68 oHoleFeature = oHoleFeatures.AddDrilledByThroughAllExtent(oSketch.SketchPoints.Item(i), oHoleDiameter, kSymmetricExtentDirection) Next End Sub
Solved! Go to Solution.