- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I am using Inventor 2019 4.4. I am currently making a template for standard parts. I am trying to create a button that will automatically extrude either a rectangle or a round at the origin so that the origin planes with always be at the center of the extrusion. I have been able to get the extrusion and the sketch to be created, but I run into issues when I want to edit the extrusion to be a different size. So far I have made it so that the extrusion is deleted if it already exists. I am hoping to add the functionality that the extrusion will only be edited so if there are other features on the part. they will not need to be re-made. I was hoping I could drive the extrusion with parameters, but i cannot find a way to put the parameter in as the extrude length, or drive the sketch with parameters (except for the initial creation). Below is the code I have so far. If anyone has any ideas, or any information that might help me out, please let me know. The code below is for the rectangular bar only and i have a separate code for the round, but I may want to put them both in the same function down the road.
Dim oDoc = ThisDoc.Document If TypeOf ThisApplication.ActiveEditObject Is Sketch Then ' Set a reference to the active sketch. Dim OpenSketch As Sketch = ThisApplication.ActiveEditObject OpenSketch.ExitEdit End If Dim oDef As PartComponentDefinition oDef = oDoc.ComponentDefinition ' Get the X-Y work plane. Dim xyPlane As WorkPlane xyPlane = oDef.WorkPlanes.Item("XY Plane") Try ExtrusionExists = ThisApplication.ActiveEditDocument.ComponentDefinition.Features("Bar Extrusion") ExtrusionExists.delete Catch Try SketchExists = ThisApplication.ActiveEditDocument.ComponentDefinition.Sketches("Bar_Sketch") SketchExists.delete Catch End Try End Try 'Try ' ThisApplication.ActiveEditDocument.ComponentDefinition.Sketches("Bar_Sketch").Delete ' Catch 'End Try ' Create a new sketch. Dim sketch As Inventor.PlanarSketch sketch = oDef.Sketches.Add(xyPlane, True) sketch.Name = "Bar_Sketch" ThisApplication.ActiveEditDocument.ComponentDefinition.Sketches("Bar_Sketch").Edit InventorVb.DocumentUpdate() ' Check to make sure a sketch is open. If Not TypeOf ThisApplication.ActiveEditObject Is PlanarSketch Then MessageBox.Show("A sketch must be active.", "iLogic") Return End If 'set a reference to the active sketch. Dim oSketch As PlanarSketch oSketch = ThisApplication.ActiveEditObject 'set a reference to the transient geometry collection. Dim oTransGeom As TransientGeometry oTransGeom = ThisApplication.TransientGeometry ' Create a rectangle 'width = BAR_W 'height = BAR_H 'length = BAR_L Dim oRectangleLines As SketchEntitiesEnumerator oRectangleLines = oSketch.SketchLines.AddAsTwoPointCenteredRectangle( oTransGeom.CreatePoint2d(0, 0),oTransGeom.CreatePoint2d(BAR_W*2.54/2, BAR_H*2.54/2)) ThisApplication.ActiveEditDocument.ComponentDefinition.Sketches("Bar_Sketch").ExitEdit Dim extrudeProfile As Profile = sketch.Profiles.AddForSolid Dim oExtFeature As ExtrudeFeature oExtFeature = oDoc.ComponentDefinition.Features.ExtrudeFeatures.AddByDistanceExtent (extrudeProfile, Parameter("BAR_L")*2.54, kSymmetricExtentDirection, kJoinOperation) oExtFeature.Name = "Bar Extrusion" ThisApplication.ActiveView.Fit iLogicVb.UpdateWhenDone = True
Solved! Go to Solution.