ilogic to change BOM structure field in document settings - IPT

ilogic to change BOM structure field in document settings - IPT

rzillich
Contributor Contributor
854 Views
3 Replies
Message 1 of 4

ilogic to change BOM structure field in document settings - IPT

rzillich
Contributor
Contributor

Sigh, I feel like this should have been EASY easy, like basic level coding even in a beginner's sense. But here i am, Im trying to get iLogic to change the default bom structure field in the document settings window on an IPT. this is what i have, the 'purchasedComponent' field changes just fine, the BOM structure does nothing at all, no error, no change, nothin'... this is what i have

 

SyntaxEditor Code Snippet

        Try
                If purchasedComponent = True Then
                        iProperties.Value("Custom", "purchasedComponent") = "P"
                        ThisDoc.Document.ComponentDefinition.BOMStructure = BOMStructureEnum.kPurchasedBOMStructure
                    Else If purchasedComponent = False
                        iProperties.Value("Custom", "purchasedComponent") = "M"
                        ThisDoc.Document.ComponentDefinition.BOMStructure = BOMStructureEnum.kNormalBOMStructure
                        
                End If
            Catch
        End Try

 

 

 

0 Likes
Accepted solutions (2)
855 Views
3 Replies
Replies (3)
Message 2 of 4

philip1009
Advisor
Advisor
Accepted solution

You forgot to end the second statement with another Then

 

SyntaxEditor Code Snippet

If purchasedComponent = True Then
	iProperties.Value("Custom", "purchasedComponent") = "P"
	ThisDoc.Document.ComponentDefinition.BOMStructure = BOMStructureEnum.kPurchasedBOMStructure
ElseIf purchasedComponent = False Then
	iProperties.Value("Custom", "purchasedComponent") = "M"
	ThisDoc.Document.ComponentDefinition.BOMStructure = BOMStructureEnum.kNormalBOMStructure
End If

In case you don't know, on the Ribbon, go to Manage > iLogic > Event Triggers, and you can set a trigger to run this rule automatically. 

Message 3 of 4

dusan.naus.trz
Advisor
Advisor

Hi,
This works for me. Thank you

ThisApplication.CommandManager.ControlDefinitions.Item("AppUpdateMassPropertiesCmd").Execute
myMass = iProperties.Mass

If ThisDoc.Document.ComponentDefinition.BOMStructure = BOMStructureEnum.kPurchasedBOMStructure Then
iProperties.Value("Custom", "MyMassiProp") = Round(myMass, 3)
End If

 

0 Likes
Message 4 of 4

philip1009
Advisor
Advisor
Accepted solution

You can shorten that 3 line if statement into 1 with a little shortcut.  Basically if there's only one line of code between your If and End statements, you can move that line to after the Then statement and remove the End statement afterwards.

 

If ThisDoc.Document.ComponentDefinition.BOMStructure = BOMStructureEnum.kPurchasedBOMStructure Then
iProperties.Value("Custom", "MyMassiProp") = Round(myMass, 3)
End If

If ThisDoc.Document.ComponentDefinition.BOMStructure = BOMStructureEnum.kPurchasedBOMStructure Then iProperties.Value("Custom", "MyMassiProp") = Round(myMass, 3)