- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi everyone,
I'm quite new to iLogic.
I'm trying to run a rule with event triggers (Part Geometry Change, Before Save Document). This rule may only run if the part is a sheetmetal document with a flatpattern view in it.
The rule detects bendlines in a flatpattern and places holes on the start and end points of the bendlines. (Sub bendmarker code borrowed from @danmorick, and sub main code borrowed from @Owner2229 edited a little)
The problem I have with this rule is, the rule also runs in an assembly (If I edit a sheetmetal part and update the assembly), but the main sub must prevent it from running in a document other than a sheetmetal. Inventor somehow runs this in the background in the sheetmetal parts? (even when the sheetmetal parts are not opened.
SyntaxEditor Code Snippet
SyntaxEditor Code Snippet
Sub Main() 'Check if open document is sheetmetal '---------------------------------------------------------------------------------------------------------- Dim oDoc As PartDocument = ThisApplication.ActiveDocument 'Dim oDoc As PartDocument = ThisDoc.Document 'Controle of document een sheetmetal document is. If oDoc.DocumentSubType.DocumentSubTypeID <> "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}" Then Exit Sub End If 'Check if open sheetmetal document has flatpattern view '----------------------------------------------------------------------------------------------------------- Dim oSMD As ComponentDefinition = oDoc.ComponentDefinition If oDoc.SubType = "{4D29B490-49B2-11D0-93C3-7E0706000000}" Then ElseIf oSMD.FlatPattern Is Nothing Then Exit Sub End If 'Check if feature "BendMarkerHoles" exists '----------------------------------------------------------------------------------------------------------- Dim FeatureName As String = "BendMarkerHoles" If Not oSMD.HasFlatPattern Then Exit Sub End If Dim oFTS As FlatPatternFeatures = oSMD.FlatPattern.Features If oFTS.Count = 0 Then BendMarker Exit Sub End If Dim MyFT As PartFeature = Nothing For Each oFT As PartFeature In oFTS If oFT.Name = FeatureName Then MyFT = oFT Exit For End If Next If Not MyFT Is Nothing Then Try oFTS("BendMarkerHoles").delete Catch End Try BendMarker Exit Sub Else BendMarker End If End Sub Sub BendMarker() Dim oDoc As PartDocument = ThisApplication.ActiveDocument Dim oSMD As ComponentDefinition = oDoc.ComponentDefinition Dim oEdge As Edge Dim oEdges As Edges Dim oEnt As SketchEntity Dim oTransGeom As TransientGeometry = ThisApplication.TransientGeometry Dim oHoleCenters As Object = ThisApplication.TransientObjects.CreateObjectCollection Dim CordXS As Double Dim CordYS As Double Dim CordXE As Double Dim CordYE As Double Dim oSketch As PlanarSketch Dim oFlat As FlatPattern = oSMD.FlatPattern Dim oSP As SketchPoint Dim oEP As SketchPoint 'Flatpattern sketch ------------------------------------------------------------------------- oSketch = oFlat.Sketches.Add(oFlat.TopFace, False) oSketch.Edit 'Detect bend down --------------------------------------------------------------------------- oEdges = oFlat.GetEdgesOfType(64005, True) For Each oEdge In oEdges oEnt = oSketch.AddByProjectingEntity(oEdge) CordXS = oEnt.StartSketchPoint.Geometry.X CordYS = oEnt.StartSketchPoint.Geometry.Y X = CordXS Y = CordYS oSP = oSketch.SketchPoints.Add(oTransGeom.CreatePoint2d(X,Y), True) oHoleCenters.Add (oSP) CordYE = oEnt.EndSketchPoint.Geometry.Y X = CordXE Y = CordYE oEP = oSketch.SketchPoints.Add(oTransGeom.CreatePoint2d(X,Y), True) oHoleCenters.Add (oEP) Next 'Detect bend up ------------------------------------------------------------------------------ oEdges = oFlat.GetEdgesOfType(64004, True) For Each oEdge In oEdges oEnt = oSketch.AddByProjectingEntity(oEdge) CordXS = oEnt.StartSketchPoint.Geometry.X CordYS = oEnt.StartSketchPoint.Geometry.Y X = CordXS Y = CordYS oSP = oSketch.SketchPoints.Add(oTransGeom.CreatePoint2d(X,Y), True) oHoleCenters.Add (oSP) CordXE = oEnt.EndSketchPoint.Geometry.X CordYE = oEnt.EndSketchPoint.Geometry.Y X = CordXE Y = CordYE oEP = oSketch.SketchPoints.Add(oTransGeom.CreatePoint2d(X,Y), True) oHoleCenters.Add (oEP) Next Call oSMD.FlatPattern.Features.HoleFeatures.AddDrilledByThroughAllExtent(oHoleCenters, 0.1, kPositiveExtentDirection) Try Dim oHoleFeat As HoleFeature oHoleFeat = oSMD.FlatPattern.Features.HoleFeatures.Item(1) oHoleFeat.Name = "BendMarkerHoles" Catch End Try oSketch.ExitEdit oSketch.Name = "MarkedBends" End Sub
Kind regards,
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Relevant
https://forums.autodesk.com/t5/inventor-ideas/sheet-metal-bendline-details/idc-p/6795343#M16036
Did you find this reply helpful ? If so please use the Accept as Solution or Kudos button below.
___________________________- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hey, how about this? Orange is the only "real" change, the rest is just simplification.
Sub Main()
'Check if open document is sheetmetal
'---------------------------------------------------------------------------------------------
Dim oDoc As Document = ThisApplication.ActiveDocument
If oDoc.DocumentSubType.DocumentSubTypeID <> "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}" Then Exit Sub
'Check if open sheetmetal document has flatpattern view
'---------------------------------------------------------------------------------------------
Dim oSMD As ComponentDefinition = oDoc.ComponentDefinition
If Not oSMD.HasFlatPattern Then Exit Sub
Dim oFlat As FlatPattern = oSMD.FlatPattern
'Check if feature "BendMarkerHoles" exists
'---------------------------------------------------------------------------------------------
Dim FeatureName As String = "BendMarkerHoles"
Dim oFTS As FlatPatternFeatures = oFlat.Features
If oFTS.Count > 0 Then
For Each oFT As PartFeature In oFTS
If oFT.Name <> FeatureName Then Continue For
Try
oFT.Delete()
Catch
End Try
Exit For
Next
End If
BendMarker(oFlat)
End Sub
Sub BendMarker(oFlat As FlatPattern)
Dim oEdges As Edges
Dim oHoleCenters As Object = ThisApplication.TransientObjects.CreateObjectCollection
'Flatpattern sketch -------------------------------------------------------------------------
Dim oSketch As PlanarSketch = oFlat.Sketches.Add(oFlat.TopFace, False)
oSketch.Edit()
'Detect bend down ---------------------------------------------------------------------------
oEdges = oFlat.GetEdgesOfType(64005, True)
WorkEdges(oHoleCenters, oSketch, oEdges)
'Detect bend up -----------------------------------------------------------------------------
oEdges = oFlat.GetEdgesOfType(64004, True)
WorkEdges(oHoleCenters, oSketch, oEdges)
Call oFlat.Features.HoleFeatures.AddDrilledByThroughAllExtent(oHoleCenters, 0.1, kPositiveExtentDirection)
Try
Dim oHoleFeat As HoleFeature = oFlat.Features.HoleFeatures.Item(1)
oHoleFeat.Name = "BendMarkerHoles"
Catch
End Try
oSketch.ExitEdit()
oSketch.Name = "MarkedBends"
End Sub
Sub WorkEdges(ByRef oHoleCenters As Object, ByRef oSketch As PlanarSketch, oEdges As Edges)
Dim oTG As TransientGeometry = ThisApplication.TransientGeometry
For Each oEdge As Edge In oEdges
Dim oEnt As SketchEntity = oSketch.AddByProjectingEntity(oEdge)
Dim P As Point2d = oEnt.StartSketchPoint.Geometry
Dim oSP As SketchPoint = oSketch.SketchPoints.Add(oTG.CreatePoint2d(P.X, P.Y), True)
oHoleCenters.Add (oSP)
P = oEnt.EndSketchPoint.Geometry
Dim oEP As SketchPoint = oSketch.SketchPoints.Add(oTG.CreatePoint2d(P.X, P.Y), True)
oHoleCenters.Add (oEP)
Next
End Sub
- - - - - - - - - - - - - - -
Regards,
Mike
"Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live." - John F. Woods
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I have another question.
The rule also detect bend lines from a lofted flange. The problem is, a lofted flange has a lot of bend lines close to each other. The blue circle in the picture indicates where the bendmarkerpoints are too close to each other.
Is there a way to concentrate the points close to each other to a single point, or maybe another solution?