Work point pattern with iLogic

Work point pattern with iLogic

uo9K5H5
Contributor Contributor
2,153 Views
8 Replies
Message 1 of 9

Work point pattern with iLogic

uo9K5H5
Contributor
Contributor

Hello,

I try to make a work point pattern using the originally selected sketch. The pattern should be placed between the start and end point and the points should be 3000 mm apart. Here is the program I already have. With this program I can select the surface on which I will make a sketch and all the edges I wont to project. Is there anyone who can help me with point pattern? 

 

Dim oPart As PartDocument = ThisApplication.ActiveDocument
Dim oDef As PartComponentDefinition = oPart.ComponentDefinition

Dim oFace As Inventor.Face
SelectFace :
oFace = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kPartFacePlanarFilter, "Select Face to Place Sketch")
If oFace Is Nothing Then
	MsgBox("No face was selected. Exiting.",,"")
	Exit Sub
ElseIf oFace.SurfaceType <> SurfaceTypeEnum.kPlaneSurface Then
	MsgBox("Selected face was not planar. Please select planar (flat) face.", , "")
	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, "Select a edge") 
	' 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("oEdges.Count = " & oEdges.Count & vbCrLf & _
	"oPoints.Count = " & oPoints.Count,,"")
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
0 Likes
Accepted solutions (1)
2,154 Views
8 Replies
Replies (8)
Message 2 of 9

Michael.Navara
Advisor
Advisor
Accepted solution

Here is sample code and test data how to create "workpoint pattern" defined by sketch entities.

'Length between points
Dim length As Double = 100 '[cm]

Dim part As PartDocument = ThisDoc.Document
Dim oSketch As PlanarSketch = part.ComponentDefinition.Sketches(2)
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

 

Message 3 of 9

uo9K5H5
Contributor
Contributor
 
 
 
 
 

Thank you for your code. It works just like i wanted. Is it possible that you can help me with inserting you code into mine. That it will work for each selected sketch separately.

0 Likes
Message 4 of 9

pramod.patel
Participant
Participant

Adding further to this task: I want to add work-axes through these points perpendicular to plane-XY, I have tried it but I am getting the error- "Parameter is incorrect" I am adding my codes here with the work-axis creating line commented out. Please guide me to correct the code so that I can create the work-axes, Thanks a lot in advance:

 

Dim length As Double = 1 '[cm]

Dim part As PartDocument = ThisDoc.Document
Dim oSketch As PlanarSketch = part.ComponentDefinition.Sketches(1)
Dim app As Application = oSketch.Application
Dim oPlane As WorkPlane
oPlane = part.ComponentDefinition.WorkPlanes.Item("XY Plane")
Dim oAxis As WorkAxes
oAxis = part.ComponentDefinition.WorkAxes
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
	Dim oWAxis As WorkAxis
    For Each point3D As Point In points3D
        workPoints.AddFixed(point3D)
		oWAxis=part.ComponentDefinition.WorkAxes.AddByNormalToSurface(oPlane, WorkPoints)
		Next
			    
Next

 

0 Likes
Message 5 of 9

Michael.Navara
Advisor
Advisor

You are not able to create WorkAxis by WorkPlane and Point. You need to create work points first. Add this workpoints to some collection or use them for creation of work axes directly

 

 

...

	'Create WorkPoints and WorkAxes
	Dim oWorkAxes As WorkAxes = part.ComponentDefinition.WorkAxes
	Dim xyWorkPlane = part.ComponentDefinition.WorkPlanes(3)
	For Each point3D As Point In points3D
		Dim wp As WorkPoint = workPoints.AddFixed(point3D)
		Dim wa As WorkAxis = oWorkAxes.AddByNormalToSurface(xyWorkPlane, wp)
	Next
...

 

Message 6 of 9

pramod.patel
Participant
Participant

Thankyou for your reply and it works fine on a regular continuous closed figure, for example I have tried it on a circle and with the defined pitch it distributed the work points. But, I need to create the points on an irregular sketch which is a skeleton sketch for the arrangement of the heavy machines track plates. The overall sketch length is around 31000mm and those points are to be arranged at the pitch length of 550mm, when I ran the code on my sketch to create the points, then it creates the point at all the points of the individual curve segments, rather when I defined the pitch in the beginning then I need it to distribute those points following the pitch length around the whole sketch. Please refer to my sketch attached here the rule could also be run and the effect could be seen in the sketch. I will be highly thankful for the relevant changes in the script to create those points at a defined pitch all over the skeleton sketch. 

0 Likes
Message 7 of 9

adam.nagy
Autodesk Support
Autodesk Support

The simplest might be if you automate the instructions here:
https://grabcad.com/tutorials/tutorial-how-to-pattern-along-a-geometry-line-in-autodesk-inventor 

Just instead of selecting a Hole feature, you would select a WorkPoint and distribute those along the sketch lines

adamnagy_0-1643114923576.png

You just need to place the starting WorkPoint and figure out how many others will need to be placed along the sketch lines. In order to find the full length of the sketch lines, you could create a profile from the sketch and use RegionProperties.Perimeter:

https://adndevblog.typepad.com/manufacturing/2015/10/face-to-planarsketch.html 



Adam Nagy
Autodesk Platform Services
0 Likes
Message 8 of 9

pramod.patel
Participant
Participant

Thankyou Mr. Nagy for your response! Yes, This is surely a simplest way, but I need the work features at later stage for the generation of iMates. Also the the point distribution which we are getting here, I need the straight line distance between concecutive points equal to my pitch value which is 550mm here. So the point distributions should be at a chord-pitch length of 550mm. Is there any method while we use the 'curve evaluator' in iLogic to make points on a random curve at the chord lengths?

Thanks again for the your response!

 

0 Likes
Message 9 of 9

nedeljko.sovljanski
Advocate
Advocate

Hi @pramod.patel 

Solution for "chain" problem is not simple. It is easy to describe but difficult for realize. First you need collection of all curves in sketch which creates continuous line. Then use start point from first curve and find intersection between first curve and circle r=550mm. You have more than one solution. Pick correct one and use it as center for next circle, and so on... Pay attention some solution could be found on adjacent curve. At the end last point must fall on first point. If it not case correct radius of top middle curve and run same process again.

As I said it will not be easy but when you find solution you will feel beauty of coding. 😊