Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

need help on ilogic code create holes on bendlines

0 REPLIES 0
Reply
Message 1 of 1
tkw
Participant
91 Views, 0 Replies

need help on ilogic code create holes on bendlines

is there a way to make this work within an assembly I use it in triggers before save and when I save within assembly I get an error


'[ edit these variables as needed
sSketchName = "Flat Pattern Sketch" sHoleName = "Locator Holes" oOffset = 0.000 'defines offset from edge of flat pattern oDiameter = 0.070 'defines hole diameter '] ' a reference to the active document. Dim oPartDoc As PartDocument oPartDoc = ThisApplication.ActiveDocument 'verify document type is sheet metal If oPartDoc.ComponentDefinition.Type <> 150995200 Then MessageBox.Show("File is not a sheet metal part.", "iLogic") Exit Sub End If Dim oCompDef As SheetMetalComponentDefinition oCompDef = oPartDoc.ComponentDefinition ' Check to make sure a flat pattern is open. If Not TypeOf ThisApplication.ActiveEditObject Is FlatPattern Then Try If oCompDef.HasFlatPattern = False Then oCompDef.Unfold Else oCompDef.FlatPattern.Edit End If Catch MessageBox.Show("Error editting the flat pattern.", "iLogic") End Try End If ' a reference to the active flat pattern. Dim oFlatPattern As FlatPattern oFlatPattern = ThisApplication.ActiveEditObject 'clean up existing holes Dim oHole As HoleFeature For Each oHole In oFlatPattern.Features.HoleFeatures oHole.Delete Next Dim oFace As Face 'oFace = oFlatPattern.BottomFace oFace = oFlatPattern.TopFace Dim oSketch As PlanarSketch 'clean up existing sketch For Each oSketch In oFlatPattern.Sketches If oSketch.Name = sSketchName Then oSketch.Delete End If Next ' Create a new sketch. The second argument specifies to include/not include ' the edges of the face in the sketch. oSketch = oFlatPattern.Sketches.Add(oFace, False) ' Change the name. oSketch.Name = sSketchName ' Create a new object collection for the hole center points. oHoleCenters = ThisApplication.TransientObjects.CreateObjectCollection Dim oTG As TransientGeometry oTG = ThisApplication.TransientGeometry Dim oPoint As Point2d Dim oSketchPoint As SketchPoint 'oOffset = oOffset * 2.5400013716 'converts cm to inches Dim oEdge As Edge Dim oEdges As Edges ' Get all Bend UP edges 'where true = top face oEdges = _ oFlatPattern.GetEdgesOfType( _ FlatPatternEdgeTypeEnum.kBendUpFlatPatternEdge, True) For Each oEdge In oEdges Dim line As SketchLine = oSketch.AddByProjectingEntity(oEdge) Dim startPt As Point2d startPt = line.StartSketchPoint.Geometry Dim endPt As Point2d endPt = line.EndSketchPoint.Geometry If startPt.Y < endPt.Y Then startPt.Y = startPt.Y + oOffset endPt.Y = endPt.Y - oOffset Else startPt.Y = startPt.Y - oOffset endPt.Y = endPt.Y + oOffset End If Dim startSkPt As SketchPoint startSkPt = oSketch.SketchPoints.Add(startPt, True) oSketch.GeometricConstraints.AddGround(startSkPt) Dim endSkPt As SketchPoint endSkPt = oSketch.SketchPoints.Add(endPt, True) oSketch.GeometricConstraints.AddGround(endSkPt) oHoleCenters.Add(startSkPt) oHoleCenters.Add(endSkPt) line.Delete() Next ' Get all Bend Down edges 'where true = top face oEdges = _ oFlatPattern.GetEdgesOfType( _ FlatPatternEdgeTypeEnum.kBendDownFlatPatternEdge, True) For Each oEdge In oEdges Dim line As SketchLine = oSketch.AddByProjectingEntity(oEdge) Dim startPt As Point2d startPt = line.StartSketchPoint.Geometry Dim endPt As Point2d endPt = line.EndSketchPoint.Geometry If startPt.Y < endPt.Y Then startPt.Y = startPt.Y + oOffset endPt.Y = endPt.Y - oOffset Else startPt.Y = startPt.Y - oOffset endPt.Y = endPt.Y + oOffset End If Dim startSkPt As SketchPoint startSkPt = oSketch.SketchPoints.Add(startPt, True) oSketch.GeometricConstraints.AddGround(startSkPt) Dim endSkPt As SketchPoint endSkPt = oSketch.SketchPoints.Add(endPt, True) oSketch.GeometricConstraints.AddGround(endSkPt) oHoleCenters.Add(startSkPt) oHoleCenters.Add(endSkPt) line.Delete() Next ' Create the hole feature. oHole = oFlatPattern.Features.HoleFeatures.AddDrilledByThroughAllExtent( _ oHoleCenters, oDiameter * 2.5400013716 , kPositiveExtentDirection) 'oHoleCenters, oDiameter , kPositiveExtentDirection) oHole.Name = sHoleName oSketch.Visible = True
0 REPLIES 0

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Technology Administrators


Autodesk Design & Make Report