Replace Sketch Entity

Replace Sketch Entity

danijel.radenkovic
Collaborator Collaborator
1,228 Views
2 Replies
Message 1 of 3

Replace Sketch Entity

danijel.radenkovic
Collaborator
Collaborator

Hello to all,

I am not sure that this is the right place for this topic but I would like to hear opinion from someone who had a similar problem.

 

I am looking for the way to easily replace 2D sketch geometry with another 2d sketch geometry without loosing references.

For example, imagine that I have created one arc which is extruded to surface. I believe there is way, somewhere, to replace arc with straight line or another arc but without breaking extruded surface feature. I have to say that sketch geometry is not generated but imported from AutoCAD format, .dwg or .dxf. I have tried using "import" feature to place 2D geometry and it works perfect if you try to modify the current geometry through the AutoCAD and update in Inventor. But, if you try to break the sketch and add/remove something new inside of sketch, it doesn't work and all referenced features are broken-what is if you agree, expected.

 

Please see attached video for better understanding.

Any help, link, advice is very appreciated.

 

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.
0 Likes
1,229 Views
2 Replies
Replies (2)
Message 2 of 3

danijel.radenkovic
Collaborator
Collaborator

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.Update

Do 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.
0 Likes
Message 3 of 3

danijel.radenkovic
Collaborator
Collaborator

Any update? Advice? Idea?

 

Regards

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.
0 Likes