Change a part's hole feature in an assembly document

Change a part's hole feature in an assembly document

bhudson4XNR5
Participant Participant
276 Views
2 Replies
Message 1 of 3

Change a part's hole feature in an assembly document

bhudson4XNR5
Participant
Participant

I have a rule that runs in an assembly document that makes changes to part's inside the assembly based on certain parameters.  One of those parts has blind tapped holes, and I want to change those to a thru hole with full tap depth but I'm not sure how to change that feature from a rule at the assembly level.  Any help?

 

I've used the below code to accomplish the same change at the part level, I just need to update it to work when the code runs in the assembly document for a specified part in that assembly. 

oHole1 = ThisDoc.Document.ComponentDefinition.Features.HoleFeatures.Item(“Hole1”)
oHole1.SetThroughAllExtent(kPositiveExtentDirection)
oHole1.TapInfo.FullTapDepth = True

 

0 Likes
Accepted solutions (1)
277 Views
2 Replies
Replies (2)
Message 2 of 3

WCrihfield
Mentor
Mentor
Accepted solution

Hi @bhudson4XNR5.  If you want to run a rule from the top level assembly that will make this change to a part somewhere down within the assembly, then one way or another, we will need to specify either the full file name (path, name, & extension) of the part, or we need to specify which component in the assembly represents that part, so we can climb down through the API object structure to that part.  Is the part represented by a 'top level' component in the main assembly, or is it down within a sub assembly, or is it even deeper than that?  There are several ways to specify which component to target, but I need to know which way would work best for you.  We can prompt the user to manually 'Pick' a component (with the mouse), but that would take away some of the automation.  We could just type the name of the component into the code, as long as that component's name will not change.  If the component is down one or more levels, then we would need to specify which components to go down through to get to that part, starting with the top level sub assembly.

Below is an example of if the part is a top level component named "Part1:1", within the 'active' assembly.

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
'only if it is a 'top level' component.  If not, we would need to do this different.
Dim oOcc As ComponentOccurrence = oOccs.ItemByName("Part1:1")
Dim oPDoc As PartDocument = oOcc.ReferencedDocumentDescriptor.ReferencedDocument
Dim oHoleFeats As HoleFeatures = oPDoc.ComponentDefinition.Features.HoleFeatures
Dim oHole1 As HoleFeature = oHoleFeats.Item("Hole1")
oHole1.SetThroughAllExtent(kPositiveExtentDirection)
oHole1.TapInfo.FullTapDepth = True

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 3 of 3

bhudson4XNR5
Participant
Participant

That's exactly what I needed.  My part is in the top level assembly, so no need to dig into sub-assemblies, and the part name will always be the same so I could just replace the "Part1:1" with the part I needed.  Thanks for the help!

0 Likes