Edit Feature via API

Edit Feature via API

Dai_Tech
Enthusiast Enthusiast
578 Views
9 Replies
Message 1 of 10

Edit Feature via API

Dai_Tech
Enthusiast
Enthusiast

Hello everyone,

I want to call Edit Feature of existing finishes via API.

Example: Finishes with name is "Face1". I want to change other face by manual pick.

Dai_Tech_0-1728447125569.png

 

0 Likes
Accepted solutions (2)
579 Views
9 Replies
Replies (9)
Message 2 of 10

Andrii_Humeniuk
Advisor
Advisor

Hi @Dai_Tech . You need to get the FinishFeatures object. Here is an iLogic example:

Dim oDoc As Document = TryCast(ThisDoc.Document, Document)
If oDoc Is Nothing Then Exit Sub
Dim oFinish As FinishFeatures = oDoc.ComponentDefinition.Features.FinishFeatures
If oFinish.Count = 0 Then Exit Sub
Dim oF1 As FinishFeature = TryCast(oFinish("Face1"), FinishFeature)
If oF1 Is Nothing Then Exit Sub
MessageBox.Show("Area - " & oF1.Parameters(3).Value, oF1.Name)

In line 5, we get a FinishFeature named Face1.

Andrii Humeniuk - CAD Coordinator, Autodesk Certified Instructor

LinkedIn | My free Inventor Addin | My Repositories

Did you find this reply helpful ? If so please use the Accept as Solution/Like.

EESignature

0 Likes
Message 3 of 10

Dai_Tech
Enthusiast
Enthusiast

Thanks sir,

I know that. I can call it. But I want to show popup edit feature. How to do that?

 

Dai_Tech_1-1728460645637.png

 

0 Likes
Message 4 of 10

Andrii_Humeniuk
Advisor
Advisor

The Edit Feature UI is a compilation of method sets from the FinishFeature.Definition property. Setting example:

Dim oInvApp As Inventor.Application = ThisApplication
Dim oDoc As Document = TryCast(oInvApp.ActiveDocument, Document)
If oDoc Is Nothing Then Exit Sub
Dim oFinish As FinishFeatures = oDoc.ComponentDefinition.Features.FinishFeatures
If oFinish.Count = 0 Then Exit Sub
Dim oF1 As FinishFeature = TryCast(oFinish("Face1"), FinishFeature)
If oF1 Is Nothing Then Exit Sub
With oF1.Definition
	.InputFaces = oInvApp.TransientObjects.CreateFaceCollection '1
	.FinishType = FinishTypeEnum.kAppearanceFinishType '2
	.Appearance = oDoc.ActiveAppearance '3
	.Comment = "" '4
End With

Andrii_Humeniuk_0-1728461727881.png

 

Andrii Humeniuk - CAD Coordinator, Autodesk Certified Instructor

LinkedIn | My free Inventor Addin | My Repositories

Did you find this reply helpful ? If so please use the Accept as Solution/Like.

EESignature

Message 5 of 10

WCrihfield
Mentor
Mentor

This is just a guess, since I can not test it yet, but I think that if you truly want the manual user interface dialog to show, specifically for editing an existing feature, then you would have to 'select' that feature, one way or another, then execute the same command as the one in the right-click menu.  Below is an example of a code like that, which I have not tested yet.

Sub Main
	Dim oDoc As Inventor.Document = ThisDoc.FactoryDocument
	If oDoc Is Nothing Then Return
	If (Not TypeOf oDoc Is PartDocument) And (Not TypeOf oDoc Is AssemblyDocument) Then Return
	Dim oSS As Inventor.SelectSet = oDoc.SelectSet
	Dim oCD As Inventor.ControlDefinition = ThisApplication.CommandManager.ControlDefinitions.Item("EditFeatureWrapperCmd")
	Dim oFFs As FinishFeatures = oDoc.ComponentDefinition.Features.FinishFeatures
	For Each oFF As FinishFeature In oFFs
		If oFF.Name = "Face1" Then
			oSS.Clear
			oSS.Select(oFF)
			oCD.Execute
		End If
	Next
End Sub

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

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 6 of 10

Dai_Tech
Enthusiast
Enthusiast

That's exactly what I wanted.

But it have a problem with below line.

oCD.Execute "Don't run this line?"

 

