Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Auto Drawing Rolling check measurements, Issues with ilogic Intersection points.

3 REPLIES 3
SOLVED
Reply
Message 1 of 4
roy_pridham
155 Views, 3 Replies

Auto Drawing Rolling check measurements, Issues with ilogic Intersection points.

Hello, got stuff with some ilogic code, I'm trying to create 3 lines with ilogic cade and its harder then expected.

I find myself drawing the same sketch 20 - 30 times a day and i want to automate it.

 

Any ideas of pointers as to where too from here i would be glad to know.

 

I'm stuck i cant seem to find the intersection point on the curve using the circles.

 

This is what i want to draw, 1m straight line from Arc start point and 2m straight line from Arc End point touching the curve:

roy_pridham_1-1718573672434.png

 

This is the code i have done so far:

 

 

Sub Main()
    ' Prompt the user to select a view in the drawing
    Dim oView As DrawingView
    oView = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kDrawingViewFilter, "Select a view")

    ' Check if a view was selected
    If oView Is Nothing Then
        MessageBox.Show("No view selected. Exiting script.")
        Exit Sub
    End If

    ' Create a sketch in the selected view
    Dim oSketch As DrawingSketch
    oSketch = oView.Sketches.Add()

    ' Project all entities in the view onto the sketch
    Dim oDrawingCurves As DrawingCurvesEnumerator
    oDrawingCurves = oView.DrawingCurves
    Dim oProjectedEntities As ObjectCollection
    oProjectedEntities = ThisApplication.TransientObjects.CreateObjectCollection()

    For Each oCurve As DrawingCurve In oDrawingCurves
        oProjectedEntities.Add(oSketch.AddByProjectingEntity(oCurve))
    Next

    ' Open the sketch for editing
    oSketch.Edit()

    ' Prompt the user to select a curve in the sketch
    Dim oSelectedEntity As Object
    oSelectedEntity = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kSketchCurveFilter, "Select a curve")

    ' Check if the selected entity is a SketchArc or SketchLine
    Dim oSelectedCurve As SketchEntity
    If TypeOf oSelectedEntity Is SketchArc Or TypeOf oSelectedEntity Is SketchLine Then
        oSelectedCurve = oSelectedEntity

        ' Get the start and end points of the selected curve
        Dim oStartPoint As Point2d
        Dim oEndPoint As Point2d
        If TypeOf oSelectedCurve Is SketchArc Then
            oStartPoint = CType(oSelectedCurve, SketchArc).StartSketchPoint.Geometry
            oEndPoint = CType(oSelectedCurve, SketchArc).EndSketchPoint.Geometry
        ElseIf TypeOf oSelectedCurve Is SketchLine Then
            oStartPoint = CType(oSelectedCurve, SketchLine).StartSketchPoint.Geometry
            oEndPoint = CType(oSelectedCurve, SketchLine).EndSketchPoint.Geometry
        End If

        ' Create a circle at the start point of the selected curve with radius 2000 mm (2 meters)
        Dim radiusStart As Double = 2000.0 ' in mm
        Dim oCircleStart As SketchCircle
        oCircleStart = oSketch.SketchCircles.AddByCenterRadius(oStartPoint, radiusStart)

        ' Create a circle at the end point of the selected curve with radius 1000 mm (1 meter)
        Dim radiusEnd As Double = 1000.0 ' in mm
        Dim oCircleEnd As SketchCircle
        oCircleEnd = oSketch.SketchCircles.AddByCenterRadius(oEndPoint, radiusEnd)

        ' Draw a line between the start and end points of the selected curve
        oSketch.SketchLines.AddByTwoPoints(oStartPoint, oEndPoint)

    Else
        MessageBox.Show("The selected entity is not a curve.")
        oSketch.ExitEdit()
        Exit Sub
    End If

    ' Exit sketch edit mode
    oSketch.ExitEdit()
End Sub

 

 

This is what it draws:

roy_pridham_0-1718573556357.png

 

 

3 REPLIES 3
Message 2 of 4
JelteDeJong
in reply to: roy_pridham

you could try something like this. I have drawn the circle just like you but instead of getting the intersection point I constraint the line to the circle and then to the selected curve. (Also keep in mind that the Inventor API works with cm instead of mm)

