Hello to all,
I have tried with an simpler example. VBA code bellow creates a 4 lines which are constrained in the shape of rectangle (I am not using rectangle function cause this is a simple representation of my problem and I will later use arcs and lines):
Option Explicit
Sub CreateNewSkecth()
' Declare a variable to handle a reference to a document.
Dim invDoc As Inventor.Document
' Set a reference to the active document.
Set invDoc = ThisApplication.ActiveDocument
' Get the component definition.
Dim partDef As Inventor.PartComponentDefinition
Set partDef = invDoc.ComponentDefinition
' Use existing sketch.
Dim xySketch As Inventor.PlanarSketch
Set xySketch = partDef.Sketches.Item("Sketch1")
' Get a reference to the TransientGeometry object.
Dim tg As TransientGeometry
Set tg = ThisApplication.TransientGeometry
' Get a reference to the SketchLines collection.
Dim xyLines As Inventor.SketchLines
Set xyLines = xySketch.SketchLines
' Draw a lines
Dim line1 As Inventor.SketchLine
Set line1 = xyLines.AddByTwoPoints(tg.CreatePoint2d(0, 0), tg.CreatePoint2d(4, 0))
Dim line2 As Inventor.SketchLine
Set line2 = xyLines.AddByTwoPoints(tg.CreatePoint2d(4, 0), tg.CreatePoint2d(4, 4))
Dim line3 As Inventor.SketchLine
Set line3 = xyLines.AddByTwoPoints(tg.CreatePoint2d(4, 4), tg.CreatePoint2d(0, 4))
Dim line4 As Inventor.SketchLine
Set line4 = xyLines.AddByTwoPoints(tg.CreatePoint2d(0, 4), tg.CreatePoint2d(0, 0))
' Make a constraints
line1.EndSketchPoint.Merge line2.StartSketchPoint
line2.EndSketchPoint.Merge line3.StartSketchPoint
line3.EndSketchPoint.Merge line4.StartSketchPoint
line4.EndSketchPoint.Merge line1.StartSketchPoint
End Sub
Second part of the code will delete existing lines and create a 4 new lines and update a model. As it is expected, extrusion is broken because of loosing references:
' Delete existing lines
Dim oEntity As SketchEntity
For Each oEntity In xySketch.SketchLines()
oEntity.Delete
Next
' Draw a new lines
Dim line5 As Inventor.SketchLine
Set line5 = xyLines.AddByTwoPoints(tg.CreatePoint2d(0, 0), tg.CreatePoint2d(4, 0))
Dim line6 As Inventor.SketchLine
Set line6 = xyLines.AddByTwoPoints(tg.CreatePoint2d(4, 0), tg.CreatePoint2d(4, 4))
Dim line7 As Inventor.SketchLine
Set line7 = xyLines.AddByTwoPoints(tg.CreatePoint2d(4, 4), tg.CreatePoint2d(0, 4))
Dim line8 As Inventor.SketchLine
Set line8 = xyLines.AddByTwoPoints(tg.CreatePoint2d(0, 4), tg.CreatePoint2d(0, 0))
' Make a new constraints
line5.EndSketchPoint.Merge line6.StartSketchPoint
line6.EndSketchPoint.Merge line7.StartSketchPoint
line7.EndSketchPoint.Merge line8.StartSketchPoint
line8.EndSketchPoint.Merge line5.StartSketchPoint
'Update a model
ThisApplication.ActiveDocument.UpdateDo you have some suggestion how to recover features bellow sketch? Replacing a sketch entities will be the best solution but as far as I am informed, it is not possible.
If I am wrong, please react.
Here is how it is possible in SolidWorks: https://www.youtube.com/watch?v=X2QxPWkVTMI
Danijel
Inventor 2018/Windows 10 x64
If this information was helpful, please consider marking it as an Accepted Solution by using the Accept as Solution. Kudos are also gladly accepted.