Finding specific virtual part in BOM

Finding specific virtual part in BOM

Thomas.Long
Advocate Advocate
1,885 Views
7 Replies
Message 1 of 8

Finding specific virtual part in BOM

Thomas.Long
Advocate
Advocate

I have a function that is intended to find a given part and change the item number. I'm using it to renumber the BOM in a very specific order. The order is currently correct, however my assemblies use virtual parts. My current bit of code when checking the BOM can't find virtual parts because they simply show up as the assembly name. I've tried checking BomRow.PartNumber, but apparently partnumber isn't a member of the bomrow which was a tad unexpected.

 

Can anyone modify this to account for virtual parts?

 

Thank you,

Thomas Long

 

 

'Changes item number of part given to specified item number
'\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
Function  BomNumber(PartName As String, Item As Integer)

	Dim oAsm As AssemblyDocument
	Dim oBom As BOM
	Dim oBomRows As BOMRowsEnumerator
	Dim oBomRow As BOMRow
	Dim oBomView As BOMView
	Dim oDef As ComponentDefinition
	Dim PartNumber As String
	
	oAsm = ThisDoc.Document
	oBom = oAsm.ComponentDefinition.BOM
	oBomView = oBom.BOMViews("Structured")
	oBomRows = oBomView.BOMRows
	
	oBom.StructuredViewEnabled = True
	oBom.StructuredViewFirstLevelOnly = False
	
	For Each oBomRow In oBomRows
		oDef = oBomRow.ComponentDefinitions(1)
		PartNumber = oDef.Document.PropertySets("{32853F0F-3444-11D1-9E93-0060B03C1CA6}")("Part Number").Value
		If PartName = PartNumber Then oBomRow.itemNumber = Item
	Next	

End Function
'\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
Accepted solutions (1)
1,886 Views
7 Replies
Replies (7)
Message 2 of 8

MechMachineMan
Advisor
Advisor
Accepted solution

Step 1:

   - Establish what information you need

     - "We need to find out what parts are virtual components because it appears accessing part numbers for them works differently"

 

Step 2:

   - Establish what methods/objects you need to access and in what order to get that information

   - Open the object model and API help. Search for virtual components; try navigating to the parent of each until you get to an object that's familiar, or       try browse a logical parent object to see what provides the proper information.

   - In this case, BOMRow is the first object that will be specific to the item we want to look at. Looking at the methods and properties available for that             object, the only thing that seems that it might be vaguely related is Type.

   - Write some quick code to see what the line returns. In this case, it returns kBOMRowObject. Not specific enough; we need to go deeper.

   - How about the Component Definitions item associated with the row? Again, look through available methods and properties. Type appears again.            Hmm. Try it out. Bingo "kVirtualComponentDefinitionObject"

   - ie; 

 

MsgBox(oBOMRow.ComponentDefinitions(1).Type)


'This returns 100676072.
' As it is a type and the Type property returns a value corresponding to an ObjectTypeEnum, we look it up in the API Help.
' It tells us this corresponds to virtual component definition

 

Step 3:

   - Establish how the unit test works to establish such a thing, and how to implement in your code

   - This essentially works the same as the unit test, but with an if statement.

 

oDef = oBomRow.ComponentDefinitions(1)
If oDef.Type = 100675072 'Virutal Component

  - Lets see what is accessible through the virtual component definition.

  - Looks like a gold mine.

  - Read the API Help, and implement this.

 

Function  BomNumber(PartName As String, Item As Integer)

    Dim oAsm As AssemblyDocument
    Dim oBom As BOM
    Dim oBomRows As BOMRowsEnumerator
    Dim oBomRow As BOMRow
    Dim oBomView As BOMView
    Dim oDef As ComponentDefinition
    Dim PartNumber As String
    
    oAsm = ThisDoc.Document
    oBom = oAsm.ComponentDefinition.BOM
    oBom.StructuredViewEnabled = True
    oBom.StructuredViewFirstLevelOnly = False
    
    oBomView = oBom.BOMViews("Structured")
    oBomRows = oBomView.BOMRows
    
    For Each oBomRow In oBomRows
        oDef = oBomRow.ComponentDefinitions(1)
        
        If oDef.Type = 100675072 'Virutal Component
            PartNumber = oDef.PropertySets("{32853F0F-3444-11D1-9E93-0060B03C1CA6}")("Part Number").Value
        Else
            PartNumber = oDef.Document.PropertySets("{32853F0F-3444-11D1-9E93-0060B03C1CA6}")("Part Number").Value
        End If
        
        If PartName = PartNumber Then oBomRow.itemNumber = Item
    Next    

End Function

 

Step 4:

   - Profit


--------------------------------------
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
Message 3 of 8

Curtis_Waguespack
Consultant
Consultant

@MechMachineMan wrote:

 

Step 4:

   - Profit


I thought "steal underpants" was a prerequisite to "profit"?

EESignature

Message 4 of 8

MechMachineMan
Advisor
Advisor

@Curtis_Waguespack wrote:

I thought "steal underpants" was a prerequisite to "profit"?


 

Smiley LOL


--------------------------------------
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 5 of 8

Thomas.Long
Advocate
Advocate

Thank you,

 

I actually have no idea how to find the API help. I've just been googling things over and over to learn how to do this

0 Likes
Message 6 of 8

MechMachineMan
Advisor
Advisor

See here:

 

http://forums.autodesk.com/t5/inventor-customization/add-selection-filter-to-ilogic-code/m-p/6700118...

 

Also, 

 

it's online now at: 

 

http://help.autodesk.com/view/INVNTOR/2018/ENU/?query=Application&cg=Developer%27s%20Documentation

 

 


--------------------------------------
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 7 of 8

Anonymous
Not applicable

I looking for a function in ilogic that is intended to find a given Title and change according to the Title the necessary item numbering in the BOM. I'm using it to renumber the BOM in my configuration tool.

For example:

BOM

Item          Titel

1                  Rope drum steel struct.

2                  Bushing

3                 etc.

...

 

If Title = Rope drum steel struct. then

oBomRow.itemNumber = 1

If Title = Bushing then

oBomRow.itemNumber = 2

 

and so on

 

The previous solution certainly provides my solution, but I miss the last step to success.

Many thanks

 

0 Likes
Message 8 of 8

MechMachineMan
Advisor
Advisor

@Anonymous

 

As your request does not have very much to do with the topic of this thread, you should create your question with more detail as a new thread.


--------------------------------------
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