ilogic: Add individual mass property to drawing BOM

ilogic: Add individual mass property to drawing BOM

dialunau
Advocate Advocate
899 Views
5 Replies
Message 1 of 6

ilogic: Add individual mass property to drawing BOM

dialunau
Advocate
Advocate

Hello everyone, I'm starting with the ilogic drawing code. I want to show the inividual mass propety for all of he components of the assembly, but I can't get it to work. I'm tryin to add the new column at the end of the BOM, but it gives me the following error:

 

Error in rule: 1, in document: X.iam

The parameter is incorrect. (Exception from HRESULT: 0x80070057 (E_INVALIDARG))

 

My code is as follows:

'///////////////////  C O D E  ///////////////////////'

 

Sub Main()
	Dim oPartDoc As Document
	oPartDoc = ThisDoc.Document
	Dim oDrawingDoc As DrawingDocument
	Dim typ As DocumentTypeEnum
	typ = ThisDoc.Document.Type
    oDrawingDoc = ThisApplication.Documents.Add(Inventor.DocumentTypeEnum.kDrawingDocumentObject, "C:\Users\Public\Documents\Autodesk\Inventor 2021\Templates\en-US\BOHN.idw", True)
	
	Call ansicht(oPartDoc,oDrawingDoc)
End Sub

'////////// Place views ////////////////////////////////////////////////////////////////////////////////

Sub ansicht(oPartDoc, oDrawingDoc)
	Dim oSheet As Sheet
	Dim oDoc1 As String = ThisDoc.FileName(False)
	Dim oBaseViewOptions As NameValueMap
	Dim oPoint0 As Point2d
	Dim oView0 As DrawingView
	
	SpiderID = Right(oDoc1, Len(oDoc1))
	ViewScale = 0.5
	oSheet = oDrawingDoc.Sheets.Item(1)
	oBaseViewOptions = ThisApplication.TransientObjects.CreateNameValueMap
	oBaseViewOptions.Add(SpiderID & ".ipt", False)
	oPoint0 = ThisApplication.TransientGeometry.CreatePoint2d(37,15) ' front view
	oView0 = oSheet.DrawingViews.AddBaseView(oPartDoc, oPoint0, ViewScale, kFrontViewOrientation, kHiddenLineRemovedDrawingViewStyle, "View1")
	
	Dim oPview1 As DrawingView
	Dim oPview2 As DrawingView
	Dim oPview3 As DrawingView
	Dim oPview4 As DrawingView
	Dim oPoint1 As Point2d
	Dim oPoint2 As Point2d
	Dim oPoint3 As Point2d
	Dim oPoint4 As Point2d
	
	oPoint1 = ThisApplication.TransientGeometry.CreatePoint2d(60, 15)
	oPview1 = oSheet.DrawingViews.AddProjectedView(oView0, oPoint1, kHiddenLineRemovedDrawingViewStyle, ViewScale)
	oPoint2 = ThisApplication.TransientGeometry.CreatePoint2d(10, 15)
	oPview2 = oSheet.DrawingViews.AddProjectedView(oView0, oPoint2, kHiddenLineRemovedDrawingViewStyle, ViewScale)
	oPoint3 = ThisApplication.TransientGeometry.CreatePoint2d(37, 42)
	oPview3 = oSheet.DrawingViews.AddProjectedView(oView0, oPoint3, kHiddenLineRemovedDrawingViewStyle, ViewScale)
	oPoint4 = ThisApplication.TransientGeometry.CreatePoint2d(60, 42)
	oPview4 = oSheet.DrawingViews.AddProjectedView(oView0, oPoint4, kHiddenLineRemovedDrawingViewStyle, ViewScale)
	
	Call BOM(oDrawingDoc,oSheet,oView,oPartDoc)
End Sub

'////////// B O M ////////////////////////////////////////////////////////////////////////////////

Sub BOM(oDrawingDoc,oSheet,oView0,oPartDoc)

	Dim oBOM As BOM
	Dim oPartsLists As PartsLists
	Dim oPartsList As PartsList

	'Try to get the first view on the sheet
	Try
		oView0 = oSheet.DrawingViews(1)
	Catch
		MessageBox.Show("There is no view in the drawing", _
		"Export du dessin", MessageBoxButtons.OK, MessageBoxIcon.Error)
		Return
	End Try

	'gets the refference model
	oModelDoc = oPartDoc
	'BOM database
	oBOM = oModelDoc.ComponentDefinition.BOM
	' enable the BOM view
	oBOM.PartsOnlyViewEnabled = True
	'get the PartsLists collection
	oPartsLists = oSheet.PartsLists
	'clean up part lists on the drawing
	For Each oPartsList In oPartsLists
		oPartsList.Delete
	Next
	
	'Setting BOM position
	Dim BomPlacementPoint As Point2d
	Dim oBorder As Border = oSheet.Border
	BomPlacementPoint = ThisApplication.TransientGeometry.CreatePoint2d _
	(0, oBorder.RangeBox.MaxPoint.Y)
	
	'Create new partsList
	oPartsList = oPartsLists.Add(oView0, BomPlacementPoint, PartsListLevelEnum.kPartsOnly)
	
	'specify property set
	Dim oPropSetID As String
	Dim oPropType As String
	Dim oPropSet As PropertySets = oPartDoc.PropertySets	
	Dim oProp As PropertySet
	Dim oMass As String
	oProp = oPropSet.Item("Design tracking properties")
	
	'specify the mass property
	oMass = oProp.Item(39).Name

	'specify the property
	oProp = oPropSet.Item(39)
	oPropType = Inventor.PropertyTypeEnum.kVolumePartsListProperty
	oPropSetID = oProp.InternalName
	
	'Set the new column position
	oColTargetIndex = 5
	oColumnInsertBefore = False 
	
	'add column
	oCol = oPartsList.PartsListColumns.Add(oPropType, oPropSetID, oProp.PropId, oColTargetIndex, oColumnInsertBefore)
