Sketch Redefine in part interface to another plane parallel to the initial sketch plane

Sketch Redefine in part interface to another plane parallel to the initial sketch plane

sanil_heartbeats
Contributor Contributor
529 Views
5 Replies
Message 1 of 6

Sketch Redefine in part interface to another plane parallel to the initial sketch plane

sanil_heartbeats
Contributor
Contributor

The same question was asked earlier in this post replied by @ekinsb in 2013

 

https://forums.autodesk.com/t5/inventor-customization/sketch-redefine/m-p/4412841#M46141 

 

but at that point of time inventor used to remove all the references when a sketch is redefined from one plane to another even though both planes are parallel to each other. But now in inventor 2021 it is possible without losing the references. 

 

I am trying to redefine the hole feature to use a different sketch instead of the current one. i.e. if the hole was made using SKECTH 5, then I need to change that and make the hole to get the points from another sketch SKECTH 6.

 

Public Sub ChangeHoleSketch()

    Dim partDoc As PartDocument
    Set partDoc = ThisApplication.ActiveDocument
    Dim partComp As PartComponentDefinition
    Set partComp = partDoc.ComponentDefinition
    
    If partDoc.SelectSet.Count > 0 Then
        If (partDoc.SelectSet.Item(1).Type <> kHoleFeatureObject) Then
            MsgBox "Please select Hole feature only."
            Exit Sub
        Else
            Dim hole As HoleFeature
            Set hole = partDoc.SelectSet.Item(1)
    
            MsgBox hole.ExtendedName
            Dim sk As PlanarSketch
            Set sk = hole.Sketch
            MsgBox sk.Name
            
        End If
    Else
        MsgBox "A Hole Feature must be selected first."
        Exit Sub
    End If
        
End Sub

The problem is I don't understand a way to proceed further, I can get the base sketch here. But how do I replace it with another sketch ??

@ekinsb 

0 Likes
530 Views
5 Replies
Replies (5)
Message 2 of 6

FINET_Laurent
Advisor
Advisor

Hi,

 

This may helps : https://forums.autodesk.com/t5/inventor-customization/redefining-sketch-features-with-ilogic/td-p/84...

 

Regards,

 

FINET L.

If this post solved your question, please kindly mark it as "Solution"

If this post helped out in any way to solve your question, please drop a "Like"

@LinkedIn     @JohnCockerill

0 Likes
Message 3 of 6

sanil_heartbeats
Contributor
Contributor

I was expecting a solution with VB.net. I believe iLogic is a totally different workflow. Is there an alternative in VB.net??

0 Likes
Message 4 of 6

WCrihfield
Mentor
Mentor

For one thing, the Sketch property of a HoleFeature is a 'read only' property, so you can't just change it's value to another sketch.  However, the HoleFeature also has a property called PlacementDefinition, which returns a HolePlacementDefinition object.  That is the base class for a set of other derived objects that are specific to the type of placement that was used.  In your case it should check out to be a SketchHolePlacementDefinition type.  And that has a HoleCenterPoints property, that points to an ObjectCollection.  I believe you can either just replace that collection object, or clear it then add the sketch points from your other sketch into it.  Give that a try.

 

If this solved your problem, or answered your question, please click ACCEPT SOLUTION.
Or, if this helped you, please click (LIKE or KUDOS) 👍.

If you want and have time, I would appreciate your Vote(s) for My IDEAS 💡or you can Explore My CONTRIBUTIONS

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 5 of 6

Curtis_Waguespack
Consultant
Consultant

Hi @sanil_heartbeats ,

 

There might be a better way, but the way I've done this is just to get the info from the hole, delete the hole, create the new hole using the old hole info, then rename the new hole to be the same as the old hole.

 

Attached is an example part (Inventor 2019) doing this with iLogic, but the code is pretty much all API.

 

Here is the code as well in case it helps someone find this in a search in the future.

 

I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com

 

 

Dim oDoc As PartDocument
oDoc = ThisApplication.ActiveDocument

Dim oHoles As HoleFeatures
oHoles = oDoc.ComponentDefinition.Features.HoleFeatures

Dim oHole As HoleFeature
oHole = oHoles.Item(1)
oHoleSketch = oHole.Sketch
oName = oHole.Name

oExtentType = oHole.ExtentType
oDepth = oHole.Depth

Dim oDiameter As Double
oDiameter = oHole.HoleDiameter.Value

oHole.Delete(True) 'true retains the sketch
oHoleSketch.Visible = False 'turn off sketch if retained

Dim oSketch As PlanarSketch
oSketch = oDoc.ComponentDefinition.Sketches.Item("Sketch3")

Dim oCollection As ObjectCollection
oCollection = ThisApplication.TransientObjects.CreateObjectCollection

For Each oSketchPoint In oSketch.SketchPoints
	If oSketchPoint.holecenter = True Then
		oCollection.Add(oSketchPoint)
	End If
Next

Dim oPlacementDef As Object
oPlacementDef = oHoles.CreateSketchPlacementDefinition(oCollection)

If oExtentType = PartFeatureExtentEnum.kThroughAllExtent Then
	oHole = oHoles.AddDrilledByThroughAllExtent _
		(oPlacementDef, oDiameter, kPositiveExtentDirection)
Else If oExtentType = PartFeatureExtentEnum.kDistanceExtent Then
	oHole = oHoles.AddDrilledByDistanceExtent _
		(oPlacementDef, oDiameter, oDepth, kPositiveExtentDirection)
End If

oHole.Name = oName
	

 

EESignature

0 Likes
Message 6 of 6

Curtis_Waguespack
Consultant
Consultant

Hi @WCrihfield 

 

I just took a quick look at just swapping out the Placement definition per your suggestion, and it worked, but the hole was still consuming the original sketch even though it uses the points in the new sketch? ... there's probably a way to remedy this, I just didn't look any further.

 

Here's the code, that will work in the file I attached in my previous post, if you want to investigate further.

 

(also, I did a quick test and your method seems to be better for not breaking assembly constraints that use the hole geometry, but it wasn't 100% when the sketch used a different face,  for instance if the hole was redefined to use a sketch on the front face of a cube vs the top face, then an insert constraint fell apart, but a mate to the center line of the hole was ok  )

 

I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com

 

Dim oDoc As PartDocument
oDoc = ThisApplication.ActiveDocument

Dim oHoles As HoleFeatures
oHoles = oDoc.ComponentDefinition.Features.HoleFeatures

Dim oHole As HoleFeature
oHole = oHoles.Item(1)

Dim oSketch As PlanarSketch
oSketch = oDoc.ComponentDefinition.Sketches.Item("Sketch3")

Dim oCollection As ObjectCollection
oCollection = ThisApplication.TransientObjects.CreateObjectCollection

For Each oSketchPoint In oSketch.SketchPoints
	If oSketchPoint.holecenter = True Then
		oCollection.Add(oSketchPoint)
	End If
Next

Dim oPlacementDef As Object
oPlacementDef = oHoles.CreateSketchPlacementDefinition(oCollection)

oHole.PlacementDefinition = oPlacementDef
oSketch.Visible = False
	

 

EESignature

0 Likes