Community
Hello Everyone,
goal: I'm want to constrain fasteners placed in an assembly by picking the proxy faces and then create a feature based pattern of the fasteners if the hole feature in the part is patterned.
I'm not a programmer but I'm learning and was able to place and constrain the fasteners to a part hole based on the a few reference codes I have come across. However, I can't figure out the logic to creating a pattern of the fasteners.
The code needs to:
1. check if the hole feature the fastener is constrained to was patterned or not. If there is no pattern, then exit.
2. If there is a pattern, then create a feature based pattern of the collection created.
oApp = ThisApplication Dim oDoc As Document = oApp.ActiveDocument Dim oCompDef As AssemblyComponentDefinition = oDoc.ComponentDefinition Dim oAllOcc As ComponentOccurrences Dim oOcc As ComponentOccurrence Dim oPart1 As ComponentOccurrence Dim oPart2 As ComponentOccurrence Do Dim oHole1 As Face oHole1 = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kPartFaceCylindricalFilter, "Pick Bolt/Washer Cylindrical Face, Press Esc to cancel") If oHole1 Is Nothing Then Exit Sub oPart1 = oHole1.ContainingOccurrence Dim oFP1 As FaceProxy oPart1.CreateGeometryProxy(oHole1, oFP1) Dim oHole2 As Face oHole2 = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kPartFaceCylindricalFilter, "Pick Part Hole Face, Press Esc to cancel") If oHole2 Is Nothing Then Exit Sub oPart2 = oHole2.ContainingOccurrence Dim oFP2 As FaceProxy oPart2.CreateGeometryProxy(oHole2,oFP2) oCompDef.Constraints.AddMateConstraint(oFP1, oFP2, "0", InferredTypeEnum.kInferredLine, InferredTypeEnum.kInferredLine) oDoc.Update Dim oFace1 As Face = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kPartFacePlanarFilter, "Pick Washer Face. Press Esc to cancel") If oFace1 Is Nothing Then Exit Sub Dim oFace2 As Face = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kPartFacePlanarFilter, "Pick Part face. Press Esc to cancel") If oFace2 Is Nothing Then Exit Sub oCompDef.Constraints.AddMateConstraint(oFace1, oFace2, "0") oDoc.Update 'Creating a collection... Dim oTO As TransientObjects = ThisApplication.TransientObjects Dim oComps As ObjectCollection = oTO.CreateObjectCollection Dim oComp As Object 'Loop for selecting components that need to be added to the collection... While True oComp = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kAssemblyOccurrenceFilter, "Select the Components to pattern.") If oComp Is Nothing Then Exit While oComps.Add(oComp) End While
'FROM THIS SECTION OF THE CODE I'M UNSURE WHETHER MY LOGIC IS CORRECT OR NOT
Dim oPartComp As PartComponentDefinition Dim oPartFeatures As PartFeatures Dim oPF As PartFeature Dim oFeature As PartFeature Dim oProxyFeature As Object Dim oFace As Face = oHole2.GetSourceFace 'The real face of the hole selected in part 2... oFeature = oFace.CreatedByFeature 'The cut/hole feature that consumes Hole2 selected during constraining the fasteners... oPart = oFeature.Parent Dim oFeature1 As PartFeature For Each oOcc In oAllOcc If oOcc = oPart Then For Each oPF In oPartFeatures If oPF.Type = kCircularPatternFeatureObject Then oFeature.Name = oPF.ParentFeatures.Item(1).Name oFeature1 = oPF End If If oPF.Type <> kCircularPatternFeatureObject Then Exit Sub If oPF.Type = kRectangularPatternFeatureObject Then oFeature.Name = oPF.ParentFeatures.Item(1).Name oFeature1 = oPF End If If oPF.Type <> kRectangularPatternFeatureObject Then Exit Sub Next End If Next oFeature = oProxyFeature oCompDef.Occurrences.Item(1).CreateGeometryProxy(oFeature1, oProxyFeature) oCompDef.OccurrencePatterns.AddFeatureBasedPattern(oComps, oProxyFeature) Loop
Can't find what you're looking for? Ask the community or share your knowledge.