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

Redefine Extrude Sketch

Is there a possibility via the API to change a specific "Extrusion1" based on "Sketch1" to another different "Sketch2"?

Regards,

Arthur Knoors

Autodesk Affiliations:

Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:Drawing List!|Toggle Drawing Sheet!|Workplane Resize!|Drawing View Locker!|Multi Sheet to Mono Sheet!|Drawing Weld Symbols!|Drawing View Label Align!|Open From Balloon!|Model State Lock!
Posts and Ideas:Dimension Component!|Partlist Export!|Derive I-properties!|Vault Prompts Via API!|Vault Handbook/Manual!|Drawing Toggle Sheets!|Vault Defer Update!


! For administrative reasons, please mark a "Solution as solved" when the issue is solved !

It does seem like I have seen this done before.  It should be possible because the ExtrudeFeature.Definition property is Read/Write, meaning we can set a different ExtrudeDefinition as its value.  Possible steps might be to get a 'Copy' of the existing ExtrudeDefinition to a variable, then use the definition's available 'Set' methods to change it as needed, then set that copy of the definition back as the new value of ExtrudeFeature.Definition property.  May need to do so in silent operation though, not sure.  I have not tried it recently.  ExtrudeDefinition.Profile property is Read/Write also, but I would only do that on the copied version of the definition, then set the definition as new definition, instead of trying to do it directly.

 

Edit:  I may have been wrong about what I remembered being possible.  I did a little local testing within a test part, and I can easily change the extents of an existing extrude feature, and can potentially change between profiles within the same sketch that the extrude feature is already pointing to, when there are multiple profiles within that same sketch.  But getting an existing extrude feature to switch to using a completely different sketch is something I have not been able to do during my initial recent testing.  I know that when using BRep references for changing extent related details, we must move end of part to before feature, then back after feature, but that should not be needed for sketch profile change, so I am not sure why it is not allowing this.  Maybe something we have to ask the folks at Autodesk about.  This has to be something that has been asked about before, because it seems very familiar.  But I lost a lot of my code snippets a while back, which contained not only code examples, but links to important/informational discussions like that.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

@bradeneuropeArthur ,  as @WCrihfield mentioned, as far as I know we can't switch the sketch...

 

but we can delete and recreate the extrusion

 

hope this helps,

Curtis

 

example:

Curtis_Waguespack_0-1726510246701.png

 

 

Dim oPartDoc As PartDocument
oPartDoc = ThisDoc.Document

Dim oCompDef As PartComponentDefinition
oCompDef = oPartDoc.ComponentDefinition

Dim oSketch As PlanarSketch
oSketch = oCompDef.Sketches.Item("Sketch2")

' Create a profile.
Dim oProfile As Profile
oProfile = oSketch.Profiles.AddForSolid

sName = "Extrusion1"

Dim oExtrude As ExtrudeFeature
oExtrude = oCompDef.Features.ExtrudeFeatures.Item(sName)

oExtrude.Delete

Dim oExtrudeDef As ExtrudeDefinition
oExtrudeDef = oCompDef.Features.ExtrudeFeatures.CreateExtrudeDefinition(oProfile, kJoinOperation)
Call oExtrudeDef.SetDistanceExtent(4, kPositiveExtentDirection)
oExtrude = oCompDef.Features.ExtrudeFeatures.Add(oExtrudeDef)

oExtrude.Definition.Profile = oProfile
oExtrude.Name = sName