0 Likes
Message 7 of 10

WCrihfield
Mentor
Mentor

Hi @Dai_Tech.  I am not sure what you meant in your last reply.  Do you mean that you only wanted to select that feature, but did not really want to show the user interface dialog or editing it?  Did that line of code cause an error message to show?  If it cased an error, then what did the error message say?

 

I am not sure if you are familiar with the technique being used in my code example, so I will attempt to explain it.  A ControlDefinition is the base type of object used by many of the things we see in the user interface of Inventor, like ButtonsComboBoxes, and PopUps.  It defines the 'command' that gets executed when, for example, we click on a button in the ribbon, and also defines which icons are used to represent this command.  When we use the ControlDefinition.Execute method, it is like clicking on that button in the user interface, or clicking on that item in a right-click menu in this case.  There is also the similar ControlDefinition.Execute2 method, which gives us slightly more control over how the timing of the command's execution will work, when there are other things going on at the same time.  But I will not go into the difference between 'Synchronous' and 'Asynchronous' here, because that is a complex subject.  So that line of code you pointed out is executing the specified command on the object that was just selected, similar to what you do manually, but without the right-click step in the middle.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 8 of 10

Dai_Tech
Enthusiast
Enthusiast
Accepted solution

Hi @WCrihfield

Thank you for your explanation. However, as I mentioned earlier, the code is not fully working. The code only selects the feature but doesn't actually execute the Edit feature command. Could you help me rewrite the code so that it properly triggers the Edit action?

I want to select the feature and display the edit dialog with a single click.

Dai_Tech_2-1728799870356.png

 

Here is my code.

Public Module MainModule
    Dim _invApp As Inventor.Application = Marshal.GetActiveObject("Inventor.Application")
    Sub EditFishfeature()
        Dim oDoc As Inventor.Document = _invApp.ActiveDocument
        If oDoc Is Nothing Then Return
        If (Not TypeOf oDoc Is PartDocument) And (Not TypeOf oDoc Is AssemblyDocument) Then Return
        Dim oSS As Inventor.SelectSet = oDoc.SelectSet
        Dim oFFs As FinishFeatures = oDoc.ComponentDefinition.Features.FinishFeatures

        For Each oFF As FinishFeature In oFFs
            If oFF.Name = "Face1" Then
                oSS.Clear()
                oSS.Select(oFF)
                Try
                    _invApp.CommandManager.ControlDefinitions.Item("EditFeatureWrapperCmd").Execute()
                    MsgBox("Edit feature command executed successfully.")
                Catch ex As Exception
                    MsgBox("Failed to execute Edit feature command: " & ex.Message)
                End Try
            End If
        Next
    End Sub
End Module

 

0 Likes
Message 9 of 10

Andrii_Humeniuk
Advisor
Advisor
Accepted solution

Hi @Dai_Tech . You need to use the "PartNGxFinishEditCtxCmd" command. An example of iLogic code:

Public Sub Main()
    Dim oDoc As Inventor.Document = ThisApplication.ActiveDocument
    If oDoc Is Nothing Then Return
    If (Not TypeOf oDoc Is PartDocument) And (Not TypeOf oDoc Is AssemblyDocument) Then Return
    Dim oSS As Inventor.SelectSet = oDoc.SelectSet
    Dim oFFs As FinishFeatures = oDoc.ComponentDefinition.Features.FinishFeatures

    For Each oFF As FinishFeature In oFFs
        If oFF.Name = "Face1" Then
            oSS.Clear()
            oSS.Select(oFF)
            Try
                ThisApplication.CommandManager.ControlDefinitions.Item("PartNGxFinishEditCtxCmd").Execute()
                MsgBox("Edit feature command executed successfully.")
            Catch ex As Exception
                MsgBox("Failed to execute Edit feature command: " & ex.Message)
            End Try
        End If
    Next
End Sub

Andrii Humeniuk - CAD Coordinator, Autodesk Certified Instructor

LinkedIn | My free Inventor Addin | My Repositories

Did you find this reply helpful ? If so please use the Accept as Solution/Like.

EESignature

0 Likes
Message 10 of 10

Dai_Tech
Enthusiast
Enthusiast

Thank sir @Andrii_Humeniuk  @WCrihfield.

It works. 

0 Likes