Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How to avoid derived base part?

6 REPLIES 6
SOLVED
Reply
Message 1 of 7
saseendrankombath
489 Views, 6 Replies

How to avoid derived base part?

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

 

6 REPLIES 6
Message 2 of 7
mucip
in reply to: saseendrankombath

Hi,

Did you try to use "Suppress Link with Base compenent"???...

 

Regards,

Mucip:)

Message 3 of 7
saseendrankombath
in reply to: mucip

I want to avoid only iterating in to the derived part.

Message 4 of 7
mucip
in reply to: saseendrankombath

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:)

 

Message 5 of 7
saseendrankombath
in reply to: 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.

Message 6 of 7
ekinsb
in reply to: saseendrankombath

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.


Brian Ekins
Inventor and Fusion 360 API Expert
Mod the Machine blog
Message 7 of 7
saseendrankombath
in reply to: ekinsb

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.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report