Message 1 of 5
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I have iLogic code to create a new sketch, draw a line on that sketch and then create a hole and a rectangular pattern of that hole. I am trying to use the line I created in the sketch as the direction line for the pattern so i can set the pattern to curve length. This way my hole pattern will auto update if my part changes size. My problem is that i cannot seem to figure out how to have the pattern reference the line in my sketch as the direction curve. Here is what I have so far. Any help would be greatly appreciated.
Class ThisRule Dim oPartDoc As Document Dim oPartCompDef As PartComponentDefinition Dim oTG As TransientGeometry Dim oSketchPoint As SketchPoint Dim SketchPointParentSketch As PlanarSketch Dim vectorForCheck As UnitVector Dim pointToCheck As Point Dim foundObjects As ObjectsEnumerator Dim locationPoints As ObjectsEnumerator Dim oFace As Face Dim oFrontEdge As Edge Dim oLeftEdge As Edge Dim oRightEdge As Edge Dim oSketch As PlanarSketch Dim oQty As Integer Dim oFromLeftEdge As Double Dim oFromRightEdge As Double Dim oFromFrontEdge As Double Dim oFrontEdgeDistance As Double Dim oPatternSpacing As Double End Class Sub Main() oPartDoc = ThisDoc.Document oPartCompDef = ThisApplication.ActiveDocument.ComponentDefinition oTG = ThisApplication.TransientGeometry 'get measurements to determine Material Thickness Dim My_x As Double = Measure.ExtentsLength Dim My_y As Double = Measure.ExtentsWidth Dim My_z As Double = Measure.ExtentsHeight 'Make shortest value the Thickness, rounded to 4 places Dim oThickness As Double = Round(MinOfMany(My_x, My_y, My_z), 4) 'Select Face and Edges to dimension sketch circles from oFace = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kPartFaceFilter, "Select Surface to Place Holes") oFrontEdge = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kPartEdgeFilter, "Select Front Edge of Pattern") oLeftEdge = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kPartEdgeFilter, "Select Left Edge of Pattern") oRightEdge = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kPartEdgeFilter, "Select Right Edge of Pattern") Dim oMaterial As String = MaterialType Dim oHoleType As String = HoleType Dim oHoleSize As Double = HoleSizes * 2.54 'Add Sketch and set sketch origin point to the startVertex of the FrontEdge oSketch = oPartCompDef.Sketches.Add(oFace, False) oSketch.AxisEntity = oFrontEdge oSketch.OriginPoint = oFrontEdge.StartVertex oSketch.NaturalAxisDirection = True 'Create the name for the sketch based on user assigned parameters 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 'Check all sketches in the model tree and compare the names to the 'name of the newly created sketch and if name exists increment the 'suffix by 1. Continue until the newly created sketch name is unique 'and can be used. For Each oSketchNameCheck As Sketch In oPartCompDef.Sketches If Left(oSketchNameCheck.Name,oNameCharCount) = oNameCompare Then Dim oSketchNumber As Integer = Val(Mid(oSketchNameCheck.Name, oNameNumCount, 2)) While oSketchNameSuffix <= oSketchNumber oSketchNameSuffix = oSketchNameSuffix + 1 End While End If Next oSketch.Name = oNameCompare & oSketchNameSuffix 'QTY of holes and distance from front, left and right edges oQty = 4 oFrontEdgeDistance = ThisApplication.MeasureTools.GetMinimumDistance(oFrontEdge.StartVertex, oFrontEdge.StopVertex) oFromLeftEdge = FromLeftEdge * 2.54 oFromRightEdge = oFrontEdgeDistance - (FromRightEdge *2.54) oFromFrontEdge = FromFrontEdge * 2.54 oPatternSpacing = (oFrontEdgeDistance - (oFromLeftEdge + oFromRightEdge)) / (oQty - 1) Call oSketch.SketchLines.AddByTwoPoints(oTG.CreatePoint2d(oFromLeftEdge, oFromFrontEdge), oTG.CreatePoint2d(oFromRightEdge, oFromFrontEdge)) 'Dim oSketchLine As SketchEntitiesEnumerator = oSketch.SketchLines.Item(1) 'Dim oLine as oSketchLines = oSketch.SketchLines.Item(1) 'create a sketch point to check if the coordinate system needs 'To be flipped so the circles fall inside the parent part. OriginCheck() If (foundObjects.Count = 0) Then oSketch.NaturalAxisDirection = False OriginCheck() If (foundObjects.Count = 0) Then oSketch.NaturalAxisDirection = True oSketch.OriginPoint = oFrontEdge.StopVertex OriginCheck() If (foundObjects.Count = 0) Then oSketch.NaturalAxisDirection = False OriginCheck() End If End If End If oSketchPoint.Delete Dim oPoint As Point = oSketch.SketchToModelSpace(oTG.CreatePoint2d(oFromleftEdge, oFromFrontEdge)) Dim oLinearPlacementDef As LinearHolePlacementDefinition = oPartCompDef.Features.HoleFeatures.CreateLinearPlacementDefinition(oFace, oLeftEdge, oFromLeftEdge, oFrontEdge, oFromFrontEdge, oPoint) Call oPartCompDef.Features.HoleFeatures.AddDrilledByThroughAllExtent(oLinearPlacementDef, ".156in", kPositiveExtentDirection) ' Create the object collection. Dim FeatureColl As ObjectCollection = ThisApplication.TransientObjects.CreateObjectCollection ' Add the newly created hole feature to the collection. Call FeatureColl.Add(oPartCompDef.Features.HoleFeatures.Item(1)) ' Number of elements (X axis) Dim NbrOfHolesLength As Integer NbrOfHolesLength = 2 ' Distance between elements. Dim DistanceHolesLength As Double DistanceHolesLength = 1 ' Number of elements (Y axis) Dim NbrOfHolesWidth As Integer NbrOfHolesWidth = 1 ' Distance between elements. Dim DistanceHolesWidth As Double DistanceHolesWidth = 1 ' Create the pattern. 'Call oPartCompDef.Features.RectangularPatternFeatures.Add(FeatureColl, oFrontEdge, True, NbrOfHolesLength, _ 'DistanceHolesLength * 2.54, kDefault, , oLeftEdge, True, NbrOfHolesWidth, DistanceHolesWidth * 2.54, _ 'kDefault, , , kIdentical) Call oPartCompDef.Features.RectangularPatternFeatures.Add(FeatureColl, oFrontEdge, True, NbrOfHolesLength, _ DistanceHolesLength * 2.54, PatternSpacingTypeEnum.kFitToPathLength, , , , , , , , , kIdentical) 'oSketch.Delete() End Sub Public Sub OriginCheck() oSketchPoint = oSketch.SketchPoints.Add(oTG.CreatePoint2d(oFromLeftEdge, oFromFrontEdge)) SketchPointParentSketch = oSketchPoint.Parent vectorForCheck = SketchPointParentSketch.PlanarEntityGeometry.Normal pointToCheck = oSketchPoint.Geometry3d foundObjects = Nothing locationPoints = Nothing oPartCompDef.FindUsingRay(pointToCheck, vectorForCheck, .00001, foundObjects, locationPoints) End Sub
Solved! Go to Solution.