Extrude 2d sketch to "Distance From Face" in part.

Extrude 2d sketch to "Distance From Face" in part.

Anonymous
Not applicable
705 Views
4 Replies
Message 1 of 5

Extrude 2d sketch to "Distance From Face" in part.

Anonymous
Not applicable

I have a sketch "MySketch" and work plane "MyWorkPlane".

 

I want to extrude the profile of MySketch with Extents being set to "Distance From Face" from MyWorkPlane.

I would also like to to be able to choose Solid, Join/Cut/Intersect, Distance & Direction.

 

The reason I don't create the extrusion manually, and just toggle suppress/unsuppress, is because I'll need to create an unknown amount of extrusions and they'll use different sketches to extrude.

0 Likes
Accepted solutions (1)
706 Views
4 Replies
Replies (4)
Message 2 of 5

WCrihfield
Mentor
Mentor

Does the sketch already exist before running this code?

Is it already named "MySketch" before running this code?

Does the work plane already exist before running this code?

Is it already named "MyWorkPlane" before running this code?

Or, do you want to create and / or rename any of these items within the code?

I asume the MyWorkPlane is not the plane that the MySketch was created on, right?

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 3 of 5

Anonymous
Not applicable

Both the sketches and work planes exist, and are named correctly, prior to running the code that does the extrusion. 

 

The sketches are created on origin planes, not on the user work planes.

 

The plane (planes) are created programmatically (prior to running the extrusion code). I've already written the code that creates the planes, and it works fine.

0 Likes
Message 4 of 5

WCrihfield
Mentor
Mentor
Accepted solution

Assuming the sketch already exists, and is already named "MySketch"; and assuming the work plane already exists and is already named "MyWorkPlane", you could possibly use something similar to this code.

Dim oDoc As PartDocument = ThisApplication.ActiveDocument
Dim oDef As PartComponentDefinition = oDoc.ComponentDefinition
Dim oSketch As PlanarSketch = oDef.Sketches.Item("MySketch")
Dim oWPlane As WorkPlane = oDef.WorkPlanes.Item("MyWorkPlane")
oSketch.Profiles.AddForSolid

Dim oOps As New ArrayList
oOps.Add(PartFeatureOperationEnum.kCutOperation.ToString)
oOps.Add(PartFeatureOperationEnum.kIntersectOperation.ToString)
oOps.Add(PartFeatureOperationEnum.kJoinOperation.ToString)
oOps.Add(PartFeatureOperationEnum.kNewBodyOperation.ToString)
oOps.Add(PartFeatureOperationEnum.kSurfaceOperation.ToString)

Dim oOp As PartFeatureOperationEnum = InputListBox("Choose operation for this extrusion.", oOps, oOps.Item(4), "CHOOSE OPERATION")
Dim oExtFeats As ExtrudeFeatures = oDef.Features.ExtrudeFeatures
Dim oExtDef As ExtrudeDefinition = oExtFeats.CreateExtrudeDefinition(oSketch.Profiles.Item(1), oOp)

Dim oDirections As New ArrayList
oDirections.Add(PartFeatureExtentDirectionEnum.kNegativeExtentDirection.ToString)
oDirections.Add(PartFeatureExtentDirectionEnum.kPositiveExtentDirection.ToString)
oDirections.Add(PartFeatureExtentDirectionEnum.kSymmetricExtentDirection.ToString)

Dim oDir As PartFeatureExtentDirectionEnum = InputListBox("Choose direction(s) of this extrusion.", oDirections, oDirections.Item(2), "CHOOSE DIRECTION")
Dim o2Directions As Boolean = InputRadioBox("Is this extrusion two directional?","True","False")
Dim oDist1 As Double = InputBox("Enter distance for this extrusion.", "DISTANCE")
Dim oDist2 As Double
If o2Directions = False Then
	oExtDef.SetDistanceFromFaceExtent(oWPlane,False,oDir,oDist1)
ElseIf o2Directions = True Then
	oDist2 = InputBox("Enter second distance for this extrusion.", "DISTANCE 2")
	oExtDef.SetDistanceFromFaceExtent(oWPlane,False,oDir,oDist1,True,oDist2)
End If

Dim oExtFeat As ExtrudeFeature = oExtFeats.Add(oExtDef)
oExtFeat.Name = "MyExtrudeFeature"

I hope this helps.

If this solves your problem, or answers your questions, please select 'Accept As Solution'.

Or if this helps you out along the way to your solution, please click the 👍 Likes button.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 5 of 5

Anonymous
Not applicable

Thanks!

I had issues with the InputListBoxes not working ("can't convert to integer"), but I could easily rewrite the code to do what I wanted it to. Much appreciated!

0 Likes