Changing Boolean type

Changing Boolean type

Anonymous
Not applicable
1,698 Views
8 Replies
Message 1 of 9

Changing Boolean type

Anonymous
Not applicable

In Solid modeling features like Extrude, Revolve, the boolean option (PartFeatureOperationEnum) is given explicitly and one can change it from say, 'Join' to 'New Solid' in UI. Can this edition be done via API also? Programmaetcially, can I traverse the whole feature tree and go on chaning the exititng boolean type to say, "New Solid", thereby separating all the feature volumes?

 

Another question: many sheet metal features have implicit boolean (mostly 'Join'). Can same editing be don, meaning chaning the 'Join' to 'New Solid", programmetically?

0 Likes
Accepted solutions (1)
1,699 Views
8 Replies
Replies (8)
Message 2 of 9

Vladimir.Ananyev
Alumni
Alumni

Inventor API uses the concept of Definition object that is used as the input by the appropriate Add method to create a feature object.  As an example, Extrude feature is created using ExtrudeDefinition object.  It has a lot of different methods and properties. E.g., ExtrudeDefinition.Operation property controls the type of operation – kNewBodyOperation, kJoinOperation, kCutOperation, kIntersectOperation, or kSurfaceOperation.


Vladimir Ananyev
Developer Technical Services
Autodesk Developer Network

0 Likes
Message 3 of 9

Anonymous
Not applicable
Wish to know if I can EDIT the boolean type to "New Solid" using APIs. If so, is such facility available to only few (like Extrude) or for all solid features (like Flange, Hole etc)?
0 Likes
Message 4 of 9

Vladimir.Ananyev
Alumni
Alumni

If you can edit the operation type in the UI then it should be possible via API.

For the ExtrudeFeature it could be done in the following way:

Sub ChangeOperationType()

    Dim oDoc As PartDocument
    Set oDoc = ThisApplication.ActiveDocument
    Dim oDef As PartComponentDefinition
    Set oDef = oDoc.ComponentDefinition
    
    Dim oExtrude As ExtrudeFeature
    Set oExtrude = oDef.Features.ExtrudeFeatures.Item(2)
    
    Dim oExtrudeDef As ExtrudeDefinition
    Set oExtrudeDef = oExtrude.Definition
    
    Debug.Print "Initial Operation type: " & oExtrudeDef.Operation
    oExtrudeDef.Operation = PartFeatureOperationEnum.kNewBodyOperation
    Debug.Print "Current Operation type: " & oExtrudeDef.Operation
    Beep
End Sub

part.PNG

 

Output to the Immediate Window:

Initial Operation type: 20481
Current Operation type: 20485

browser1.PNG   =>   browser2.PNG

 

Definition objects may very significantly, so please refer to the Inventor API for detailed descriptions.

 

Best regards,


Vladimir Ananyev
Developer Technical Services
Autodesk Developer Network

0 Likes
Message 5 of 9

Anonymous
Not applicable

Thanks. Changing boolean of Extrude is working fine.

 

I am finding that not all Definition objects are exposing their internal boolean types. Expecially the Sheet Metal features.

Also, isn't there any generic way, say at PartFeature level, where boolean type can be changed to NEW?

0 Likes
Message 6 of 9

Anonymous
Not applicable

Coming back to original problem...

 

Once boolean type is changed, I get separate solids for each extrude. I wish to change their colors differently so as to distcinguish them.

 

Below is the code I wrote but it errors out given the attached part

 

        Public Sub GenerateCells()
            Dim allFeatures As Inventor.PartFeatures = _invApp.ActiveDocument.ComponentDefinition.Features
            Dim extrudefeatures As ObjectCollection = _invApp.TransientObjects.CreateObjectCollection

            Dim ifeat As PartFeature
            For Each ifeat In allFeatures
                If TypeOf ifeat Is ExtrudeFeature Then
                    ExtrudeFeatures.Add(ifeat)
                End If
            Next
            Debug.Print("------------------------------------------------")
            ' GO reverse way, else does not work
            If (extrudefeatures.Count > 0) Then
                For i As Integer = extrudefeatures.Count To 1 Step -1
                    ChangeOperationType(extrudefeatures.Item(i))
                Next
                extrudefeatures.Clear()
            End If

            ' Color all new solids differenty
            For iii As Integer = 1 To m_partDoc.ComponentDefinition.SurfaceBodies.Count
                Dim body As SurfaceBody = m_partDoc.ComponentDefinition.SurfaceBodies.Item(iii)
                Dim colorID As Integer = iii Mod 4
                Try
                    body.Appearance = m_partDoc.AppearanceAssets.Item(colorID)
                Catch ex As Exception
                    ' Some error, gracefully suppressing
                    MsgBox("Error : " & ex.Message)
                End Try

            Next
        End Sub

        Sub ChangeOperationType(ByRef oExtrude As ExtrudeFeature)
            Dim oDef As PartComponentDefinition = m_partDoc.ComponentDefinition
            Dim oExtrudeDef As ExtrudeDefinition = oExtrude.Definition
            Dim oldOperation As PartFeatureOperationEnum = oExtrudeDef.Operation
            Debug.Print("Feature " & oExtrude.Name & " Old Type " & oldOperation)

            Try
                oExtrudeDef.Operation = PartFeatureOperationEnum.kNewBodyOperation
            Catch ex As Exception
                ' Some error, gracefully suppressing
                MsgBox("Error : " & ex.Message)
            End Try
            Dim newOperation As PartFeatureOperationEnum = oExtrudeDef.Operation
            Debug.Print("Current Operation type: " & newOperation)
            Beep()
        End Sub

