API to edit a feature

API to edit a feature

MattH_Work
Collaborator Collaborator
1,021 Views
2 Replies
Message 1 of 3

API to edit a feature

MattH_Work
Collaborator
Collaborator

If I have a feature name (Fillet2, Extrude2 etc) can I open the 'edit' dialog for that feature via VB

 

Cheers

 

Matt


MattH
Product Design Collection 2026
Vault Pro 2026
0 Likes
1,022 Views
2 Replies
Replies (2)
Message 2 of 3

Ruffy85
Collaborator
Collaborator

Fillet Feature (Complex) API Sample

 

not the edit dialog itself but via code

 

Public Sub CreateFilletComplex()
    ' Create a new Part document.
    Dim oPartDoc As PartDocument
    Set oPartDoc = ThisApplication.Documents.Add(kPartDocumentObject, _
                 ThisApplication.FileManager.GetTemplateFile(kPartDocumentObject))
    
    ' Set a reference to the compdef.
    Dim oCompDef As PartComponentDefinition
    Set oCompDef = oPartDoc.ComponentDefinition
    
    ' Create a sketch on the xy work plane.
    Dim oSketch As PlanarSketch
    Set oSketch = oCompDef.Sketches.Add(oCompDef.WorkPlanes.Item(3))
    
    ' Draw a rectangle.
    Dim oEnts As SketchEntitiesEnumerator
    Set oEnts = oSketch.SketchLines.AddAsTwoPointRectangle( _
                            ThisApplication.TransientGeometry.CreatePoint2d(-6, -4), _
                            ThisApplication.TransientGeometry.CreatePoint2d(6, 4))

    Dim oProfile As Profile
    Set oProfile = oSketch.Profiles.AddForSolid
    
    ' Create an extrusion.
    Dim oExtrudeDef As ExtrudeDefinition
    Set oExtrudeDef = oCompDef.Features.ExtrudeFeatures.CreateExtrudeDefinition(oProfile, kJoinOperation)
    Call oExtrudeDef.SetDistanceExtent(8, kSymmetricExtentDirection)
    Dim oExtrude As ExtrudeFeature
    Set oExtrude = oCompDef.Features.ExtrudeFeatures.Add(oExtrudeDef)

    ' Create an EdgeCollection object to use for inputting the edges for fillets.
    Dim oEdgeCollection As EdgeCollection
    Set oEdgeCollection = ThisApplication.TransientObjects.CreateEdgeCollection
    
    ' Add all of the edges of the start face to the edge collection.
    Dim oEdge As Edge
    For Each oEdge In oExtrude.StartFaces.Item(1).Edges
        oEdgeCollection.Add oEdge
    Next

    ' Obtain a FilletDefinition object to use in defining the various inputs to create the fillet.
    Dim oFilletDef As FilletDefinition
    Set oFilletDef = oCompDef.Features.FilletFeatures.CreateFilletDefinition

    ' Create the first edge set.
    Call oFilletDef.AddConstantRadiusEdgeSet(oEdgeCollection, 1.5)
    
    ' Reinitialize the edge collection.
    Set oEdgeCollection = ThisApplication.TransientObjects.CreateEdgeCollection
    
    ' Add all of the edges of the end face to the edge collection.
    For Each oEdge In oExtrude.EndFaces.Item(1).Edges
        oEdgeCollection.Add oEdge
    Next
    
    ' Create the first edge set.
    Call oFilletDef.AddConstantRadiusEdgeSet(oEdgeCollection, 1)
    
    ' Find the edges that go between the start and end faces by checking to
    ' see if they're parallel to the Z axis.
    Dim oZVector As UnitVector
    Set oZVector = ThisApplication.TransientGeometry.CreateUnitVector(0, 0, 1)
    Dim oSideEdges(1 To 4) As Edge
    Dim EdgeCount As Long
    EdgeCount = 0
    For Each oEdge In oCompDef.SurfaceBodies.Item(1).Edges
        ' In this case we know all the edges are linear.
        Dim oLine As LineSegment
        Set oLine = oEdge.Geometry
        
        If oLine.Direction.IsParallelTo(oZVector) Then
            EdgeCount = EdgeCount + 1
            Set oSideEdges(EdgeCount) = oEdge
        End If
    Next
    
    ' Add the first two edges to a constant radius edge set.
    Set oEdgeCollection = ThisApplication.TransientObjects.CreateEdgeCollection
    oEdgeCollection.Add oSideEdges(1)
    oEdgeCollection.Add oSideEdges(2)
    Call oFilletDef.AddConstantRadiusEdgeSet(oEdgeCollection, 0.5)
    
    ' Create a variable radius edge set for the third edge.
    Set oEdgeCollection = ThisApplication.TransientObjects.CreateEdgeCollection
    oEdgeCollection.Add oSideEdges(3)
    Call oFilletDef.AddVariableRadiusEdgeSet(oEdgeCollection, 1, 2)
    
    ' Create a variable radius edge with a different internal radius for the fourth edge.
    Set oEdgeCollection = ThisApplication.TransientObjects.CreateEdgeCollection
    oEdgeCollection.Add oSideEdges(4)
    Dim oVarRadiusEdgeSet As FilletVariableRadiusEdgeSet
    Set oVarRadiusEdgeSet = oFilletDef.AddVariableRadiusEdgeSet(oEdgeCollection, 0.5, 1.5)
    Call oVarRadiusEdgeSet.AddIntermediateRadius(oSideEdges(4), 3, 0.5)
        
    Dim oFillet As FilletFeature
    Set oFillet = oCompDef.Features.FilletFeatures.Add(oFilletDef, False)
End Sub
If my reply was helpful, please give a "Kudo" or click the "Accept as Solution" button below (or both).
0 Likes
Message 3 of 3

MechMachineMan
Advisor
Advisor

Or you could use the code to get the browser node then:

 

.EnsureVisible

.DoSelect

 

and then run the control definition that is associated with editing features.

 

There is plenty of blogs around that explain the process. Some google-fu will get you there.


--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.

Justin K
Inventor 2018.2.3, Build 227 | Excel 2013+ VBA
ERP/CAD Communication | Custom Scripting
Machine Design | Process Optimization


iLogic/Inventor API: Autodesk Online Help | API Shortcut In Google Chrome | iLogic API Documentation
Vb.Net/VBA Programming: MSDN | Stackoverflow | Excel Object Model
Inventor API/VBA/Vb.Net Learning Resources: Forum Thread

Sample Solutions:Debugging in iLogic ( and Batch PDF Export Sample ) | API HasSaveCopyAs Issues |
BOM Export & Column Reorder | Reorient Skewed Part | Add Internal Profile Dogbones |
Run iLogic From VBA | Batch File Renaming| Continuous Pick/Rename Objects

Local Help: %PUBLIC%\Documents\Autodesk\Inventor 2018\Local Help

Ideas: Dockable/Customizable Property Browser | Section Line API/Thread Feature in Assembly/PartsList API Static Cells | Fourth BOM Type
0 Likes