Changing BOM Structure of an Assembly to Purchased using iLogic

Changing BOM Structure of an Assembly to Purchased using iLogic

EScales
Advocate Advocate
1,174 Views
3 Replies
Message 1 of 4

Changing BOM Structure of an Assembly to Purchased using iLogic

EScales
Advocate
Advocate

I have a rule that triggers every time a new part or assembly is started.  It pops up a form for the user to select Manufactured, Purchased or Stock.  If the user selects Purchased, I want the BOM structure for that part/assembly to change to Purchased.

What I have works great with a part, but when I start a new assembly, I get this error.

MPS Error.PNG

Here is my current rule.

SyntaxEditor Code Snippet

'The Try/Catch looks to see if the parameter M_P_S exists...if not, the Catch imports the .xml file
Try
M = Parameter("M_P_S")
Catch
'Import custom parameter
iLogicVb.Automation.ParametersXmlLoad(ThisDoc.Document, "L:\Autodesk Software\iLogic Rules\NuTec M_P_S Custom Parameter.xml")
End Try

iLogicForm.ShowGlobal("NuTec (M,P,S)", FormMode.Modal)

'This calls the current value of the M_P_S parameter and truncates the value to 1 character
iProperties.Value("Custom", "Mfg, Purchase, Stock") = Left(Parameter("M_P_S"), 1)

'This changes the BOM Structure for this part/assembly to Purchased if M_P_S = P (Purchased)
'Else it changes the BOM Structure to Normal
Dim oDoc As Document = ThisApplication.ActiveDocument

If Parameter("M_P_S") = "P (Purchased)" Then
oDoc.ComponentDefinition.BOMStructure = BOMStructureEnum.kPurchasedBOMStructure
Else
oDoc.ComponentDefinition.BOMStructure = BOMStructureEnum.kNormalBOMStructure
End If

'kDefaultBOMStructure 51969 The default structure type.
'kInseparableBOMStructure 51974 The inseparable structure type.
'kNormalBOMStructure 51970 The normal structure type.
'kPhantomBOMStructure 51971 The phantom structure type.
'kPurchasedBOMStructure 51973 The purchased structure type.
'kReferenceBOMStructure 51972 The reference structure type.
'kVariesBOMStructure 51975 The structure type varies amongst references.

InventorVb.DocumentUpdate()

 

0 Likes
1,175 Views
3 Replies
Replies (3)
Message 2 of 4

MechMachineMan
Advisor
Advisor

Do some debugging and find out which line it fails at...


--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.

Justin K
Inventor 2018.2.3, Build 227 | Excel 2013+ VBA
ERP/CAD Communication | Custom Scripting
Machine Design | Process Optimization


iLogic/Inventor API: Autodesk Online Help | API Shortcut In Google Chrome | iLogic API Documentation
Vb.Net/VBA Programming: MSDN | Stackoverflow | Excel Object Model
Inventor API/VBA/Vb.Net Learning Resources: Forum Thread

Sample Solutions:Debugging in iLogic ( and Batch PDF Export Sample ) | API HasSaveCopyAs Issues |
BOM Export & Column Reorder | Reorient Skewed Part | Add Internal Profile Dogbones |
Run iLogic From VBA | Batch File Renaming| Continuous Pick/Rename Objects

Local Help: %PUBLIC%\Documents\Autodesk\Inventor 2018\Local Help

Ideas: Dockable/Customizable Property Browser | Section Line API/Thread Feature in Assembly/PartsList API Static Cells | Fourth BOM Type
0 Likes
Message 3 of 4

EScales
Advocate
Advocate

It fails at the highlighted line...

FAILED_AT_THIS_LINE.png

0 Likes
Message 4 of 4

MechMachineMan
Advisor
Advisor

Try explicitly declaring the CompDef as AssemblyCompDef instead of the generic object.


--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.

Justin K
Inventor 2018.2.3, Build 227 | Excel 2013+ VBA
ERP/CAD Communication | Custom Scripting
Machine Design | Process Optimization


iLogic/Inventor API: Autodesk Online Help | API Shortcut In Google Chrome | iLogic API Documentation
Vb.Net/VBA Programming: MSDN | Stackoverflow | Excel Object Model
Inventor API/VBA/Vb.Net Learning Resources: Forum Thread

Sample Solutions:Debugging in iLogic ( and Batch PDF Export Sample ) | API HasSaveCopyAs Issues |
BOM Export & Column Reorder | Reorient Skewed Part | Add Internal Profile Dogbones |
Run iLogic From VBA | Batch File Renaming| Continuous Pick/Rename Objects

Local Help: %PUBLIC%\Documents\Autodesk\Inventor 2018\Local Help

Ideas: Dockable/Customizable Property Browser | Section Line API/Thread Feature in Assembly/PartsList API Static Cells | Fourth BOM Type
0 Likes