Wednesday, October 23, 2013

...An iProp For Everyone!

In my last post, I showed one solution to a common task of using assembly level parameters to set iProperties of part files in your assembly using an Array and a For Next Loop.  Using that solution, we specified each component that we wanted to push the iProperties to.

In this post, I'd like to discuss another solution that will push iProperties down to all components in your assembly, even those inside of sub-assemblies.


Sub Main
        Dim oAsmDoc As AssemblyDocument 
        oAsmDoc = ThisApplication.ActiveDocument 

    '    Call the function that does the recursion. 
        Call TraverseAssembly(oAsmDoc.ComponentDefinition.Occurrences, 1)
End Sub 

Private Sub TraverseAssembly(Occurrences As ComponentOccurrences, Level As Integer) 
    '    Iterate through all of the occurrences in this assembly.  Level 1 components. 
    
        Dim oOcc As ComponentOccurrence 
        For Each oOcc In Occurrences 
        
        '    Get the selected item document occurrence name
            Dim oBrowserNode As String
            oBrowserNode = oOcc.Name
    
                Try                                                
                    '    Push the required iProperties down to the occurrences
                        iProperties.Value(oBrowserNode, "Custom", "SO_Number") = Sales_Order_Number
                        iProperties.Value(oBrowserNode, "Custom", "Company") = Customer_Name
                        iProperties.Value(oBrowserNode, "Project", "Project") = Project_Description
        
                Catch
                    '    Do not raise or display an error.
                
                End Try
        
            '    Check to see if this occurrence represents a subassembly 
            '    and recursively call this function to traverse through it. 
                If oOcc.DefinitionDocumentType = kAssemblyDocumentObject Then
                    
                    Call TraverseAssembly(oOcc.SubOccurrences, Level + 1) 
                    
                End If 
        Next 
End Sub

The above code will go iterate through each occurrence in your assembly and set the required iProperties.  If the occurrence is a sub-assembly, it will also iterate through each component inside of that sub-assembly.

Hopefully you see some benefit in the above solution.  Leave me a comment and let me know.

Randy

"The only way to do great work is to love what you do." - Steve Jobs

Wednesday, October 16, 2013

An iProp for you, an iProp for you...

When creating a configurable assembly using iLogic, you’ll often need to push iProperties down to the part files in your assembly.  Quite often these are project specific iProperties such as Project Number, Client Name, Sales Order, etc.

Writing a separate line to push the iProperty down to each component in your assembly is not a very efficient way of going about it.

Another way of accomplishing this is creating an Array whose values include the components in your assembly and a For Next loop.

iPropArray = New String(){"Sideframe_RH", "Sideframe_LH", "End_Guard"}

For Each part In iPropArray
    iProperties.Value(part, "Custom", "SO_Number") = Sales_Order_Number
    iProperties.Value(part, "Custom", "Company") = Customer_Name
    iProperties.Value(part, "Project", "Project") = Project_Description
Next

The Array values are the browser node names of the components in the assembly.

Inside the For Next loop are the actions you want done to each part in the array.  In this case, I’m pushing down iProperties but with a little imagination, you can see how you could expand on this.

Now if I were reading this, I’d say “But Randy, what if I don’t want to list out all the parts.  I want to do the same action to all the parts in my assembly”.  My answer to myself would be “Yes you can do that Randy…but you’ll have to wait until the next post.

Randy

"Nothing can stop the man with the right mental attitude from achieving his goal; nothing on earth can help the man with the wrong mental attitude." - Thomas Jefferson 

Wednesday, October 9, 2013

Pardon the interruption

Hey folks,

I hope everyone has been enjoying Carl's blog posts and getting helpful information out of them.

I just wanted to do a quick post and let everyone know that soon I'll be starting to contribute to this blog.  I work with iLogic on a frequent basis and am looking forward to posting, sharing and hopefully starting some good discussions.

Talk to you soon!

Randy


“Challenges are what make life interesting and overcoming them is what makes life meaningful.” - Joshua J. Marine