Hi @Anonymous
This page proved quite useful:
http://help.autodesk.com/view/INVNTOR/2019/ENU/?guid=GUID-35F2F555-48A8-438E-952F-7EF60DA1ADAE
And from that I have built this relatively simple "AssemblyCreateExtrusion" rule:
imports System.Linq
Sub Main()
Dim CutFeatureName As String = "DemoAssemblyCutFeature"
If TypeOf ThisApplication.ActiveDocument Is AssemblyDocument Then
Dim AssyDoc As AssemblyDocument = ThisApplication.ActiveDocument
Dim AssyDef As AssemblyComponentDefinition = AssyDoc.ComponentDefinition
If Parameter("TotalWidth") >= 1500 Then
DeleteCutFeature(AssyDef, CutFeatureName)
MessageBox.Show("No cut required")
Else
If Parameter("FinalPanel") = "003" Then
'check if 003 is inserted
For Each occ As ComponentOccurrence In AssyDef.Occurrences
Logger.Debug(occ.Name)
If occ.Name.Contains("004") Then
Component.Replace(occ.Name, "CutMe003.ipt", True)
End If
Next
Else
For Each occ As ComponentOccurrence In AssyDef.Occurrences
Logger.Debug(occ.Name)
If occ.Name.Contains("003") Then
Component.Replace(occ.Name, "CutMe004.ipt", True)
End If
Next
End If
DeleteCutFeature(AssyDef, CutFeatureName)
CreateAssemblyCut(AssyDef, CutFeatureName)
End If
Else
MessageBox.Show("Not using an Assembly, Exiting!")
Exit Sub
End If
iLogicVb.UpdateWhenDone = True
End Sub
Sub DeleteCutFeature(ByVal AssyDef As AssemblyComponentDefinition, FeatureName As String)
Dim FeatureToDelete As ExtrudeFeature = (From extFeat As ExtrudeFeature In AssyDef.features.extrudefeatures
Where extFeat.Name = FeatureName
Select extFeat).FirstOrDefault()
If Not FeatureToDelete Is Nothing Then
FeatureToDelete.Delete(True, False)
Logger.Debug("Deleted: " & FeatureName)
End If
End Sub
Sub CreateAssemblyCut(ByVal AssyDef As AssemblyComponentDefinition, FeatureName As String)
Dim cutSketch As PlanarSketch = (From sk As PlanarSketch In AssyDef.Sketches
Where sk.name.tolower.contains("cut")
Select sk).FirstOrDefault()
If Not cutSketch Is Nothing Then
Dim cutProfile As Profile = cutSketch.Profiles.AddForSolid
Dim extrudeDef As ExtrudeDefinition = AssyDef.Features.ExtrudeFeatures.CreateExtrudeDefinition(cutProfile, PartFeatureOperationEnum.kCutOperation)
Dim cutPlane1 As WorkPlane = (From wp As WorkPlane In AssyDef.WorkPlanes
Where wp.name.contains("1")
Select wp).FirstOrDefault()
Dim cutPlane2 As WorkPlane = (From wp As WorkPlane In AssyDef.WorkPlanes
Where wp.name.contains("2")
Select wp).FirstOrDefault()
If Not cutPlane1 Is Nothing And Not cutPlane2 Is Nothing Then
extrudeDef.SetFromToExtent(cutPlane1, True, cutPlane2, True) ' the true statements here might adversely affect things?
Dim extrudeCut As ExtrudeFeature = AssyDef.Features.ExtrudeFeatures.Add(extrudeDef)
For Each occ As ComponentOccurrence In AssyDef.Occurrences
extrudeCut.AddParticipant(occ)
Next
extrudeCut.Name = FeatureName
Logger.Debug("Created: " & FeatureName)
Else
MessageBox.Show("couldn't find workplanes containing 1 & 2 in their names")
End If
Else
MessageBox.Show("We couldn't find the right sketch! Exiting.")
Exit Sub
End If
End Sub
which works in conjunction with the attached assembly (and part files). I've currently got an iTrigger on Parameter change that calls the above, but this shows the basic steps to create an extrusion in an assembly and "reattach" participants to the newly created extruded-cut-between-workplanes.
I also created a form within the assembly to show it in action. Move the slider & the workplanes will move automatically. For some reason the occurrence replacement needs a click of the AssemblyCreateExtrusion button before it'll do anything, which is odd because it too triggers a parameter change. (Perhaps I'll post this as a separate thread for the Autodesk bods to look at!?)