Get BOMStructure of an assembly, ilogic

Get BOMStructure of an assembly, ilogic

Christian.Stanglmeier
Contributor Contributor
1,029 Views
5 Replies
Message 1 of 6

Get BOMStructure of an assembly, ilogic

Christian.Stanglmeier
Contributor
Contributor

Hi,

 

I try to get the BOMStructure of an assembly with ilogic.

 

With a Part it works fine, but not with an Assembly.

 

Is there a different between Part and Assembly?

 

This Rule runs automaticly bevore save the Dokument.

 

I know where the problem is:

 

If doc.DocumentType = kPartDocumentObject And doc.ComponentDefinition.BOMStructure = 51970 Then

 

But I don't know how to fix it.

 

May someone help?

 

Here is the ilogic code for the Rule.

 

THX

 

 

'kDefaultBOMStructure=51969 'The Default Structure type.
'kNormalBOMStructure=51970 'The normal Structure type.
'kPhantomBOMStructure=51971 'The phantom Structure type.
'kReferenceBOMStructure=51972 'The reference Structure type.
'kPurchasedBOMStructure=51973 ' The purchased Structure type.
'kInseparableBOMStructure=51974 'The inseparable Structure type.
'kVariesBOMStructure=51975 'The Structure type varies amongst references.
'
'kUnknownDocumentObject
'kPartDocumentObject
'kAssemblyDocumentObject
'kDrawingDocumentObject
'kPresentationDocumentObject
'kDesignElementDocumentObject
'kForeignModelDocumentObject
'kSATFileDocumentObject
'kNoDocument

doc = ThisDoc.Document
InventorVb.DocumentUpdate()

'Part and normal
If doc.DocumentType = kPartDocumentObject And doc.ComponentDefinition.BOMStructure = 51970 Then
iProperties.Value("custom", "10_Werkst./DIN") = doc.PropertySets.Item("Design Tracking Properties").Item("Material").Value
iProperties.Value("custom", "11_Abmessung") = Round(Measure.ExtentsLength,0) & "x" & Round(Measure.ExtentsWidth,0) & "x" & Round(Measure.ExtentsHeight,0)
iProperties.Value("Custom", "Masse")=(Round(iProperties.Mass,2)) &" kg"
End If

'Assembly and inseparable
If doc.DocumentType = kAssemblyDocumentObject And doc.ComponentDefinition.BOMStructure = 51974 Then
iProperties.Value("custom", "10_Werkst./DIN") = doc.PropertySets.Item("Design Tracking Properties").Item("Weld Material").Value
iProperties.Value("custom", "11_Abmessung") = Round(Measure.ExtentsLength,0) & "x" & Round(Measure.ExtentsWidth,0) & "x" & Round(Measure.ExtentsHeight,0)
iProperties.Value("Custom", "Masse")=(Round(iProperties.Mass,2)) &" kg"
End If

