Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.

iLogic Coding of 500x500 square sketch

solomon7JX9D
Explorer

iLogic Coding of 500x500 square sketch

solomon7JX9D
Explorer
Explorer

Can anyone solve this code to create a rectangle using iLogic?

It tells me the 'Origin' on 'PlanarSketch' not found.

 

' Get the active document
Dim invDoc As Inventor.Document = ThisApplication.ActiveDocument

' Get the active sketch plane
Dim sketchPlane As PlanarSketch = invDoc.ComponentDefinition.Sketches.Add(invDoc.ComponentDefinition.WorkPlanes.Item(3))

' Define rectangle dimensions
Dim rectangleWidth As Double = 500
Dim rectangleHeight As Double = 500

' Set the origin of the sketch plane to (0,0,0)
sketchPlane.Origin = ThisApplication.TransientGeometry.CreatePoint(0, 0, 0)

' Create the rectangle
Dim startPoint As SketchPoint = sketchPlane.SketchPoints.Add(ThisApplication.TransientGeometry.CreatePoint2d(0, 0))
Dim endPoint As SketchPoint = sketchPlane.SketchPoints.Add(ThisApplication.TransientGeometry.CreatePoint2d(rectangleWidth, rectangleHeight))
Dim line1 As SketchLine = sketchPlane.SketchLines.AddByTwoPoints(startPoint, sketchPlane.SketchPoints.Add(ThisApplication.TransientGeometry.CreatePoint2d(rectangleWidth, 0)))
Dim line2 As SketchLine = sketchPlane.SketchLines.AddByTwoPoints(line1.EndSketchPoint, endPoint)
Dim line3 As SketchLine = sketchPlane.SketchLines.AddByTwoPoints(endPoint, sketchPlane.SketchPoints.Add(ThisApplication.TransientGeometry.CreatePoint2d(0, rectangleHeight)))
Dim line4 As SketchLine = sketchPlane.SketchLines.AddByTwoPoints(line3.EndSketchPoint, startPoint)

' Update the sketch
sketchPlane.Update()
0 Likes
Reply
Accepted solutions (1)
255 Views
1 Reply
Reply (1)

petr.meduna
Advocate
Advocate
Accepted solution

PlanarSketch has OriginPoint where you can set workpoint, vertex or sketchpoint. So, use default workpoint instead.

sketchPlane.OriginPoint = invDoc.ComponentDefinition.workpoints.Item(1)

 

Also, you cannot update sketch, only document.

invDoc.Update()