Vb.net create virtual component and set quantity

Vb.net create virtual component and set quantity

Anonymous
Not applicable
1,125 Views
7 Replies
Message 1 of 8

Vb.net create virtual component and set quantity

Anonymous
Not applicable

Hi everyone,

 

I try to create a button to add a virtual component in an assembly and set the quantity.

 

I found some information but nothing that really helps me. And I need some help.

 

Here is what I started :

 

Private Sub VirtualComponents_OnExecute(Context As NameValueMap) Handles VirtualComponents.OnExecute

Dim oApplication As Inventor.Application = GetObject(, "Inventor.Application") Dim oAssDoc As AssemblyDocument oAssDoc = oApplication.ActiveDocument Dim oAssDef As AssemblyComponentDefinition oAssDef = oAssDoc.ComponentDefinition Dim oMatrix As Matrix oMatrix = oApplication.TransientGeometry.CreateMatrix Dim oNewOcc As ComponentOccurrence oNewOcc = oAssDef.Occurrences.AddVirtual("MyVirtual", oMatrix) Dim oCVirtualCompDef As VirtualComponentDefinition oCVirtualCompDef = oNewOcc.Definition Dim oQuantity As Double = InputBox("Quantity") oCVirtualCompDef.BOMQuantity.SetBaseQuantit(BOMQuantityTypeEnum.kEachBOMQuantity, oQuantity) End Sub

 

Thanks

0 Likes
Accepted solutions (1)
1,126 Views
7 Replies
Replies (7)
Message 2 of 8

marcin_otręba
Advisor
Advisor

You must find this virtual component in bom, when you get corresponding row use row.TotalQuantity=oQuantity.

 

 

Hi, maybe you want to check my apps:


DrawingTools   View&ColoringTools   MRUFolders

0 Likes
Message 3 of 8

Anonymous
Not applicable

Yes, but I can not find the line corresponding to my component:

Here is what I have :

 

oAssDef.BOM.BOMViews.Item(1).BOMRows.Item(1).TotalQuantity = oQuantity
0 Likes
Message 4 of 8

marcin_otręba
Advisor
Advisor

most likely it will be last row in your Bom because you just added this component right ?

Give some for each row and  if...then statement first for check if row.componentdefinitions.item is vistualcomponent then some check if name is equal to you component name.

Hi, maybe you want to check my apps:


DrawingTools   View&ColoringTools   MRUFolders

0 Likes
Message 5 of 8

Anonymous
Not applicable
then statement first for check if row.componentdefinitions.item is vistualcomponent then some check if name is equal to you component name.

That's what I do not know how to do !

0 Likes
Message 6 of 8

marcin_otręba
Advisor
Advisor
Accepted solution

This code search using part number, so it must be set first when you add virtcomp: or change to what ever you want

 

Dim bom As Inventor.BOM = ass.ComponentDefinition.BOM
bom.StructuredViewEnabled = True
Dim bomview As Inventor.BOMView = bomm.BOMViews.Item(2)
For Each row As Inventor.BOMRow In bomview.BOMRows
Dim oCompDef As Inventor.ComponentDefinition
oCompDef = row.ComponentDefinitions.Item(1)

Dim oPartNumProperty As Inventor.Property
If TypeOf oCompDef Is Inventor.VirtualComponentDefinition Then
'Get the file property that contains the "Part Number"
'The file property is obtained from the virtual component definition
oPartNumProperty = oCompDef.PropertySets _
.Item("Design Tracking Properties").Item("Part Number")
If oPartNumProperty.Value = m_selectedItem.ItemNum Then
row.TotalQuantity = i
End If
End If
Next

Hi, maybe you want to check my apps:


DrawingTools   View&ColoringTools   MRUFolders

0 Likes
Message 7 of 8

marcin_otręba
Advisor
Advisor

but as i said in your scenario it will be last row because you just added your component. so if you want to change qty right away then use bomview.BOMRows.rows.item(bomview.rows.count)

Hi, maybe you want to check my apps:


DrawingTools   View&ColoringTools   MRUFolders

0 Likes
Message 8 of 8

Anonymous
Not applicable

I succeeded.

 

Thanks !

0 Likes