Trim solid with a plane using VBA

Trim solid with a plane using VBA

danijel.radenkovic
Collaborator Collaborator
957 Views
6 Replies
Message 1 of 7

Trim solid with a plane using VBA

danijel.radenkovic
Collaborator
Collaborator

Hello to all,

I am wondering if there is a possibility to split (trim solid) using VBA.

I have found a code for surface splitting but not for solid:

 


Dim spFeature As SplitFeature
Set spFeature = oPrtFeats.SplitFeatures.TrimSolid(oSelectedTool, oSelectedOcc.Definition.SurfaceBodies(1), ),False)


 Regards

Danijel

Inventor 2018/Windows 10 x64
If this information was helpful, please consider marking it as an Accepted Solution by using the Accept as Solution. Kudos are also gladly accepted.
0 Likes
Accepted solutions (1)
958 Views
6 Replies
Replies (6)
Message 2 of 7

Jef_E
Collaborator
Collaborator
Accepted solution

You might be surprised to know that the surfacebodies collection is a collection of solids.

 

You can put this to the test, create a part with multiple solids and run this rule in iLogic and it will show all the names for your solids.

Maybe the name is a bit confusing 😄

 

Dim oInvApp As Application
oInvApp = ThisApplication

Dim oDoc As PartDocument
oDoc = oInvApp.ActiveDocument

Dim oDef As PartComponentDefinition
oDef = oDoc.ComponentDefinition

For Each oSurfaceBody As SurfaceBody In oDef.SurfaceBodies
	MsgBox(oSurfaceBody.Name)
Next

*note that this code will only work for part documents!



Please kudo if this post was helpfull
Please accept as solution if your problem was solved

Inventor 2014 SP2
Message 3 of 7

danijel.radenkovic
Collaborator
Collaborator

Hi Jef,

I am suprised with the name "SurfaceBodies" for collection of Solid Bodies.

I have tried what you suggested and iLogic gave me the names of solids in multibody part, as you said.

 

So in my case, if I want to trim solid with a plane, this should looks like:

 

Dim oPartFeatures As PartFeatures
Set oPartFeatures = oPartDoc.ComponentDefinition.Features

Dim oSplit As SplitFeature
Set oSplit = oPartFeatures.SplitFeatures.TrimSolid(oRefPlane, oPartDef.SurfaceBodies(1), False)

Thank you, Jef!

 

Danijel

 

 

Inventor 2018/Windows 10 x64
If this information was helpful, please consider marking it as an Accepted Solution by using the Accept as Solution. Kudos are also gladly accepted.
0 Likes
Message 4 of 7

danijel.radenkovic
Collaborator
Collaborator

I have one more doubt.

Let's say that I decided to create split part using Plane1. How to edit the same split feature using Plane2?

I am not looking to delete feature and create a new one but to edit split feature.

 

I tried with:

Set oSplit = oPartFeatures.SplitFeatures.TrimSolid(oPlane2, oPartDef.SurfaceBodies(1), True)

But it creates new split feature so I have two of them.

 

Danijel

Inventor 2018/Windows 10 x64
If this information was helpful, please consider marking it as an Accepted Solution by using the Accept as Solution. Kudos are also gladly accepted.
0 Likes
Message 5 of 7

Jef_E
Collaborator
Collaborator

Well thats because you are adding a feature, when you refer to the existing the split you are able to edit it.

 

 

        Dim oInvApp As Application
        oInvApp = ThisApplication

        Dim oDoc As PartDocument
        oDoc = oInvApp.ActiveDocument

        Dim oDef As PartComponentDefinition
        oDef = oDoc.ComponentDefinition

        Dim oSplitFeature As SplitFeature
        oSplitFeature = oDef.Features.SplitFeatures.Item(1)

        oSplitFeature.SetToTrimSolid(oDef.WorkPlanes.Item(2), oDef.SurfaceBodies.Item(1), True)

 

Sorry for the late response, I intended to reply yesterday but apparently I did not hit sent.



Please kudo if this post was helpfull
Please accept as solution if your problem was solved

Inventor 2014 SP2
0 Likes
Message 6 of 7

danijel.radenkovic
Collaborator
Collaborator

There is something wrong with the last line of the code:

 

oSplitFeature.SetToTrimSolid(oDef.WorkPlanes.Item(2), oDef.SurfaceBodies.Item(1), True)

IMG.png

Also, would you like to explain me why sometimes I must to add "Set" to define some feature cause it says as on the image bellow , but sometimes works without adding "set"?

 

img01.png

Regards

Danijel

Inventor 2018/Windows 10 x64
If this information was helpful, please consider marking it as an Accepted Solution by using the Accept as Solution. Kudos are also gladly accepted.
0 Likes
Message 7 of 7

danijel.radenkovic
Collaborator
Collaborator

@danijel.radenkovic wrote:

There is something wrong with the last line of the code:

 

oSplitFeature.SetToTrimSolid(oDef.WorkPlanes.Item(2), oDef.SurfaceBodies.Item(1), True)

IMG.png

Also, would you like to explain me why sometimes I must to add "Set" to define some feature cause it says as on the image bellow , but sometimes works without adding "set"?

 

img01.png

Regards

Danijel


Solved. I forgot to call update of the feature.

Call oSplitFeature.SetToTrimSolid(oDef.WorkPlanes.Item(2), oDef.SurfaceBodies.Item(1), True)

Regards

Danijel

 

 

Inventor 2018/Windows 10 x64
If this information was helpful, please consider marking it as an Accepted Solution by using the Accept as Solution. Kudos are also gladly accepted.
0 Likes