AffectedBodies in extrusion not working as expected

AffectedBodies in extrusion not working as expected

CAD_CAM_MAN
Advocate Advocate
724 Views
5 Replies
Message 1 of 6

AffectedBodies in extrusion not working as expected

CAD_CAM_MAN
Advocate
Advocate

Inventor 2022 Build 153

I am trying to set up an Extrusion that only affects a single body in a multi solid body part. I am clearing the affectedBodies collection then adding the body I want to use. However no matter which body is being added, the extrude feature always affects the same body. I notice while watching my locals window that the count for the affectedbodies under the extrude definition is always 0 even before I clear the collection. The collection count remains at 0 after the .add line as well...

CAD_CAM_MAN_0-1638312154160.png

 

I noticed in the admapi info for the ExtrudeDefinition.AffectedBodies property it says...

"If this property is not set for multi-body parts, the default solid body is used as the affected body." How do I go about setting the property for multibody?

 

What else should I be looking at?

What am I missing?

 

CAD_CAM_MAN_1-1638312369654.png

 

'Build the extrude definition
                    Dim NEExt As ExtrudeDefinition = PCdef.Features.ExtrudeFeatures.CreateExtrudeDefinition(JT.JointProfile, MyOp)

                    If JT.JointFlipped = True Then 'Check joint direction and set extrusion direction and affected body.
                        MyDir = PartFeatureExtentDirectionEnum.kPositiveExtentDirection
                        MyBod = PCdef.SurfaceBodies(PCdef.SurfaceBodies.Count)
                    Else
                        MyDir = PartFeatureExtentDirectionEnum.kNegativeExtentDirection
                        MyBod = PCdef.SurfaceBodies(PCdef.SurfaceBodies.Count - 1)
                    End If

                    Debug.Print(MyBod.Name)
                    NEExt.SetDistanceExtent(TubeUOM.ConvertUnits(Abs(JT.JointModNonExpEnd), TubeUOMEnum, UnitsTypeEnum.kCentimeterLengthUnits), MyDir)

                    NEExt.AffectedBodies.Clear() 'Clear the bodies collection
                    NEExt.AffectedBodies.Add(MyBod) 'Set the affected body
                    PCdef.Features.ExtrudeFeatures.Add(NEExt) 'Create the feature

 

 

 

 

0 Likes
Accepted solutions (1)
725 Views
5 Replies
Replies (5)
Message 2 of 6

WCrihfield
Mentor
Mentor

Which 'operation' do you have this extrude feature doing (cut, intersect, join, new body, surface)?  I know it shouldn't matter, but are you sure the direction & distance are properly set, so it will come into contact with the target body?  It is a native multi-body part right, not imported, or partially imported, or in the context of an assembly or anything?

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 3 of 6

CAD_CAM_MAN
Advocate
Advocate

This add in I am working on builds all the geometry within context of a single Inventor native part file. All geometry is Inventor native. The operation can be cut or join depending on user input. Distance and direction are correct. 

 

0 Likes
Message 4 of 6

CAD_CAM_MAN
Advocate
Advocate

I was able to get it to work now with hiding all the bodies accept the one I want the extrude to affect. I do not want to mark this as a solution yet because it feels like something is missing with the AffectedBodies property. Seems like a work around.

  'Build the extrude definition
                    Dim NEExt As ExtrudeDefinition = PCdef.Features.ExtrudeFeatures.CreateExtrudeDefinition(JT.JointProfile, MyOp)

                    For Each SB As SurfaceBody In PCdef.SurfaceBodies 'Hide all bodies
                        SB.Visible = False
                    Next

                    If JT.JointFlipped = True Then 'Check joint direction and set extrusion direction and affected body.
                        MyDir = PartFeatureExtentDirectionEnum.kPositiveExtentDirection
                        MyBod = PCdef.SurfaceBodies(PCdef.SurfaceBodies.Count)
                    Else
                        MyDir = PartFeatureExtentDirectionEnum.kNegativeExtentDirection
                        MyBod = PCdef.SurfaceBodies(PCdef.SurfaceBodies.Count - 1)
                    End If

                    MyBod.Visible = True 'Make MyBod visible
                    Debug.Print(MyBod.Name)
                    NEExt.SetDistanceExtent(TubeUOM.ConvertUnits(Abs(JT.JointModNonExpEnd), TubeUOMEnum, UnitsTypeEnum.kCentimeterLengthUnits), MyDir)

                    'NEExt.AffectedBodies.Clear() 'Clear the bodies collection
                    'NEExt.AffectedBodies.Add(MyBod) 'Set the affected body
                    PCdef.Features.ExtrudeFeatures.Add(NEExt) 'Create the feature

 

 

 

 

 

0 Likes
Message 5 of 6

WCrihfield
Mentor
Mentor
Accepted solution

I'm not sure why it is acting that way for you, but another thought would be to change the process so that you create the ExtrudeFeature without setting the AffectedBodies of its definition.  Then use the SetAffectedBodies method of the ExtrudeFeature object after creating it.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 6 of 6

CAD_CAM_MAN
Advocate
Advocate

Thank you WCrihfield! 

I like your suggestion better than hiding everything.

 

This works now...

                    NEExt.SetDistanceExtent(TubeUOM.ConvertUnits(Abs(JT.JointModNonExpEnd), TubeUOMEnum, UnitsTypeEnum.kCentimeterLengthUnits), MyDir)
                    Dim MyExF As ExtrudeFeature = PCdef.Features.ExtrudeFeatures.Add(NEExt) 'Create the feature
                    Dim MyOC As ObjectCollection = IApp.TransientObjects.CreateObjectCollection
                    MyOC.Add(MyBod)
                    MyExF.SetAffectedBodies(MyOC)

 

0 Likes