Split solid on pattern element with iLogic

Split solid on pattern element with iLogic

lmc.engineering
Advocate Advocate
1,467 Views
5 Replies
Message 1 of 6

Split solid on pattern element with iLogic

lmc.engineering
Advocate
Advocate

Hi All,

I'm looking to split a solid body using a feature pattern element with iLogic/VBA. Below is what I have so far, however I can't seem to get the correct reference from the pattern element for the split command. The pattern elements are workplanes. Does anybody know how I might do this?

 

SyntaxEditor Code Snippet

Dim oDoc As PartDocument
oDoc = ThisDoc.Document

Dim oDef As ComponentDefinition
oDef = oDoc.ComponentDefinition

oPatternName = "Rectangular Pattern9"
Dim oPattern As RectangularPatternFeature
myFeat = Feature.InventorFeature(oPatternName)
PatternPlane = myFeat.PatternElements.Item(1)

'''Dim myPlane As WorkPlane
'''myPlane = oDef.Workplanes.Item("BaseTrimLH")

Dim SpFeature As SplitFeature
Dim oPFeatures As PartFeatures
oPFeatures = oDef.Features
'''Delete existing features
	For Each SpFeature In oDef.Features.SplitFeatures
           SpFeature.Delete
	Next
''Add new split
SpFeature = oPFeatures.SplitFeatures.SplitBody(PatternPlane,oDef.SurfaceBodies(1))

 Thanks

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

philip1009
Advisor
Advisor
Accepted solution

I think you have to go through another For Each loop through the Pattern Elements as the SplitBody method only takes individual elements, not the whole collection of elements.

 

For Each Element In FeaturePatternElements

     SplitBody(Element, SurfaceBody)

Next

 

Philip Martick
Inventor 2018 Pro, AutoCAD 2018, Autodesk Vault Basic 2018
Windows 10 Pro
2X Intel Xeon E5-2630 v4 @ 2.20GHz
16.00 GB of RAM
NVIDIA Quadro M2000

Message 3 of 6

dgreatice
Collaborator
Collaborator
Accepted solution

Hi,

 

try this:

Public Sub SplitSolid()
    Dim oApp As Application
    Dim oPD As PartDocument
    Dim oPCD As PartComponentDefinition
    Dim oSurBod As SurfaceBody
    Dim oFeats As PartFeatures
    Dim oWPPat As RectangularPatternFeature
    Dim oElPat As FeaturePatternElement
    Dim oSplitFeat As SplitFeature
    Dim oWp As WorkPlane
   
    oApp = ThisApplication
    oPD = oApp.ActiveDocument
    oPCD = oPD.ComponentDefinition
    oSurBod = oPCD.SurfaceBodies.Item(1)
    oFeats = oPCD.Features
    oWPPat = oFeats.RectangularPatternFeatures.Item(1)
    CountBody = oPCD.SurfaceBodies.Count
   
    For Each oWp In oPCD.WorkPlanes
        On Error Resume Next
        For Each Item In oWp.DrivenBy
            If Item.Name = oWPPat.Name Then
                oSurBod = oPCD.SurfaceBodies.Item(CountBody)
                oSplitFeat = oFeats.SplitFeatures.SplitBody(oWp, oSurBod)
                CountBody = oPCD.SurfaceBodies.Count
            End If
        Next
       
    Next
End Sub

 

 

 

Please use the ACCEPT AS SOLUTION or KUDOS button if my Idea helped you to solve the problem.

Autodesk Inventor Professional Certified 2014
Message 4 of 6

dgreatice
Collaborator
Collaborator

 

 

 

Please use the ACCEPT AS SOLUTION or KUDOS button if my Idea helped you to solve the problem.

Autodesk Inventor Professional Certified 2014
Message 5 of 6

lmc.engineering
Advocate
Advocate

@dgreatice @philip1009

 

Thanks very much for your replies, that's done the trick. it's easy to see where I was going wrong now

 

Cheers

0 Likes
Message 6 of 6

DominiqueBernardi5116
Contributor
Contributor

Hi dgreatice,

One last question on this topic, I've try to use your code to split a multi-solid of x solids by looping on x, and increment this way oSurBod = oPCD.SurfaceBodies.Item(x). but it still spliting only the first solid.

Any idea.

regards

 

0 Likes