Sub Main()

    Dim doc As DrawingDocument = ThisDoc.Document
    Dim sheet As Sheet = doc.ActiveSheet

    Dim curveSegment As DrawingCurveSegment = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kDrawingCurveSegmentFilter, "")
    Dim curve As DrawingCurve = curveSegment.Parent
    Dim view As DrawingView = curve.Parent

    Dim sketch As DrawingSketch = view.Sketches.Add()
    Dim sketchCurve = sketch.AddByProjectingEntity(curve)

    If TypeOf sketchCurve Is SketchArc Or TypeOf sketchCurve Is SketchLine Then
        sketch.Edit()

        Dim startSketchPoint As SketchPoint
        Dim endSketchPoint As SketchPoint
        If TypeOf sketchCurve Is SketchArc Then
            startSketchPoint = CType(sketchCurve, SketchArc).StartSketchPoint
            endSketchPoint = CType(sketchCurve, SketchArc).EndSketchPoint
        ElseIf TypeOf sketchCurve Is SketchLine Then
            startSketchPoint = CType(sketchCurve, SketchLine).StartSketchPoint
            endSketchPoint = CType(sketchCurve, SketchLine).EndSketchPoint
        End If

        DrawLine(sketch, startSketchPoint, sketchCurve, 200)
        DrawLine(sketch, endSketchPoint, sketchCurve, 100)

        sketch.ExitEdit()
    Else
        MessageBox.Show("The selected entity is not a curve.")
    End If

End Sub

Private Sub DrawLine(sketch As DrawingSketch, point As SketchPoint, curve As SketchEntity, Length As Double)
    Dim circle As SketchCircle = sketch.SketchCircles.AddByCenterRadius(point, Length)
    circle.SketchOnly = True
    sketch.GeometricConstraints.AddCoincident(circle.CenterSketchPoint, point)
    sketch.DimensionConstraints.AddDiameter(circle, circle.CenterSketchPoint.Geometry)

    Dim orign = ThisApplication.TransientGeometry.CreatePoint2d(0, 0)
    Dim l1 = sketch.SketchLines.AddByTwoPoints(point, orign)
    sketch.GeometricConstraints.AddCoincident(l1.EndSketchPoint, curve)
    sketch.GeometricConstraints.AddCoincident(l1.EndSketchPoint, circle)
End Sub

 

Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature


Blog: hjalte.nl - github.com

Message 3 of 4
roy_pridham
in reply to: roy_pridham

THANK YOU VERY MUCH 😎. I have spent way to long trying to get this to work.

Message 4 of 4
Stakin
in reply to: JelteDeJong

 

Sub Main()

    Dim doc As DrawingDocument = ThisDoc.Document
    Dim sheet As Sheet = doc.ActiveSheet

    Dim curveSegment As DrawingCurveSegment = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kDrawingCurveSegmentFilter, "")
    Dim curve As DrawingCurve = curveSegment.Parent
    Dim view As DrawingView = curve.Parent

    Dim sketch As DrawingSketch = view.Sketches.Add()
    Dim sketchCurve = sketch.AddByProjectingEntity(curve)

    If TypeOf sketchCurve Is SketchArc Or TypeOf sketchCurve Is SketchLine Then
        sketch.Edit()

        Dim startSketchPoint As SketchPoint
        Dim endSketchPoint As SketchPoint
        If TypeOf sketchCurve Is SketchArc Then
            startSketchPoint = CType(sketchCurve, SketchArc).StartSketchPoint
            endSketchPoint = CType(sketchCurve, SketchArc).EndSketchPoint
        ElseIf TypeOf sketchCurve Is SketchLine Then
            startSketchPoint = CType(sketchCurve, SketchLine).StartSketchPoint
            endSketchPoint = CType(sketchCurve, SketchLine).EndSketchPoint
        End If

        DrawLine(sketch, startSketchPoint, sketchCurve, 200)
        DrawLine(sketch, endSketchPoint, sketchCurve, 100)

        sketch.ExitEdit()
    Else
        MessageBox.Show("The selected entity is not a curve.")
    End If

End Sub

Private Sub DrawLine(sketch As DrawingSketch, point As SketchPoint, curve As SketchEntity, Length As Double)
	Dim oP02d As Point2d
	Dim oX1 As Double
	Dim oY1 As Double
	oX1 = (curve.RangeBox.MaxPoint.X + curve.RangeBox.MinPoint.X) / 2
	oY1 = (curve.RangeBox.MaxPoint.Y + curve.RangeBox.MinPoint.Y) / 2
	oP02d=ThisApplication.TransientGeometry.CreatePoint2d(oX1,oY1)
    Dim l1 = sketch.SketchLines.AddByTwoPoints(point, oP02d)
    sketch.GeometricConstraints.AddCoincident(l1.EndSketchPoint, curve)
	Dim oSkd As Inventor.TwoPointDistanceDimConstraint 		
	oSkd=sketch.DimensionConstraints.AddTwoPointDistance(l1.EndSketchPoint, l1.StartSketchPoint, DimensionOrientationEnum.kAlignedDim, oP02d)
	oSkd.Parameter.Expression=Length*10
        sketch.Solve
End Sub

 

a little modify of sub Drawline,don't need create the circle

 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Technology Administrators


Autodesk Design & Make Report