Message 1 of 5
Automatization of a iLogic program
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello,
I have an iLogic program that sets points on every edge that I select. But now I would like to make a program that would at once set points all over the part, but only on one of the surfaces. Rather I would like to optimize the program that would take less time to set these points all around the part. Here is the program:
Dim oPart As PartDocument = ThisApplication.ActiveDocument Dim oDef As PartComponentDefinition = oPart.ComponentDefinition Dim oFace As Inventor.Face SelectFace : oFace = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kPartFacePlanarFilter, "Izberi ravnino za postavitev skice.") If oFace Is Nothing Then MsgBox("Nobena površina ni bila izbrana.",,"") Exit Sub ElseIf oFace.SurfaceType <> SurfaceTypeEnum.kPlaneSurface Then MsgBox("Izbrana ravninan ni bila ravna. Prosim, izberite ravno površino.", , "") GoTo SelectFace End If Dim oSketch As PlanarSketch = oDef.Sketches.Add(oFace, False) Dim oTO As TransientObjects = ThisApplication.TransientObjects Dim oEdges As ObjectCollection = oTO.CreateObjectCollection Dim oPoints As ObjectCollection = oTO.CreateObjectCollection Dim oEdge As Edge Dim oPoint As Inventor.Point Do oEdge = ThisApplication.CommandManager.Pick( _ SelectionFilterEnum.kPartEdgeFilter, "Izberi rob.") ' If nothing gets selected then we're done If oEdge IsNot Nothing Then oEdges.Add(oEdge) Else Exit Do End If Dim oSE As SketchEntity = oSketch.AddByProjectingEntity(oEdge) If TypeOf oSE Is SketchLine Then Dim oSL As SketchLine = oSE oPoints.Add(oSL.StartSketchPoint.Geometry3d) oPoints.Add(oSL.EndSketchPoint.Geometry3d) ElseIf TypeOf oSE Is SketchArc Then Dim oSA As SketchArc = oSE oPoints.Add(oSA.StartSketchPoint.Geometry3d) oPoints.Add(oSA.EndSketchPoint.Geometry3d) End If MsgBox("Pritisni ESC, ko si končal z izbiro robov!" & vbCrLf & "(Opozorilno okno naj bo takrat še odprto)", , "Opozorilo") 'MsgBox("oEdges.Count = " & oEdges.Count & vbCrLf & _ '"oPoints.Count = " & oPoints.Count & vbCrLf & "Pritisni ESC, ko si končal z izbiro robov!" & vbCrLf & '"(Opozorilno okno naj bo takrat še odprto)", , "Opozorilo") Loop Until oEdge Is Nothing For Each oPoint In oPoints Dim oDuplicate As Boolean = False Dim oWP As WorkPoint = Nothing For Each oWP In oDef.WorkPoints If oWP.Point.X = oPoint.X And _ oWP.Point.Y = oPoint.Y And _ oWP.Point.Z = oPoint.Z Then oDuplicate = True End If Next If oDuplicate = False Then oWP = oDef.WorkPoints.AddFixed(oPoint, False) End If Next 'Length between points Dim length As Double = 300 '[cm] Dim part As PartDocument = ThisDoc.Document Dim app As Application = oSketch.Application Dim workPoints = part.ComponentDefinition.WorkPoints For Each skEntity As SketchEntity In oSketch.SketchEntities If skEntity.Construction Then Continue For 'Try to get evaluator Dim evaluator As Curve2dEvaluator Try evaluator = skEntity.Geometry.Evaluator Catch 'SketchPoints has no evaluator Continue For End Try 'Get curve parameter extents Dim minParam As Double Dim maxParam As Double evaluator.GetParamExtents(minParam, maxParam) 'Get curve parameters by length Dim ptParam As Double Dim ptParams As New List(Of Double) Dim i = 0 Do evaluator.GetParamAtLength(minParam, length * i, ptParam) ptParams.Add(ptParam) i += 1 Loop While ptParam < maxParam 'Get point coordinates from curve parameters Dim ptCoords As Double() = {} evaluator.GetPointAtParam(ptParams.ToArray(), ptCoords) 'Convert 2D coordinates in sketch to 3D coordinates in model space Dim points3D As New List(Of Point) For j = 0 To ptCoords.Length - 2 Step 2 Dim x = ptCoords(j) Dim y = ptCoords(j + 1) Dim pt2D = app.TransientGeometry.CreatePoint2d(x, y) Dim pt3D = oSketch.SketchToModelSpace(pt2D) points3D.Add(pt3D) Next 'Create WorkPoints For Each point3D As Point In points3D workPoints.AddFixed(point3D) Next Next