@Sergio.D.Suárez Here are the two rules I have. First is the rule to create the parameters
Dim oPartDoc As Document = ThisDoc.Document
Dim oPartCompDef As PartComponentDefinition = ThisApplication.ActiveDocument.ComponentDefinition
If oPartDoc.DocumentType = kPartDocumentObject Then
Dim oParams As Parameters = oPartCompDef.Parameters
Dim oUserParams As UserParameters = oParams.UserParameters
Try
oHoleSizes = oUserParams.Item("HoleSizes")
Catch
oInsulationType = oUserParams.AddByValue("HoleSizes", 0, kInchLengthUnits)
MultiValue.SetList("HoleSizes", .109375, .125, .15625, .1875, .21875, .28125)
End Try
Try
oMaterial = oUserParams.Item("MaterialType")
Catch
oInsulationType = oUserParams.AddByValue("MaterialType", " ", kTextUnits)
MultiValue.SetList("MaterialType", "Starboard", "Acrylic", "Proboard")
End Try
Try
oHoleType = oUserParams.Item("HoleType")
Catch
oInsulationType = oUserParams.AddByValue("HoleType", " ", kTextUnits)
MultiValue.SetList("HoleType", "Pilot", "Thru", "Custom")
End Try
Try
oFromFrontEdge = oUserParams.Item("FromFrontEdge")
Catch
oInsulationType = oUserParams.AddByValue("FromFrontEdge", (0.25 * 2.54), kInchLengthUnits)
End Try
Try
oFromLeftEdge = oUserParams.Item("FromLeftEdge")
Catch
oInsulationType = oUserParams.AddByValue("FromLeftEdge", (1.125*2.54), kInchLengthUnits)
End Try
Try
oFromRightEdge = oUserParams.Item("FromRightEdge")
Catch
oInsulationType = oUserParams.AddByValue("FromRightEdge", (1.125*2.54), kInchLengthUnits)
End Try
End If
Parameter.UpdateAfterChange = True
MultiValue.UpdateAfterChange = True
next is a rule that needs to use those parameters to create a sketch of circles and extrude them. The parameters created by the first rule are what I want to have in a form.
Dim oPartDoc As Document = ThisDoc.Document
Dim oPartCompDef As PartComponentDefinition = ThisApplication.ActiveDocument.ComponentDefinition
Dim oTG As TransientGeometry = ThisApplication.TransientGeometry
'get measurements to determine Material Thickness
My_x = Measure.ExtentsLength
My_y = Measure.ExtentsWidth
My_z = Measure.ExtentsHeight
'Make longest value the Length, rounded to 4 places
oThickness = Round(MinOfMany(My_x, My_y, My_z), 4)
Dim oFace As Face = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kPartFaceFilter, "Select Surface to Place Holes")
Dim oFrontEdge As Edge = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kPartEdgeFilter, "Select Front Edge of Pattern")
Dim oVertex As Vertex = oFrontEdge.StartVertex
Dim oLeftEdge As Edge = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kPartEdgeFilter, "Select Left Edge of Pattern")
Dim oRightEdge As Edge = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kPartEdgeFilter, "Select Right Edge of Pattern")
oMaterial = MaterialType
oHoleType = HoleType
oHoleSize = HoleSizes * 2.54
Dim oSketch As PlanarSketch
'oSketch = oPartCompDef.Sketches.AddWithOrientation(oFace, oFrontEdge, True, True, oVertex, False)
oSketch = oPartCompDef.Sketches.Add(oFace, False)
oSketch.AxisEntity = oFrontEdge
oSketch.OriginPoint = oFrontEdge.StartVertex
Dim oSketchNameSuffix As Integer
Dim oNameCompare As String
Dim oNameNumCount As Integer
Dim oNameCharCount As Integer
If oHoleType = "Thru" Then
oSketchNameSuffix = 0
oNameCompare = "SK_Hole_"
oNameCharCount = 8
oNameNumCount = 9
Else If oHoleType = "Pilot" Then
oSketchNameSuffix = 0
oNameCompare = "SK_Pilot_"
oNameCharCount = 9
oNameNumCount = 10
End If
For Each oSketchNameCheck As Sketch In oPartCompDef.Sketches
If Left(oSketchNameCheck.Name,oNameCharCount) = oNameCompare Then
oSketchNumber = Val(Mid(oSketchNameCheck.Name, oNameNumCount, 2))
While oSketchNameSuffix <= oSketchNumber
oSketchNameSuffix = oSketchNameSuffix + 1
End While
End If
Next
oSketch.Name = oNameCompare & oSketchNameSuffix
Dim oQty = 4
oFromLeftEdge = FromLeftEdge * 2.54
oFromRightEdge = FromRightEdge * 2.54
oFromFrontEdge = FromFrontEdge * 2.54
Dim oFrontEdgeDistance = ThisApplication.MeasureTools.GetMinimumDistance(oFrontEdge.StartVertex, oFrontEdge.StopVertex)
Dim oPatternSpacing = (oFrontEdgeDistance -(oFromLeftEdge + oFromRightEdge)) / (oQty-1)
Dim oSketchPoint As SketchPoint = oSketch.SketchPoints.Add(oTG.CreatePoint2d(oFromLeftEdge, oFromFrontEdge))
Dim circleParentSketch As PlanarSketch = oSketchPoint.Parent
Dim vectorForCheck As UnitVector = circleParentSketch.PlanarEntityGeometry.Normal
Dim pointToCheck As Point = oSketchPoint.Geometry3d
Dim foundObjects As ObjectsEnumerator = Nothing
Dim locationPoints As ObjectsEnumerator = Nothing
oPartCompDef.FindUsingRay(pointToCheck, vectorForCheck, .00001, foundObjects, locationPoints)
If (foundObjects.Count = 0) Then
oSketch.NaturalAxisDirection = True
Else If (foundObjects.Count > 0) Then
oSketch.NaturalAxisDirection = False
End If
oSketchPoint.Delete
For i = 0 To oQty-1
Dim oCircle As SketchCircle = oSketch.SketchCircles.AddByCenterRadius(oTG.CreatePoint2d(oFromLeftEdge + (i * oPatternSpacing), oFromFrontEdge), (oHoleSize/2))
Next
Dim oProfile As Profile = oSketch.Profiles.AddForSolid
Dim oExtrude As ExtrudeFeature = oPartCompDef.Features.ExtrudeFeatures.AddByDistanceExtent(oProfile, oThickness*2.54, kNegativeExtentDirection, kCutOperation)