Bulge feature addin by Brian Ekins. How to do it? (vb.net)

Bulge feature addin by Brian Ekins. How to do it? (vb.net)

mikhail_tsarev
Enthusiast Enthusiast
258 Views
1 Reply
Message 1 of 2

Bulge feature addin by Brian Ekins. How to do it? (vb.net)

mikhail_tsarev
Enthusiast
Enthusiast

Hello)

I've been learning Inventor API for a while now and have made some progress, but sometimes there are tasks where you don't even know where to start.
I watched Brian Ekins' workshop and was very impressed with his "Bulge feature". It's there on 1:19:15:


https://www.autodesk.com/autodesk-university/class/iLogic-and-Inventor-API-2016#video

 

I was very impressed with this demonstration and wanted to make the same feature, like, reverse engineer it.

I understand how to do it in GUI: patch with tangent option and then replace face command. But to do it with code, I can't imagine. I especially liked the interactivity: controlling the tangency coefficient with the mouse.

 

I try write some code (as an external rule for beginning). I managed how to create a patch feature. But there is a problem with the replace face feature: in Inventor 2023 there is no API option to create this operation:

 

 

ReplaceFaceFeatures.CreateDefinition

and 

ReplaceFaceFeatures.Add(oReplaceFaceDef)

 

 

This functionality appeared only in Inventor 2024..... Brian's video is old, so the problem still has a solution, it's just that my approach is probably wrong. And I still have no idea how he was able to control the degree of tangency with the mouse in real time.

 

My code is below. Please help 😃 There is no commercial gain here, just my research interest.

 

 

Dim oDoс As PartDocument = ThisApplication.ActiveDocument
Dim oCompDef As PartComponentDefinition = oDoс.ComponentDefinition

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

' Collect up the edges to create boundary patch.
Dim oEdgeColl As EdgeCollection = ThisApplication.TransientObjects.CreateEdgeCollection
Dim oEdge As Edge

For Each oEdge In oFace.Edges
    oEdgeColl.Add(oEdge)
Next


' Create a boundary patch definition based on edges of the selected face.
Dim oBoundaryPatchDef As BoundaryPatchDefinition = oCompDef.Features.BoundaryPatchFeatures.CreateBoundaryPatchDefinition
oBoundaryPatchDef.BoundaryPatchLoops.Add(oEdgeColl)

'Set the conditions on each edge to be tangent.
For Each oEdge In oEdgeColl
oBoundaryPatchDef.BoundaryPatchLoops.Item(1).SetBoundaryCondition(oEdge, kTangentBoundaryPatchCondition)
oBoundaryPatchDef.BoundaryPatchLoops.Item(1).SetBoundaryTangentWeight(oEdge, 0.9)
Next

' Create the boundary patch feature based on the definition.
Dim oBoundaryPatch As BoundaryPatchFeature = oCompDef.Features.BoundaryPatchFeatures.Add(oBoundaryPatchDef)

' Create existing faces collection obj
Dim oExistFaceColl As FaceCollection = ThisApplication.TransientObjects.CreateFaceCollection
oExistFaceColl.Add(oFace)

' Create new faces collection obj
Dim oNewFaceColl As FaceCollection = ThisApplication.TransientObjects.CreateFaceCollection
oNewFaceColl.Add(oCompDef.Features.BoundaryPatchFeatures.Item(1).Faces.Item(1))

' create replace face feature
Dim oReplaceFaceDef As ReplaceFaceFeature = oCompDef.Features.ReplaceFaceFeatures.CreateDefinition(oExistFaceColl, oNewFaceColl)
Dim oReplaceFace As BoundaryPatchFeature = oCompDef.Features.ReplaceFaceFeatures.Add(oReplaceFaceDef)

 

 

 

 

 

 

 

0 Likes
259 Views
1 Reply
Reply (1)
Message 2 of 2

mikhail_tsarev
Enthusiast
Enthusiast

If anyone is interested, the problem is partially solved. I managed to create a code that works.

At first, today I tried to use Sculptor instead of Replace Face to get the Bulge. It worked well with cylinders, but there was a problem with polygonal contours - the edges had different directions and the patch worked badly. In the end I took an example from the api help - Delete Face, than Patch and Stitch commands. I even managed to pack it all in client feature object.

 

But I still couldn't understand how to enter a weight for tangency through mouse cursor movement and also with realtime preview of the result? Now it is set via user input. Intuitively it seems that there should be something like a a vb.net timer in which ticks mouseevents is processed as a function from the Y coordinate of the cursor with returns value from 0 to 1 and send it to the Patch.

 

Hopefully this iteration will now get at least someone's attention.

 

 

'Mihhail Tsarev

Dim oDoс As PartDocument = ThisApplication.ActiveDocument
Dim oCompDef As PartComponentDefinition = oDoс.ComponentDefinition

' pick a face
Dim oFace As Face = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kPartFacePlanarFilter, "Select planar Face")
' set TangentWeight for a patch feature
Dim oTang As String = InputBox("Enter a decimal value from 0 to 1", "User input").Replace(",", ".")

' Collect up the edges to create boundary patch.
Dim oEdgeColl As EdgeCollection = ThisApplication.TransientObjects.CreateEdgeCollection
For Each oEdge As Edge In oFace.Edges
    oEdgeColl.Add(oEdge)
Next

' Create a Delete Face feature to delete the top face.
Dim oFaceColl As FaceCollection = ThisApplication.TransientObjects.CreateFaceCollection
oFaceColl.Add(oFace)
Dim oDeleteFace As DeleteFaceFeature = oCompDef.Features.DeleteFaceFeatures.Add(oFaceColl)

' Create a boundary patch definition based on edges of the selected face.
Dim oBoundaryPatchDef As BoundaryPatchDefinition = oCompDef.Features.BoundaryPatchFeatures.CreateBoundaryPatchDefinition
oBoundaryPatchDef.BoundaryPatchLoops.Add(oEdgeColl)

'Set the conditions on each edge to be tangent.
For Each oEdge In oEdgeColl
oBoundaryPatchDef.BoundaryPatchLoops.Item(1).SetBoundaryCondition(oEdge, kTangentBoundaryPatchCondition)
oBoundaryPatchDef.BoundaryPatchLoops.Item(1).SetBoundaryTangentWeight(oEdge, oTang)
Next


' Create the boundary patch feature based on the definition.
Dim oBoundaryPatch As BoundaryPatchFeature = oCompDef.Features.BoundaryPatchFeatures.Add(oBoundaryPatchDef)


' Stitch the boundary patch surface to the original body.
Dim oSurfaceToStitch As ObjectCollection = ThisApplication.TransientObjects.CreateObjectCollection

oSurfaceToStitch.Add(oBoundaryPatch.SurfaceBodies.Item(1))
oSurfaceToStitch.Add(oCompDef.SurfaceBodies.Item(1))
oStitch = oCompDef.Features.KnitFeatures.Add(oSurfaceToStitch)


' pack everything above into client feature "Bulge"
Dim BulgeDef As Inventor.ClientFeatureDefinition = oCompDef.Features.ClientFeatures.CreateDefinition("Bulge", oDeleteFace, oStitch)
Dim Bulge As Inventor.ClientFeature = oCompDef.Features.ClientFeatures.Add(BulgeDef, "{C1111111-1111-1111-1111-0123456789A0}")

 

 

test.PNG