If Mid(ThisDoc.FileName(False), 14, 1) = "-" Then
iProperties.Value("custom", "05_Benennung") = Mid(ThisDoc.FileName(False), 22, Len(ThisDoc.FileName(False))-21)
iProperties.Value("custom", "08_Erstzulieferer-Nr.") = Left(ThisDoc.FileName(False), 16)
Else
MessageBox.Show("Dateiname falsch", "Hinweis", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
End If

 

0 Likes
Accepted solutions (2)
1,030 Views
5 Replies
Replies (5)
Message 2 of 6

Christian.Stanglmeier
Contributor
Contributor

Hi,

 

try this pls.

 

doc = ThisDoc.Document
InventorVb.DocumentUpdate()

'Schweißbaugruppe
If (doc.DocumentType = DocumentTypeEnum.kAssemblyDocumentObject And doc.ComponentDefinition.BOMStructure = Inventor.BOMStructureEnum.kInseparableBOMStructure) Then
  MessageBox.Show("Schweißbaugruppe", "Info")
End If

0 Likes
Message 3 of 6

Anonymous
Not applicable
Accepted solution

The component definition of an assembly document needs to be defined differently than a part document.

 

Try this instead:

 

 

    If doc.DocumentType = DocumentTypeEnum.kAssemblyDocumentObject Then
        Dim oAssmDoc As AssemblyDocument = doc
        oDef = oAssmDoc.ComponentDefinition
    ElseIf doc.DocumentType = DocumentTypeEnum.kPartDocumentObject Then
        Dim oPartDoc As PartDocument = doc
        oDef = oPartDoc.ComponentDefinition
    End If
    
    If doc.DocumentType = kPartDocumentObject And oDef.BOMStructure = 51970 Then 

 

0 Likes
Message 4 of 6

Christian.Stanglmeier
Contributor
Contributor

Hi,

 

thx.

 

What to do with a part, can you give also an example for a part?

 

Or can this be used now for part and assembly?

0 Likes
Message 5 of 6

Anonymous
Not applicable
Accepted solution

This will work for both assembly and part

Message 6 of 6

Christian.Stanglmeier
Contributor
Contributor

Hi,

 

here my rules, works all fine, mybe it will help someone. 🙂

 

'Regel0-IAM
Sub Main()
'MessageBox.Show("Start Rule", "<DEBUG>")
doc = ThisDoc.Document

'For Assembly only, works not for Parts
Dim oAssmDoc As AssemblyDocument = doc
oDef = oAssmDoc.ComponentDefinition

InventorVb.DocumentUpdate()

'Baugruppe (Normal)
If doc.DocumentType = kAssemblyDocumentObject And oDef.BOMStructure = 51970 Then
  'MessageBox.Show("Assembly-Normal", "<DEBUG>") 
  iProperties.Value( "Project", "Part number") = ThisDoc.FileName
  oCustomPropertySet = ThisDoc.Document.PropertySets.Item("Inventor User Defined Properties")
  For Each oCustProp In oCustomPropertySet
    oCustProp.Value = ""
  Next
End If

'Schweissbaugruppe (Inseparable)
If doc.DocumentType = kAssemblyDocumentObject And oDef.BOMStructure = 51974 Then
  'MessageBox.Show("Assembly-Inseparable", "<DEBUG>") 
  iProperties.Value( "Project", "Part number") = ThisDoc.FileName
  'Set Custom iProperties
  iProperties.Value("custom", "10_Werkst./DIN") = doc.PropertySets.Item("Design Tracking Properties").Item("Weld Material").Value
  iProperties.Value("custom", "11_Abmessung") = Round(Measure.ExtentsLength,0) & "x" & Round(Measure.ExtentsWidth,0) & "x" & Round(Measure.ExtentsHeight,0)
  iProperties.Value("Custom", "Masse") = (Round(iProperties.Mass,2)) &" kg"
  SaveFile()
End If
End Sub

Sub SaveFile()
  'Pruefen auf standardisierten Dateinamen
  'P12345_01_001-00_ET__Platte
  'MessageBox.Show("Checking Filename", "<DEBUG>")
  If (Mid(ThisDoc.FileName(False), 14, 1) = "-" And Mid(ThisDoc.FileName(False), 17, 1) = "_" And Mid(ThisDoc.FileName(False), 21, 1) = "_" )Then
    iProperties.Value("custom", "05_Benennung") = Mid(ThisDoc.FileName(False), 22, Len(ThisDoc.FileName(False))-21) 
    iProperties.Value("custom", "08_Erstzulieferer-Nr.") = Left(ThisDoc.FileName(False), 16)
  Else  
    MessageBox.Show(ThisDoc.FileName(True), "Dateiname nicht nach Standard!", MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1)
	'Return
  End If
  'STP-Konverter
  'MessageBox.Show("Saving STP-File", "<DEBUG>")
  If (ThisDoc.PathAndFileName(False) <> "") Then
    ThisDoc.Document.SaveAs(ThisDoc.PathAndFileName(False) & ".stp", True)
  End If
End Sub
'Regel0-IPT
Sub Main()
'MessageBox.Show("Start Rule", "<DEBUG>")
doc = ThisDoc.Document

'For Parts only, works not for Assembly
Dim oPartDoc As PartDocument = doc
oDef = oPartDoc.ComponentDefinition

InventorVb.DocumentUpdate()

'Bauteil(Normal)
If doc.DocumentType = kPartDocumentObject And oDef.BOMStructure = 51970 Then
  'MessageBox.Show("Part-Normal", "<DEBUG>")
  Update_Save(1)
End If

'Bauteil(Unteilbar)
If doc.DocumentType = kPartDocumentObject And oDef.BOMStructure = 51974 Then
  'MessageBox.Show("Part-Inseparable", "<DEBUG>")
  Update_Save(0)
End If
End Sub

Sub Update_Save(STP As Byte)
  iProperties.Value( "Project", "Part number") = ThisDoc.FileName
  'Set Custom iProperties
  iProperties.Value("custom", "10_Werkst./DIN") = iProperties.Material
  iProperties.Value("custom", "11_Abmessung") = Round(Measure.ExtentsLength,0) & "x" & Round(Measure.ExtentsWidth,0) & "x" & Round(Measure.ExtentsHeight,0)
  iProperties.Value("Custom", "Masse") = (Round(iProperties.Mass,2)) &" kg"
  'Pruefen auf standardisierten Dateinamen
  'P12345_01_001-00_ET__Platte
  'MessageBox.Show("Checking Filename", "<DEBUG>")
  If (Mid(ThisDoc.FileName(False), 14, 1) = "-" And Mid(ThisDoc.FileName(False), 17, 1) = "_" And Mid(ThisDoc.FileName(False), 21, 1) = "_" )Then
    iProperties.Value("custom", "05_Benennung") = Mid(ThisDoc.FileName(False), 22, Len(ThisDoc.FileName(False))-21) 
    iProperties.Value("custom", "08_Erstzulieferer-Nr.") = Left(ThisDoc.FileName(False), 16)
  Else  
    MessageBox.Show(ThisDoc.FileName(True), "Dateiname nicht nach Standard!", MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1)
	'Return
  End If
  'STP-Konverter
  'MessageBox.Show("Saving STP-File", "<DEBUG>")
  If (ThisDoc.PathAndFileName(False) <> "" And STP = 1) Then
  	ThisDoc.Document.SaveAs(ThisDoc.PathAndFileName(False) & ".stp", True)
  End If
End Sub
0 Likes