I have an addin witn OnSaveDocument for assembly which will count the part and add a custom property in to the part document. But my code takes AllReferencedDocuments and that will look into the derived base part also. if I use ReferencedDocuments it will not take the sub assemblies. Need Help to take the parts under sub assemblies and not to take derived base part. below is my code.
Private Sub m_applicationEvents_OnSaveDocument(DocumentObject As _Document, BeforeOrAfter As EventTimingEnum, Context As NameValueMap, ByRef HandlingCode As HandlingCodeEnum) Handles m_applicationEvents.OnSaveDocument If BeforeOrAfter = EventTimingEnum.kBefore Then Try If DocumentObject.SubType = "{E60F81E1-49B3-11D0-93C3-7E0706000000}" Then oAssyDoc = CType(DocumentObject, Inventor.AssemblyDocument) Dim oAssyCompDef As AssemblyComponentDefinition oAssyCompDef = oAssyDoc.ComponentDefinition Dim oCustompropset As PropertySet Dim oDoc As _Document For Each oDoc In oAssyDoc.AllReferencedDocuments If oDoc.SubType = "{4D29B490-49B2-11D0-93C3-7E0706000000}" Then oPartDoc = CType(oDoc, Inventor.PartDocument) partQty = oAssyCompDef.Occurrences.AllReferencedOccurrences(oDoc) oCustompropset = oPartDoc.PropertySets.Item("User Defined Properties") If Not oPartDoc.PropertySets.PropertySetExists("ContentCenter") Then Try If CInt(oCustompropset.Item("Qty").Value) <> partQty.Count Then oCustompropset.Item("Qty").Value = CStr(partQty.Count) End If Catch ex As Exception oCustompropset.Add(CStr(partQty.Count), "Qty") End Try End If End If Next End If Catch ex As Exception MsgBox(ex.Message) End Try End If End Sub
Solved! Go to Solution.
Solved by ekinsb. Go to Solution.
Hi,
Did you try to use "Suppress Link with Base compenent"???...
Regards,
Mucip:)
Hi,
Just open the derived part and right click on base companent on model tree and select "Unsuppress link with base companent"... As a result, you will see that neither your code nor BOM will not iterate in to the derived part...
Regards,
Mucip:)
I know this, But I don't want to do the same. I am looking for a modification on my above code to satisfy my requirement.
My initial solution to this was going to be to write a custom method to get all of the references instead of using AllReferencedDocuments, but when I was playing with the code I think there's a simpler and easier solution. If the count of the collectoin returned by AllReferencedOccurrences is 0 then you can assume it's a derived reference. At least for now, I can't think of another reason that would cause that property to return an empty collection. It's essentially telling you that there aren't any occurrences in the assembly that reference that document, which implies it's being referenced in some other way, which in this case is as a derived part.
Also, I would suggest using the DocumentType property instead of DocumentSubType to check for certain types of documents. It makes the code more readable and your current code will skip sheet metal documents.
Thanks Brian,
As you advised by checking the count and not including the 0 values, my problem is solved. At the same time I changed to DocumentType to include all type of part documents. Once again thanks for our valued advice.