iFeature: How to change affected bodies

iFeature: How to change affected bodies

ChrGBJ
Participant Participant
645 Views
5 Replies
Message 1 of 6

iFeature: How to change affected bodies

ChrGBJ
Participant
Participant

Hello there!

 

I am trying to place an iFeature on a body selected with

 

Dim oFace As Face = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kPartFacePlanarFilter, "Select a planar face")

It is being placed, but for some reason not affecting the body of which i selected oFace

but it seems like it is cutting the first solid in the part hierarchy (There are multiple solids in the .ipt)

 

I have tried to change which SurfaceBodies are being affected with the following

Dim objects = ThisApplication.TransientObjects.CreateObjectCollection
objects.Add(oFace.SurfaceBody)
    
' Create the iFeature.
Dim oiFeature As iFeature
oiFeature = oFeatures.iFeatures.Add(oiFeatureDef) oiFeature.SetAffectedBodies(objects)

This changed nothing, then i tried to update the document

Dim oPartDoc As PartDocument
oPartDoc = ThisApplication.ActiveDocument

oPartDoc.Update()

And as you guessed, nothing...

I really don't know what to try next, and hope one of you could help me out

 

Thanks in advance

 

(Here is the full iLogic Rule, )

Public Sub Main()
  Dim oPartDoc As PartDocument
  oPartDoc = ThisApplication.ActiveDocument
    
  Dim oPartDef As PartComponentDefinition
  oPartDef = oPartDoc.ComponentDefinition
	
  ' Get the selected face to use as input for the iFeature.
  Dim oFace As Face = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kPartFacePlanarFilter, "Select a planar face")
	
  selectPointOne = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kPartEdgeMidpointFilter, "Vælg Midtpunkt 1")
  pointOne = oPartDef.WorkPoints.AddByMidPoint(selectPointOne)

selectPointTwo = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kPartEdgeMidpointFilter, "Vælg Midtpunkt 1")
pointTwo = oPartDef.WorkPoints.AddByMidPoint(selectPointTwo)
Dim oFeatures As PartFeatures
oFeatures = oPartDef.Features
' Create an iFeatureDefinition object.
Dim oiFeatureDef As iFeatureDefinition
oiFeatureDef = oFeatures.iFeatures.CreateiFeatureDefinition( _
"C:\Path\iFeature.ide")
' Set the input.
Dim oInput As iFeatureInput
For Each oInput In oiFeatureDef.iFeatureInputs
Dim oParamInput As iFeatureParameterInput
Select Case oInput.Name
Case "Face"
Dim oPlaneInput As iFeatureSketchPlaneInput
oPlaneInput = oInput
oPlaneInput.PlaneInput = oFace
Case "Point1"
Dim oPlaneInput As iFeatureEntityInput
oPlaneInput = oInput
oPlaneInput.Entity = pointOne Case "Point2"
Dim oPlaneInput As iFeatureEntityInput
oPlaneInput = oInput
oPlaneInput.Entity = pointTwo
End Select
Next

Dim objects = ThisApplication.TransientObjects.CreateObjectCollection
objects.Add(oFace.SurfaceBody)

' Create the iFeature.
Dim oiFeature As iFeature
oiFeature = oFeatures.iFeatures.Add(oiFeatureDef)
oiFeature.SetAffectedBodies(objects)

oPartDoc.Update()
End Sub

Used this as my guide:

  -  https://help.autodesk.com/view/INVNTOR/2020/ENU/?guid=GUID-8E822596-71C5-4C93-B935-7A6F04C7DE10

0 Likes
646 Views
5 Replies
Replies (5)
Message 2 of 6

JelteDeJong
Mentor
Mentor

According to this post, this is a bug in the inventor API confirmed by Autodesk. But I noticed the following. If you hide all bodies except the body that you want to affect then it will work. This can easily be done by code. your code would then look something like this.

Dim oPartDoc As PartDocument
oPartDoc = ThisApplication.ActiveDocument

Dim oPartDef As PartComponentDefinition
oPartDef = oPartDoc.ComponentDefinition

' Get the selected face to use as input for the iFeature.
Dim oFace As Face = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kPartFacePlanarFilter, "Select a planar face")

Dim selectPointOne = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kPartEdgeMidpointFilter, "Vælg Midtpunkt 1")
Dim pointOne = oPartDef.WorkPoints.AddByMidPoint(selectPointOne)

Dim selectPointTwo = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kPartEdgeMidpointFilter, "Vælg Midtpunkt 1")
Dim pointTwo = oPartDef.WorkPoints.AddByMidPoint(selectPointTwo)

Dim oFeatures As PartFeatures = oPartDef.Features

' Create an iFeatureDefinition object.
Dim oiFeatureDef As iFeatureDefinition = oFeatures.iFeatures.CreateiFeatureDefinition("C:\Path\iFeature.ide")

' Set the input.
Dim oInput As iFeatureInput
For Each oInput In oiFeatureDef.iFeatureInputs
    Dim oParamInput As iFeatureParameterInput
    Select Case oInput.Name
        Case "Face"
            Dim oPlaneInput As iFeatureSketchPlaneInput
            oPlaneInput = oInput
            oPlaneInput.PlaneInput = oFace
        Case "Point1"
            Dim oPlaneInput As iFeatureEntityInput
            oPlaneInput = oInput
            oPlaneInput.Entity = pointOne
        Case "Point2"
            Dim oPlaneInput As iFeatureEntityInput
            oPlaneInput = oInput
            oPlaneInput.Entity = pointTwo
    End Select
Next

Dim affectedBody = oFace.SurfaceBody

' Hide all bodies excpect the affectedBody
For Each body As SurfaceBody In oPartDef.SurfaceBodies
    If body Is affectedBody Then
        body.Visible = True
    Else
        body.Visible = False
    End If
Next

Dim affectedBoodies = ThisApplication.TransientObjects.CreateObjectCollection
affectedBoodies.Add(affectedBody)

' Create the iFeature.
Dim oiFeature As iFeature = oFeatures.iFeatures.Add(oiFeatureDef)
oiFeature.SetAffectedBodies(affectedBoodies)

' show all bodies again
For Each body As SurfaceBody In oPartDef.SurfaceBodies
    body.Visible = True
Next


oPartDoc.Update()

Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature


Blog: hjalte.nl - github.com

Message 3 of 6

ChrGBJ
Participant
Participant

I will try that, the next problem is that i would like too select two solids to be affected, and i assume that isn't possible, because of the bug.

0 Likes
Message 4 of 6

JelteDeJong
Mentor
Mentor

I tried to do this with multiple bodies but that did not seem to work.. Maybe you have more luck.

Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature


Blog: hjalte.nl - github.com

Message 5 of 6

ChrGBJ
Participant
Participant

Thank you for your help, and sorry for the late reply. it definitely works better this way, but not as intended.

 

I hope it's okay i won't be accepting your fix as a solution, since i think this is something that should be fixed.

Maybe you know where i could report this?

 

thanks again.

0 Likes
Message 6 of 6

MM5XZCAE
Participant
Participant

What if I want to select two or more surfacebodies for an iFeature? Kindly help

 

0 Likes