Now that I'm looking at it again, and thinking about the situation(s) where you may want to run this same rule again, to update things, that original code could use s few tweaks to help with encountering those already existing fixed WorkPoints, and updating them. I suppose you could simply delete them if found, then create them again, but there is actually a way to update the existing ones, without doing that. Below is an updated version of that code, which will now check for that existing fixed WorkPoint, by the custom and unique name we are assigning it in the code, and if found, it will update its 'definition' using that same proxy point location. If it is not found, then it will proceed to create it, as usual. The process of updating existing work features varies a lot between part and assembly, and by how the feature was originally created. In an assembly, since we can only create 'fixed' work features, their 'definition type' (AssemblyWorkPointDef) is pretty much always the same...for that type of work feature anyways. See if this works better for you in 'repeat/update' type situations, such as after you moved some of those parts around in the assembly.
One thing this still does not do though...if you delete some of those part components out of the assembly, I am not sure that those fixed WorkPoints will also be deleted with them, since there is no 'real' association between the WorkPoint and the component. So, keep an eye out for that situation. If we were creating these in a part, and using 'regular' methods for defining them that were based on 'real' geometry, then they would be deleted (or broken) when the geometry they are associated with was deleted.
Sub Main
Dim oInvApp As Inventor.Application = ThisApplication
Dim oADoc As AssemblyDocument = TryCast(ThisDoc.Document, Inventor.AssemblyDocument)
If oADoc Is Nothing Then Return
Dim oADef As AssemblyComponentDefinition = oADoc.ComponentDefinition
Dim oAsmWPts As WorkPoints = oADef.WorkPoints
Dim oOccs As ComponentOccurrences = oADef.Occurrences
For Each oOcc As ComponentOccurrence In oOccs
If oOcc.Suppressed Then Continue For
If (Not TypeOf oOcc.Definition Is PartComponentDefinition) Then Continue For
Dim oOccPDef As PartComponentDefinition = oOcc.Definition
Dim oOccWPts As WorkPoints = oOccPDef.WorkPoints
For Each oOccWPt As WorkPoint In oOccWPts
If oOccWPt.IsCoordinateSystemElement OrElse
oOccWPt.Construction Then
Continue For
End If
Dim oOccWPtProxy As WorkPointProxy = Nothing
oOcc.CreateGeometryProxy(oOccWPt, oOccWPtProxy)
Dim oAsmWPt_Name As String = oOcc.Name & " - " & oOccWPt.Name
Dim oAsmWPt As WorkPoint = Nothing
Try
oAsmWPt = oAsmWPts.Item(oAsmWPt_Name)
Dim oAsmWPtDef As AssemblyWorkPointDef = oAsmWPt.Definition
oAsmWPtDef.Point = oOccWPtProxy.Point
Catch
oAsmWPt = oAsmWPts.AddFixed(oOccWPtProxy.Point, False)
End Try
If oAsmWPt.Name <> oAsmWPt_Name Then
Try : oAsmWPt.Name = oAsmWPt_Name : Catch : End Try
End If
Next oOccWPt
Next oOcc
oADoc.Update2(True)
End Sub
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

(Not an Autodesk Employee)