End Sub

 

Thanks for the help.

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

Anonymous
Not applicable

@dialunau  Try this.

 

Sub Main()
	Dim oPartDoc As Document
	oPartDoc = ThisDoc.Document
	Dim oDrawingDoc As DrawingDocument
	Dim typ As DocumentTypeEnum
	typ = ThisDoc.Document.Type
    oTemplate = ThisApplication.Documents.Add(Inventor.DocumentTypeEnum.kDrawingDocumentObject, _
	"C:\Users\Public\Documents\Autodesk\Inventor 2020\Templates\en-US\Metric\ISO.idw", True)
	
	
	Call ansicht()
End Sub


Sub ansicht ()

Dim oAsmDoc As AssemblyDocument
oAsmDoc = ThisApplication.Documents.Open _
("C:\Users\Joseph\Desktop\Inventor Study\Test.iam", False)


Dim oDrawingDoc As DrawingDocument = ThisApplication.ActiveDocument      
Dim oSheet As Sheet = oDrawingDoc.Sheets.Item(1)
Dim oScale As Double = 1 / 10


Dim Pt_0 As Point2d = ThisApplication.TransientGeometry.CreatePoint2d(5, 5)
Dim Pt_1 As Point2d = ThisApplication.TransientGeometry.CreatePoint2d(60, 5)
Dim Pt_2 As Point2d = ThisApplication.TransientGeometry.CreatePoint2d(5, 60)

Dim bView As DrawingView = oSheet.DrawingViews.AddBaseView(oAsmDoc, _
Pt_0, 1, kFrontViewOrientation, kHiddenLineDrawingViewStyle)
bView.Scale = oScale

pView_1 = oSheet.DrawingViews.AddProjectedView(bView, Pt_1, kHiddenLineRemovedDrawingViewStyle, oScale)
pView_2 = oSheet.DrawingViews.AddProjectedView(bView, Pt_2, kHiddenLineRemovedDrawingViewStyle, oScale)

oAsmDoc.Close(True)

Call BOM()

End Sub





Sub BOM ()

Dim oDrawingDoc As DrawingDocument = ThisApplication.ActiveDocument
    
Dim oSheet As Sheet
oSheet = oDrawingDoc.ActiveSheet

'Detect if the template has a parts list
Try 
Dim oPartslistCheck As PartsList
oPartslistCheck = oSheet.PartsLists(1)
partslistpresent=True
Catch
partslistpresent=False
End Try

If partslistpresent=True
        
        'Delete the current parts list
        Dim oPartsList As PartsList
        oPartsList = oDrawingDoc.ActiveSheet.PartsLists.Item(1)
        oPartsList.Delete
        
End If
                
    ' Set a reference to the first drawing view on
    ' the sheet. This assumes the first drawing
    ' view on the sheet is not a draft view.
    Dim oDrawingView As DrawingView
    oDrawingView = oSheet.DrawingViews(1)
    
    ' Set a reference to the sheet's border
    Dim oBorder As Border
    oBorder = oSheet.Border
    
    Dim oPlacementPoint As Point2d
    
        xrev = oBorder.RangeBox.MaxPoint.X
        yrev = oBorder.RangeBox.MaxPoint.Y
        
        oPlacementPoint = ThisApplication.TransientGeometry.CreatePoint2d(xrev, yrev)
        
    ' Create the parts list.
    Dim oPartsList1 As PartsList
    oPartsList1 = oSheet.PartsLists.Add(oDrawingView, oPlacementPoint)
oPartsLis1t = oDrawingDoc.ActiveSheet.PartsLists.Item(1)


oPartsList1.Sort("PART NUMBER")
oPartsList1.Renumber


oPartsList1.Style.UpdateFromGlobal 

'Switch style back and forth to ensure style is up-to-date    
    oPartsList1.Style = oDrawingDoc.StylesManager.PartsListStyles.Item("Parts List (ANSI)")
    oPartsList1.Style = oDrawingDoc.StylesManager.PartsListStyles.Item("Parts List (ISO)")

InventorVb.DocumentUpdate()
End Sub
0 Likes
Message 3 of 6

dialunau
Advocate
Advocate

