Making extrusion in an assembly using ilogc

Making extrusion in an assembly using ilogc

RyanRausch
Enthusiast Enthusiast
1,335 Views
6 Replies
Message 1 of 7

Making extrusion in an assembly using ilogc

RyanRausch
Enthusiast
Enthusiast

We have an assembly in which a sketch already exists.  In this assembly I would like to make an ilogic rule to take the existing sketch and extrude (cut) through all, and then remove a component from the extrusion.  I would also like another rule in this assembly to delete the above extrusion w/o deleting the sketch.  Is something like this possiable?

0 Likes
Accepted solutions (2)
1,336 Views
6 Replies
Replies (6)
Message 2 of 7

WCrihfield
Mentor
Mentor

Hi @RyanRausch.  Yes, it sounds possible.  But you would have to be able to find that sketch by code, probably by its name, unless it is the only sketch in the assembly.  You would also have to specify which direction to extrude/cut the  sketch.  And you would also need to somehow specify which component you want to remove from the effects of that extrude cut.  You should also give that extrude feature a specific name, that way you can easily find it by its name in the second rule, to be able to delete it.  And yes, there is a way to delete an extrusion without deleting the sketch it was based on, both manually, and by code.  Do you need help writing those rules, or are you still just in the idea phase?  If you need help writing the rules, you will need to provide all the needed details mentioned above, and/or provide a sample file set.  If you provide files, make sure they do not contain any personal or proprietary data.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 3 of 7

RyanRausch
Enthusiast
Enthusiast

I would like help writing those rules, we would be able to implement them right away.  I was able to attach (3) screenshots.  One of the model tree and assembly before the extrusion, and one of the assembly after the extrusion. Sketch 2 is the that needs to be extruded, and FC-CH1GC will need to be removed from the extrusion.

Let me know if you need more details.

0 Likes
Message 4 of 7

WCrihfield
Mentor
Mentor
Accepted solution

Hi @RyanRausch.  I'm about to leave for the day, and had other stuff going on, but below is a code you can use for the first rule.  I haven't tested it yet though, of course, so proceed with caution.  I noticed that you had two components in your assembly with that same base name, but one had the ":1" after it, and the other had ":2" after it, so I assumed you meant to exclude both of them from the extrude, so I used a loop near the end to get all of them with the same starting part of their name, with the text in it that you specified.

If ThisDoc.Document.DocumentType <> DocumentTypeEnum.kAssemblyDocumentObject Then
	MsgBox("An Assembly Document must be active for this rule to work. Exiting.", vbCritical, "")
	Exit Sub
End If
Dim oADoc As AssemblyDocument = ThisDoc.Document
Dim oADef As AssemblyComponentDefinition = oADoc.ComponentDefinition
Dim oOccs As ComponentOccurrences = oADef.Occurrences
Dim oSketch2 As PlanarSketch = oADef.Sketches.Item("Sketch 2")
Dim oProfile As Inventor.Profile
Try
	oProfile = oSketch2.Profiles.AddForSolid
Catch
	Logger.Error("Error getting extrudable Profile from sketch.")
	Exit Sub
End Try
Dim oExtFeats As ExtrudeFeatures = oADef.Features.ExtrudeFeatures
Dim oExtDef As ExtrudeDefinition = oExtFeats.CreateExtrudeDefinition(oProfile, PartFeatureOperationEnum.kCutOperation)
oExtDef.SetThroughAllExtent(PartFeatureExtentDirectionEnum.kSymmetricExtentDirection)
Dim oExtFeat As ExtrudeFeature = oExtFeats.Add(oExtDef)
For Each oOcc As ComponentOccurrence In oOccs
	If oOcc.Name.StartsWith("FC-CH1CG") Then
		oExtFeat.RemoveParticipant(oOcc)
	End If
Next

If this solved your problem, or answered your question, please click ACCEPT SOLUTION .
Or, if this helped you, please click (LIKE or KUDOS) 👍.

 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 5 of 7

RyanRausch
Enthusiast
Enthusiast

That works great.  If you send the code for the other rule that would be awesome.

Thank you!

0 Likes
Message 6 of 7

WCrihfield
Mentor
Mentor
Accepted solution

Hi @RyanRausch.  Below is an example of an iLogic rule you could potentially used to delete the extrusion that the other rule created.  Since I did not include a line in the last code to give that extrusion feature a specific name, I decided to attempt to find that same extrude feature a different way in the example below.  I am finding it by looping through each possible extrude feature, and checking if the profile that it was it was based on originated from the same named sketch that we used in the first rule.  The line of code starting with "oEF.Delete" is where the action is.  That is where you can specify which aspects of the feature you want to attempt to preserve when deleting it.  The first input True is to retain the consumed sketch.  The second input True is to attempt to retain dependent features and sketches.  (Those are the ones that may have been created after that feature existed, and are based on that feature somehow, so they are dependent on it.  Usually it would not be a good idea to attempt to keep those, and if you do, you may have to fix them.)  Then the third input True is to retain dependent work features.  For example, if that feature created a new face, and you created a WorkPlane that was offset from that face, that WorkPlane would be dependent on that feature.  If you try to maintain those after deleting the feature, you may have to fix them somehow.  You get asked the same questions in a pop-up dialog when manually deleting an Extrude feature, and this is a way to control that by code.

Below is the code:

 

If ThisDoc.Document.DocumentType <> DocumentTypeEnum.kAssemblyDocumentObject Then
	MsgBox("An Assembly Document must be active for this rule to work. Exiting.", vbCritical, "")
	Exit Sub
End If
Dim oADoc As AssemblyDocument = ThisDoc.Document
Dim oADef As AssemblyComponentDefinition = oADoc.ComponentDefinition
Dim oSketch2 As PlanarSketch = oADef.Sketches.Item("Sketch 2")
Dim oExtFeats As ExtrudeFeatures = oADef.Features.ExtrudeFeatures
If oExtFeats.Count = 0 Then Exit Sub
Dim oExtFeat As ExtrudeFeature = Nothing
For Each oEF As ExtrudeFeature In oExtFeats
	If oEF.Definition.Profile.Parent Is oSketch2 Then
		oEF.Delete(True, True, True) 'try to preserve everything else associated with it
	End If
Next

 

If this solved your problem, or answered your question, please click ACCEPT SOLUTION .
Or, if this helped you, please click (LIKE or KUDOS) 👍.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 7 of 7

RyanRausch
Enthusiast
Enthusiast

This works great.  Thank you for your time.

0 Likes