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 put in parameters to sub-assemblies

1 REPLY 1
Reply
Message 1 of 2
bmerton
1126 Views, 1 Reply

How to put in parameters to sub-assemblies

So here is my problem.  I have an iLogic assembly of around 50 parts.  I want to generate a parts list in the drawing that automatically calculates the Total_Weight, Total_Surface_Area and Total_Quantity of each of these parts based on multiplying the Weight, Surface_Area and Quantity (thisBOMQuantity) of the parts in a single product by a field called Quantity_Required in the top-level assembly.

 

To do this,  I need to add the following parameters to each part:  Weight, Surface_Area, Total_Weight, Total_Surface_Area and Total_Quantity and click 'Export' - I don't know the number of times that I have forgotten this.

 

Then, I am adding a rule in the top level assembly that looks like this:

 

SyntaxEditor Code Snippet

'LHS Plate
If Component.IsActive("LHS Plate:1") = True
Parameter("LHS Plate:1", "Surface_Area")=iProperties.Area("LHS Plate:1")
Parameter("LHS Plate:1", "Material_Colour")=iProperties.Material("LHS Plate:1")
Parameter("LHS Plate:1", "Mass")=iProperties.Mass("LHS Plate:1")
Parameter("LHS Plate:1", "Total_Quantity") = ThisBOM.CalculateQuantity("Model Data", "LHS Plate")*Quantity_Required
Parameter("LHS Plate:1", "Total_Mass")= Parameter("LHS Plate:1", "Total_Quantity")*Parameter("LHS Plate:1", "Mass")
Parameter("LHS Plate:1", "Total_Surface_Area")= Parameter("LHS Plate:1", "Total_Quantity")*Parameter("LHS Plate:1", "Surface_Area")
End If

As you can imagine, this is an EXTREMELY cumbersome process.

 

I am certain that there is a VisualBasic way to do this.  However, I am not very good at VisualBasic.  I understand the CONCEPT of 'looping' but have no idea how to get it to work.  That means that I wouldn't be able to take another code and apply it to my instance.  If someone can help me by walking me through exactly how to:

 

1.  Automatically create the parameters in all the parts.

2.  Automatically create the type of code I have pasted above for each part IF that part is active in the assembly (ie not suppressed). OR Visual Basic code that replicates the function of the above.

 

Is there anyone who can help on this?  Really so much thanks in advance.  We have wasted many many hours, days, weeks on this.  I need a permanent fix!

 

1 REPLY 1
Message 2 of 2
philippe.leefsma
in reply to: bmerton

Hi Bmerton,

 

We can't write 100% of the code for you, if this is what you want, then you would need to hire a consultant or a freelancer who does all the work for you... rather we are here to provide guidance through some code samples and can help to fix some broken code, but you have a better knowledge of your work environment, so a better approach would be that you take the step and learn how to write the code yourself. We have plenty of resources that can help you getting started, the Inventor API Help files are full of VBA samples that you can cut and paste for example.

 

Here is how to create a parameter and set value:

 

Public Sub CreateParameters()
    ' Get the active document.  Assumes a part document is active.
    Dim partDoc As PartDocument
    Set partDoc = ThisApplication.ActiveDocument
    
    ' Get the UserParameters collection
    Dim userParams As UserParameters
    Set userParams = partDoc.ComponentDefinition.Parameters.UserParameters
    
    ' Create a parameter using an expression.  The parameters unit is specified
    ' as millimeters, but the value of the parameter will be 3 inches because
    ' the unit is specified as part of the expression.
    Dim param As Parameter
    Set param = userParams.AddByExpression("NewParam1", "3 in", kMillimeterLengthUnits)
    
    ' Create a parameter using a value.  When setting by value, the value is always
    ' in database units.  In this case it is a length so it will always be in
    ' centimeters.  The units used for the parameter will be the current length units
    ' of the document because it's defined to use the default display length units.
    Set param = userParams.AddByValue("NewParam2", 3 * 2.54, kDefaultDisplayLengthUnits)
End Sub


Public Sub SetParameter()
    ' Get the Parameters object. Assumes a part or assembly document is active.
    Dim oParameters As Parameters
    Set oParameters = ThisApplication.ActiveDocument.ComponentDefinition.Parameters
    
    ' Get the parameter named "Length".
    Dim oLengthParam As Parameter
    Set oLengthParam = oParameters.Item("Length")
    
    ' Change the equation of the parameter.
    oLengthParam.Expression = "3.5 in"
    
    ' Update the document.
    ThisApplication.ActiveDocument.Update
End Sub

 

Take a look at how to iterate through the occurrences of an assembly. It is not clear from your description if you are working with a single level of occurrences or if you can have nested structures (assemblies, sub-assemblies, sub-sub-assemblies and so on...)

 

Here is a VBA example that iterates the assembly direct components and changes the parameters value:

 

Sub UpdateParameters()

    Dim asm As AssemblyDocument
    Set asm = ThisApplication.ActiveDocument
    
    Dim occurrence As ComponentOccurrence
    For Each occurrence In asm.ComponentDefinition.Occurrences
    
        If Not occurrence.Suppressed Then
        
            Dim partCompDef As PartComponentDefinition
            Set partCompDef = occurrence.Definition

            'update component parameter using assembly parameter
            partCompDef.parameters("Total").value = asm.ComponentDefinition.parameters("SomeParam").value * quantity
        
        End If
             
    Next

End Sub

 

Here by simply googling "ilogic iterate components", I could spot the following thread, first hit:

 

http://forums.autodesk.com/t5/inventor-general-discussion/ilogic-assembly-component-occurrence-defin...

 

I hope that helps,

Philippe.

 



Philippe Leefsma
Developer Technical Services
Autodesk Developer Network

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

Post to forums  

Autodesk Design & Make Report