I can create the BOM with this code, however, my problem is that I want to add the "Mass" property to the part list, so I can see the individual mass of all of the components in the drawing. Do you know how to add the mass column automatially with ilogic? .

0 Likes
Message 4 of 6

Anonymous
Not applicable

Hi @dialunau . Sorry I forgot to mention. Im having trouble adding the mass column. 

0 Likes
Message 5 of 6

Anonymous
Not applicable
Accepted solution

@dialunau  Here is the updated code.

 

Sub Main()
	Dim oPartDoc As Document
	oPartDoc = ThisDoc.Document
	Dim oDrawingDoc As DrawingDocument
	Dim typ As DocumentTypeEnum
	typ = ThisDoc.Document.Type
    oTemplate = ThisApplication.Documents.Add(Inventor.DocumentTypeEnum.kDrawingDocumentObject, _
	"C:\Users\Public\Documents\Autodesk\Inventor 2020\Templates\en-US\Metric\ISO.idw", True)
	
	
	Call ansicht()
End Sub


Sub ansicht ()

Dim oAsmDoc As AssemblyDocument
oAsmDoc = ThisApplication.Documents.Open _
("C:\Users\Joseph\Desktop\Inventor Study\AL WASL\Workspaces\Workspace\03.Assembly Masters\01.UCW Panels\508540FT01CB24-013\508540FT01CB24-013.iam", False)


Dim oDrawingDoc As DrawingDocument = ThisApplication.ActiveDocument      
Dim oSheet As Sheet = oDrawingDoc.Sheets.Item(1)
Dim oScale As Double = 1 / 10


Dim Pt_0 As Point2d = ThisApplication.TransientGeometry.CreatePoint2d(5, 5)
Dim Pt_1 As Point2d = ThisApplication.TransientGeometry.CreatePoint2d(60, 5)
Dim Pt_2 As Point2d = ThisApplication.TransientGeometry.CreatePoint2d(5, 60)

Dim bView As DrawingView = oSheet.DrawingViews.AddBaseView(oAsmDoc, _
Pt_0, 1, kFrontViewOrientation, kHiddenLineDrawingViewStyle)
bView.Scale = oScale

pView_1 = oSheet.DrawingViews.AddProjectedView(bView, Pt_1, kHiddenLineRemovedDrawingViewStyle, oScale)
pView_2 = oSheet.DrawingViews.AddProjectedView(bView, Pt_2, kHiddenLineRemovedDrawingViewStyle, oScale)

oAsmDoc.Close(True)

Call BOM()

End Sub





Sub BOM ()

Dim oDrawingDoc As DrawingDocument = ThisApplication.ActiveDocument
    
Dim oSheet As Sheet
oSheet = oDrawingDoc.ActiveSheet

'Detect if the template has a parts list
Try 
Dim oPartslistCheck As PartsList
oPartslistCheck = oSheet.PartsLists(1)
partslistpresent=True
Catch
partslistpresent=False
End Try

If partslistpresent=True
        
        'Delete the current parts list
        Dim oPartsList As PartsList
        oPartsList = oDrawingDoc.ActiveSheet.PartsLists.Item(1)
        oPartsList.Delete
        
End If
                
    ' Set a reference to the first drawing view on
    ' the sheet. This assumes the first drawing
    ' view on the sheet is not a draft view.
    Dim oDrawingView As DrawingView
    oDrawingView = oSheet.DrawingViews(1)
    
    ' Set a reference to the sheet's border
    Dim oBorder As Border
    oBorder = oSheet.Border
    
    Dim oPlacementPoint As Point2d
    
        xrev = oBorder.RangeBox.MaxPoint.X
        yrev = oBorder.RangeBox.MaxPoint.Y
        
        oPlacementPoint = ThisApplication.TransientGeometry.CreatePoint2d(xrev, yrev)
        
    ' Create the parts list.
    Dim oPartsList1 As PartsList
    oPartsList1 = oSheet.PartsLists.Add(oDrawingView, oPlacementPoint)
oPartsLis1t = oDrawingDoc.ActiveSheet.PartsLists.Item(1)

oPartsList1.Style.UpdateFromGlobal 

'Switch style back and forth to ensure style is up-to-date    
    oPartsList1.Style = oDrawingDoc.StylesManager.PartsListStyles.Item("Parts List (ANSI)")
    oPartsList1.Style = oDrawingDoc.StylesManager.PartsListStyles.Item("Parts List (ISO)")
	
'ADD COLUMNS
Dim oColumns As PartsListColumns = oPartsList1.PartsListColumns
oColumns.Add(kMassPartsListProperty, "{32853F0F-3444-11D1-9E93-0060B03C1CA6}", "58")
oColumns.Add(kVolumePartsListProperty, "{32853F0F-3444-11D1-9E93-0060B03C1CA6}", "60")


oPartsList1.Sort("PART NUMBER")
oPartsList1.Renumber

InventorVb.DocumentUpdate()
 
End Sub
0 Likes
Message 6 of 6

dialunau
Advocate
Advocate

That's exactly what I needed, now I can see the mass of the components of the assembly.

Thanks a lot.

0 Likes