iLogic Rectangular Pattern FitToPath using SketchLine

iLogic Rectangular Pattern FitToPath using SketchLine

neodd70
Enthusiast Enthusiast
594 Views
2 Replies
Message 1 of 3

iLogic Rectangular Pattern FitToPath using SketchLine

neodd70
Enthusiast
Enthusiast

I'm having trouble in iLogic getting a rectangular Pattern to use a SketchLine as the FitToPathLength. If I use an edge I select early in the code it works fine but then my hole pattern is set to the length of that edge. What I am trying to do is create a sketch and dimension a line in the sketch Which I can do but now I want to use that line to drive how long the pattern will be but I'm having trouble figuring out how access the sketch line to use in the Rectangular Pattern feature. I'm not a programmer so I am fumbling thru trying to figure this out and I can't seem to find anything in the forums or the API help that indicate how to do this. Any help anyone could give would be greatly appreciated. Here is the code I have so far.

Dim oPartDoc As Document = ThisDoc.Document
Dim oPartCompDef As PartComponentDefinition = ThisApplication.ActiveDocument.ComponentDefinition
Dim oTG As TransientGeometry = ThisApplication.TransientGeometry

'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
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 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")

'Add Sketch and set sketch origin point to the startVertex of the FrontEdge

Dim oSketch As PlanarSketch = oPartCompDef.Sketches.Add(oFace, False)
oSketch.AxisEntity = oFrontEdge
oSketch.OriginPoint = oFrontEdge.StartVertex
oSketch.NaturalAxisDirection = False

'QTY of holes and distance from front, left and right edges
Dim oQty As Integer = 4
Dim oFrontEdgeDistance As Double = ThisApplication.MeasureTools.GetMinimumDistance(oFrontEdge.StartVertex, oFrontEdge.StopVertex)
Dim oFromLeftEdge As Double = FromLeftEdge * 2.54
Dim oFromRightEdge As Double = oFrontEdgeDistance - (FromRightEdge *2.54)
Dim oFromFrontEdge As Double = FromFrontEdge * 2.54
Dim oPatternSpacing As Double = (oFrontEdgeDistance - (oFromLeftEdge + oFromRightEdge)) / (oQty - 1)


Dim oWPLeft As WorkPoint = oPartCompDef.WorkPoints.AddByTwoLines(oLeftEdge, oFrontEdge)
oWPLeft.Visible = False
Dim oLeftDimPoint As SketchPoint = oSketch.AddByProjectingEntity(oWPLeft)
Dim oWPRight As WorkPoint = oPartCompDef.WorkPoints.AddByTwoLines(oRightEdge, oFrontEdge)
oWPRight.Visible = False
Dim oRightDimPoint As SketchPoint = oSketch.AddByProjectingEntity(oWPRight)

Dim oLine As SketchLine = oSketch.SketchLines.AddByTwoPoints(oTG.CreatePoint2d(oFromLeftEdge, oFromFrontEdge), oTG.CreatePoint2d(oFromRightEdge, oFromFrontEdge))

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

'This works and doesn't throw an error but is using a selected edge
'of the solid as the "FitToPathlength" 

'Call oPartCompDef.Features.RectangularPatternFeatures.Add(FeatureColl, oFrontEdge, True, NbrOfHolesLength, _
'DistanceHolesLength * 2.54, PatternSpacingTypeEnum.kFitToPathLength, , , , , , , , , kIdentical)

'This is what I want to use to drive the Pattern Direction because it is a line
'controlled by dimensions and as the part shrinks and grows the pattern of holes
'will adjust accordingly. However this throws an error.
Dim oPatternDir As Object = oSketch.SketchLines.Item(1)
Call oPartCompDef.Features.RectangularPatternFeatures.Add(FeatureColl, ooPatternDir, True, NbrOfHolesLength, _
DistanceHolesLength * 2.54, PatternSpacingTypeEnum.kFitToPathLength, , , , , , , , , kIdentical)

  

595 Views
2 Replies
Replies (2)
Message 2 of 3

Raider_71
Collaborator
Collaborator

Hi I also need help with this. Anyone got any bright ideas for using a sketchline for direction when doing a rectangular pattern?

0 Likes
Message 3 of 3

neodd70
Enthusiast
Enthusiast

@Raider_71  you need to create a path from the sketchline you want to use.

Dim oPatternPath As Object = CompDef.Features.CreatePath(This is the sketchLine you want to use for your pattern)

                oPatternFeature = CompDef.Features.RectangularPatternFeatures.Add(Collection of Features to Pattern, oPatternPath, Direction As A Boolean, PatternQty,
                20(I believe this number is arbitrary if using fit to path length), PatternSpacingTypeEnum.kFitToPathLength, , , , , , , , PatternComputeTypeEnum.kIdenticalCompute, PatternOrientationEnum.kIdentical)

the PatternComputeTypeEnum and PaternOrientationEnum bot set to identical makes it so if your face is not planar then the patterned features will be at the same orientation to the face (wherever they are)  as the parent feature is.

 

It's been a long time since I wrote the code but IIRC that is all correct.  Also this is writen in VB.net so if doing this in iLogic you'll have to adjust some of the arguments, I don't think you have to specify the Enum type on certain things. Like I said it's been a long time plus I don't do anything in iLogic anymore, everything I do is VB.net and are dll's.