iLogic to access parameters within a base component, referenced to a Part.

iLogic to access parameters within a base component, referenced to a Part.

kevin_hay
Contributor Contributor
2,305 Views
2 Replies
Message 1 of 3

iLogic to access parameters within a base component, referenced to a Part.

kevin_hay
Contributor
Contributor

Hi everyone.

 

I'm currently using iLogic to scan through every occurrence in an assembly using the ComponentOccurrencesEnumerator.

 

I define oLeafDocs = oAsmDef.occurrences.AllLeafOccurrences, then define oOcc as Component Occurrence.

 

This means I can run a for loop to parse each oOcc (Occurrence) to determine what kind of part it is based on some criteria such as name, part number etc and subsequently call a Subroutine or Function to perform processing on that part contextually.

 

Some of the parts detected in the assembly structure contain Base Components as they have been derived. The Base Component doesn't appear to get picked up as part of the scanning of the assembly tree, how could I include detecting a list of Base Components and then access parameters within the base component to force an update?

 

The logic is:

 

Assembly -> Part -> (Found Part, so do some processing)

 

From occurrence of Part -> Detect any references such as Base Components, access Parameters from Base Component in order to utilise them to adjust property information in the derived part.

 

Here is a sample framework code, without any processing to illustrate how things are currently operating:

 

You will see how the occurrences are defined, and then I call a different routine for processing types of part based on their Occurrence Name.

 

Sub Main()
    Dim oAsmDoc As AssemblyDocument 
    oAsmDoc = ThisApplication.ActiveDocument 
    ' Get the assembly component definition. 
    Dim oAsmDef As AssemblyComponentDefinition 
    oAsmDef = oAsmDoc.ComponentDefinition 
    ' Get all of the leaf occurrences of the assembly. 
    
    Dim oLeafOccs As ComponentOccurrencesEnumerator 
    oLeafOccs = oAsmDef.Occurrences.AllLeafOccurrences 
    ' Iterate through the occurrences and print the name. 
    Dim oOcc As ComponentOccurrence
    ' Only Process visible components
            
    For Each oOcc In oLeafOccs
        
        Dim custParamSet As Parameters
        custParamSet=oOcc.Definition.Document.ComponentDefinition.Parameters
        ' Set access to Custom and Default iProperties
        Dim customPropSet As PropertySet        
        ' Set target rule name to use in identifying Line Pipe and Pulled Bend parts
    
        ' If rule exists, this means part is a Pipe or a Pulled Bend
        If Left(oOcc.Name,20)="KHA17-134-C-201-004-" Then
            ProcessPipes(oOcc,custParamSet,customPropSet,SurfaceArea,MassVal,VolVal)
        Else If Left(oOcc.Name,20)="KHA17-134-C-201-003-"
            ProcessPipes(oOcc,custParamSet,customPropSet,SurfaceArea,MassVal,VolVal)
        Else If Left(oOcc.Name,20)="KHA17-134-C-201-002-"
            ProcessPipes(oOcc,custParamSet,customPropSet,SurfaceArea,MassVal,VolVal)
        Else If Left(oOcc.Name,20)="KHA17-134-C-201-001-"
            ProcessPipes(oOcc,custParamSet,customPropSet,SurfaceArea,MassVal,VolVal)
        Else If Left(oOcc.Name,16)="KHA17-134-Z-005-"
            ProcessBends(oOcc,custParamSet,customPropSet,SurfaceArea,MassVal,VolVal)
        Else If Left(oOcc.Name,16)="KHA17-134-Z-002-"
            ProcessTees(oOcc,custParamSet,customPropSet,SurfaceArea,MassVal,VolVal)
        Else
            ProcessMisc(oOcc,custParamSet,customPropSet,SurfaceArea,MassVal,VolVal)
        End If
    Next
    iLogicVb.UpdateWhenDone = True
End Sub

One of the called Functions looks as follows:

 

 

Private Function ProcessBends(oOcc As ComponentOccurrence,custParamSet As Parameters,customPropSet As PropertySet,ByRef SA As Double,ByRef MV As Double,ByRef VV As Double)
    oUserParams=custParamSet.UserParameters
    oModelParams=custParamSet.ModelParameters
    customPropSet = oOcc.Definition.Document.PropertySets.Item("Inventor User Defined Properties")
    stdPropSet = oOcc.Definition.Document.PropertySets.Item("Design Tracking Properties")
    
    Try
    tempstring = stdPropSet.Item("Description").Value
    stdPropSet.Item("Description").Value = Replace(tempstring, "PULLED BEND,","PULLED BEND -")
    stdPropSet.Item("Stock Number").Value = stdPropSet.Item("Description")
    Catch
    'MsgBox("Failure processing Bends")
    End Try
    
    SA = 0
    MV = 0
    VV = 0
End Function

It is within these functions that I would like to access the parameters from a linked Base Component in order to populate the derived components default properties.

 

Thanks,

Kev.

 

0 Likes
Accepted solutions (1)
2,306 Views
2 Replies
Replies (2)
Message 2 of 3

Curtis_Waguespack
Consultant
Consultant
Accepted solution

Hi kevin.hay,

 

I think you'd want to work with referenced files rather than occurrences. Here's a quick example.

 

Warning: run this on a small example file set, as it shows a message box for each referenced file name, which could mean dozens and dozens of clicks if you run this on a large assembly file, as is.

 

Also just as a tip,  programming questions of this type are better suited to search/ask on the Inventor Customization forum :
http://forums.autodesk.com/t5/Autodesk-Inventor-Customization/bd-p/120

 

I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com

 

Dim oAsmDoc As AssemblyDocument 
oAsmDoc = ThisApplication.ActiveDocument 
Dim oDoc As Document         
Dim oRefFile As FileDescriptor
For Each oDoc In oAsmDoc.AllReferencedDocuments  
	MessageBox.Show(oDoc.FullFileName, "iLogic")
	For Each oRefFile In oDoc.file.ReferencedFileDescriptors
		MessageBox.Show("This File: " & vbLf & oDoc.FullFileName _
		& vbLf & vbLf & "Refrences this file: " & vbLf & oRefFile.FullFileName, "iLogic")
	Next
Next

 

EESignature

Message 3 of 3

kevin_hay
Contributor
Contributor

Thanks for the good advice Curtis.

 

I will give this a go as an alternative.

 

Cheers,


Kev.

0 Likes