- 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.