ilogic: Split Multiple bodies using surface

ilogic: Split Multiple bodies using surface

Anonymous
Not applicable
1,146 Views
4 Replies
Message 1 of 5

ilogic: Split Multiple bodies using surface

Anonymous
Not applicable

I'm trying.... and failing to write some ilogic for inventor 2018 which will split multiple bodies using a surface. 

the amount of bodies changes as its rectangularly patterned around a sketch (which changes) 

 

what i have at the moment is: 

Dim oApp As Application
Dim oPrt As PartDocument
Dim oPRTCD As PartComponentDefinition
Dim oSB As SurfaceBody
Dim oFT As PartFeatures
Dim oRPF As RectangularPatternFeatures
Dim oFPE As FeaturePatternElement
Dim oSplit As SplitFeature
Dim oREFSKT As Sketch
Dim oCut = CBCT2
Dim oThing As FeaturePatternElements
oApp = ThisApplication
oPrt = oApp.ActiveDocument
oPRTCD = oPrt.ComponentDefinition
oSB = oPRTCD.SurfaceBodies.oThing
oFT = oPRTCD.Features
oRPF = oFT.RectangularPatternFeatures.
CountBody = oPRTCD.SurfaceBodies.Count
oThing = "Feature pattern2"

For Each body In oPRTCD.SurfaceBodies
	On Error Resume Next 
	For Each item In oREFSKT.drivenby
		If item.name = oRPF.name Then 
			oSB = oPRTCD.SurfaceBodies.Item(countbody)
			oSplit = oFT.SplitFeatures.SplitBody(oSB,oRPF)
			countbody = oPRTCD.SurfaceBodies.Count
		End If 
	Next
	
Next 

where CBCT2 is the surface used to cut and rectangular pattern2 is where the bodies are made. 

ive got this far from digging through the forums and google. 

 

any help would be greatly appreacated

0 Likes
1,147 Views
4 Replies
Replies (4)
Message 2 of 5

Ralf_Krieg
Advisor
Advisor

Hello

 

There are parts of code missing? oREFSKT is declared and used, but never assigned a value to it. Is "rectangular pattern2" a rectangular pattern or are sketchdriven pattern?

I started from scratch and wrote it for both pattern types. I assume that "CBCT2" is the name of the Worksurface?

 

Please try out:

Private Sub Main()
	
Dim oPartDoc As PartDocument = ThisDoc.Document

Dim oCompDef As PartComponentDefinition = oPartDoc.ComponentDefinition

Dim oSplitTool As WorkSurface
For Each oSplitTool In oCompDef.WorkSurfaces
    If oSplitTool.SurfaceBodies.Item(1).Name = "CBCT2" Then Exit For
Next

If oSplitTool Is Nothing 
	MsgBox("Surface " & Chr(34) & "CBCT2" & Chr(34) & " not found. Exit", , "iLogic - MultiBodySplit")
	Exit Sub
End If

Dim oSurfaceBodies As SurfaceBodies
oSurfaceBodies = GetSketchPattern(oCompDef)
If oSurfaceBodies Is Nothing Then oSurfaceBodies = GetRectPattern(oCompDef)
		
Dim oBody As SurfaceBody
Dim oSplitFeature As SplitFeature

If oPatternFeature IsNot Nothing Then
	For Each oBody In oCompDef.SurfaceBodies
    	oSplitFeature = oCompDef.Features.SplitFeatures.SplitBody(oSplitTool, oBody)
	Next
Else
	MsgBox("Pattern feature " & Chr(34) & "rectangular pattern 2" & Chr(34) & " not found. Exit", , "iLogic - MultiBodySplit")
	Exit Sub
End If

End Sub


Private Function GetSketchPattern(ByVal oCompDef As PartComponentDefinition) As SurfaceBodies

Dim oPatternFeature As SketchDrivenPatternFeature
For Each oPatternFeature In oCompDef.Features.SketchDrivenPatternFeatures
    If oPatternFeature.Name = "rectangular pattern2" Then
        GetSketchPattern = oPatternFeature.SurfaceBodies
        Exit For
    End If
Next

End Function

Private Function GetRectPattern(ByVal oCompDef As PartComponentDefinition) As SurfaceBodies

Dim oPatternFeature As RectangularPatternFeature
For Each oPatternFeature In oCompDef.Features.RectangularPatternFeatures
    If oPatternFeature.Name = "rectangular pattern2" Then
        GetRectPattern = oPatternFeature.SurfaceBodies
        Exit For
    End If
Next

End Function

 


R. Krieg
RKW Solutions
www.rkw-solutions.com
Message 3 of 5

Anonymous
Not applicable

hey thank you 

 

sorry for slow reply, been off work for a couple of days. 

 

I'm getting the error  "Pattern feature "rectangular Pattern2" not found. exit" 

is there a difference between solid and surface bodies?

 

n.b I cant upload model due to nature of business.

 

0 Likes
Message 4 of 5

Anonymous
Not applicable

ive added a msgbox to see if its counting the bodies, which it is, but still erroring out. 

 

Dim oSurfaceBodies As SurfaceBodies
oSurfaceBodies = GetSketchPattern(oCompDef)
If oSurfaceBodies Is Nothing Then oSurfaceBodies = GetRectPattern(oCompDef)
		MsgBox(oSurfaceBodies.Count)
Dim oBody As SurfaceBody
Dim oSplitFeature As SplitFeature

If oPatternFeature IsNot Nothing Then
	For Each oBody In oCompDef.SurfaceBodies
    	oSplitFeature = oCompDef.Features.SplitFeatures.SplitBody(oSplitTool, oBody)
	Next
Else
	MsgBox("Pattern feature " & Chr(34) & "rectangular pattern 2" & Chr(34) & " not found. Exit", , "iLogic - MultiBodySplit")
	Exit Sub
End If

End Sub
0 Likes
Message 5 of 5

Anonymous
Not applicable
Is "rectangular pattern2" a rectangular pattern or are sketchdriven pattern? rectangular pattern

I started from scratch and wrote it for both pattern types. I assume that "CBCT2" is the name of the Worksurface? its a surface body derived from a surfacesweep
0 Likes