Automatization of a iLogic program

Automatization of a iLogic program

uo9K5H5
Contributor Contributor
423 Views
4 Replies
Message 1 of 5

Automatization of a iLogic program

uo9K5H5
Contributor
Contributor

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

 

0 Likes
424 Views
4 Replies
Replies (4)
Message 2 of 5

chandra.shekar.g
Autodesk Support
Autodesk Support

@uo9K5H5,

 

Please provide non confidential part file and resultant part file after executing iLogic program.

 

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



0 Likes
Message 3 of 5

uo9K5H5
Contributor
Contributor

Hi, Here are the files. And I would also like not to have massage box whenever I select a new edge. 

0 Likes
Message 4 of 5

chandra.shekar.g
Autodesk Support
Autodesk Support

@uo9K5H5,

 

Expected result after executing iLogic program?

 

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



0 Likes
Message 5 of 5

uo9K5H5
Contributor
Contributor

The entire geometry in the picture represents the path of the cable tray. My goal is to divide the entire geometry into several smaller 3000 mm long segments. I am going to use Frame Insert feature to insert 3000 mm long frames. Frame Insert can not insert custom length profiles, but It can just make the profile through the entire selected edge or between two points. So that is why I need work points to be patterned across the edge. The program work in the following order:

1.  Run the rule

2.  Select a face for sketch and all the edges which are automatically saved in a sketch with a unique name

3.  First work point to be placed on the starting end of sketched edges

4.  All the rest work points patterned across the made path. 

Now what I would like to achieve is that I will run the rule and all the edges on one side of the geometry will be selected. And i would like to know how to turn off the massage box to pop out whenever I am selecting an edge. 

 

0 Likes