Applying color interactively works ok, but not using APIs. Anything missing?

0 Likes
Message 7 of 9

Vladimir.Ananyev
Alumni
Alumni

>>>
isn't there any generic way, say at PartFeature level, where boolean type can be changed to NEW?
<<<

No, this functinality is implemented at the definition level because different features have too different definitions.


Vladimir Ananyev
Developer Technical Services
Autodesk Developer Network

0 Likes
Message 8 of 9

Vladimir.Ananyev
Alumni
Alumni
Accepted solution

Your code fails to change appearances because of the insufficient document appearances quantity.  The document contains 3 appearances items (1, 2, 3), but your code tries to get items 4 and 0.

 

I’ve added a pair of appearances and slightly simplified your code.

Here are the results:

results.PNG

 

Output

------------------------------------------------
Feature Extrusion6 Old Type 20482
Current Operation type: 20485
Feature Extrusion4 Old Type 20481
Current Operation type: 20485
Feature Extrusion3 Old Type 20481
Current Operation type: 20485
Feature Extrusion2 Old Type 20482
Current Operation type: 20485
body 1   colorID = 2
body 2   colorID = 3
body 3   colorID = 4
body 4   colorID = 1
body 5   colorID = 2

 

Public Sub GenerateCells()
    Dim oDoc As PartDocument = oApp.ActiveDocument
    Dim oDef As PartComponentDefinition = oDoc.ComponentDefinition
    Dim extrudefeatures As Inventor.ExtrudeFeatures = oDef.Features.ExtrudeFeatures
    
    Debug.Print("------------------------------------------------")
    If (extrudefeatures.Count > 1) Then
        For i As Integer = 2 To extrudefeatures.Count
            Dim oEF As ExtrudeFeature = extrudefeatures.Item(i)
            ChangeOperationType(oEF)
        Next
    End If
    
    ' Color all new solids differenty
    ' this document must have enough document appearences! n = 1..extrudefeatures.Count
    For j As Integer = 1 To oDef.SurfaceBodies.Count
        Dim body As SurfaceBody = oDef.SurfaceBodies.Item(j)
        Dim colorID As Integer = j Mod 4 + 1
        Try
            Debug.Print("body " & j & "   colorID = " & colorID)
            body.Appearance = oDoc.AppearanceAssets.Item(colorID)
        Catch ex As Exception
            ' Some error, gracefully suppressing
            MsgBox("Error : " & ex.Message)
        End Try
    Next
    oDoc.Update()
End Sub


Sub ChangeOperationType(ByRef oExtrude As ExtrudeFeature)
    Dim oExtrudeDef As ExtrudeDefinition = oExtrude.Definition
    Dim oldOperation As PartFeatureOperationEnum = oExtrudeDef.Operation
    Debug.Print("Feature " & oExtrude.Name & " Old Type " & oldOperation)
    Try
        oExtrudeDef.Operation = PartFeatureOperationEnum.kNewBodyOperation
    Catch ex As Exception
        ' Some error, gracefully suppressing
        MsgBox("Error : " & ex.Message)
    End Try
    Dim newOperation As PartFeatureOperationEnum = oExtrudeDef.Operation
    Debug.Print("Current Operation type: " & newOperation)
End Sub

cheers,


Vladimir Ananyev
Developer Technical Services
Autodesk Developer Network

Message 9 of 9

Anonymous
Not applicable

This works really fine. Thanks a lot.

0 Likes