- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hey y'all. I am trying to create some code I can run in a drawing document that is going to automatically add a different parts list to my sheet depending on if the current view on the sheet is a part or assembly. I have pieced together some code, but have not had any success when running it. (no errors, but nothing happens) I think the problem is something to do with calling on "oDwgDoc.type" and not the type in the view on the sheet. I have pasted the code below:
oDwgDoc = ThisApplication.ActiveDocument Dim oSheet As Sheet oSheet = oDwgDoc.ActiveSheet Dim oBaseView As DrawingView Dim oPartsList As PartsList oBaseView = oSheet.DrawingViews.Item(1) If Not oBorder Is Nothing Then oPlacementPoint = oBorder.RangeBox.MaxPoint Else oPlacementPoint = ThisApplication.TransientGeometry.CreatePoint2d(oSheet.Width - 2.54/2, oSheet.Height - 2.54) End If Try oPartsList = oSheet.PartsLists(1) Catch If oDwgDoc.Type = kAssemblyDocumentObject Then oPartsList = oSheet.PartsLists.Add(oBaseView, oPlacementPoint) oPartsList.Style = oDwgDoc.StylesManager.PartsListStyles.Item("Assembly List") Else If oDwgDoc.Type = kPartDocumentObject Then oPartsList = oSheet.PartsLists.Add(oBaseView, oPlacementPoint) oPartsList.Style = oDwgDoc.StylesManager.PartsListStyles.Item("Parts List Dimensionless") End If End Try End Sub
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
The easiest method is using the ilogic API route. This targets the document at view (1) of sheet (1)
Dim modelDoc As Document = ThisDoc.ModelDocument
The longer method is the Inventor API route helpful article here
Then once you have the document you can determine its document type see help page here
Syntax
Document.DocumentType() As DocumentTypeEnum
Property
If doc.DocumentType = DocumentTypeEnum.kAssemblyDocumentObject Then
'DO SOMETHING
End If
Or if this helped you, please, click (like)
Regards
Alan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
try this:
Dim doc = ThisApplication.ActiveDocument
Dim sheet As Sheet = doc.ActiveSheet
Dim baseView As DrawingView = sheet.DrawingViews.Item(1)
Dim refDoc As Document = baseView.ReferencedDocumentDescriptor.ReferencedDocument
Dim border = sheet.Border
Dim placementPoint = border.RangeBox.MaxPoint
If border Is Nothing Then
placementPoint = ThisApplication.TransientGeometry.CreatePoint2d(sheet.Width - 2.54 / 2, sheet.Height - 2.54)
End If
Dim partsList As PartsList
Try
partsList = sheet.PartsLists(1)
Catch
partsList = sheet.PartsLists.Add(baseView, placementPoint)
End Try
If refDoc.DocumentType = DocumentTypeEnum.kAssemblyDocumentObject Then
partsList.Style = doc.StylesManager.PartsListStyles.Item("Assembly List")
ElseIf refDoc.DocumentType = DocumentTypeEnum.kPartDocumentObject Then
partsList.Style = doc.StylesManager.PartsListStyles.Item("Parts List Dimensionless")
End If
Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
Blog: hjalte.nl - github.com
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I had only tested this on drawing sheets with parts, and it works fine, but when trying it on a sheet with an assembly I get the following error(below). If I place a parts list manually, it will set it to the correct format. It is just unable to place it by itself.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
When you add a partlist and intend it to be for an assembly you need to set the PartlistlevelEnum which is parts only or structured all level etc. See partlist.add method API help here.
If you look at the more info tab of the error message this might be explained. Tab 1 is no good for diagnostics and should be ignored.
In the API help page navigate to PartsListLevelEnum here and select the correct one.
Syntax
PartsLists.Add( ViewOrModel As Object, PlacementPoint As Point2d, [Level] As PartsListLevelEnum, [NumberingScheme] As Variant, [NumberOfSections] As Long, [WrapLeft] As Boolean ) As PartsList
Or if this helped you, please, click (like)
Regards
Alan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
That worked! I just had to add in an extra "else if" statement for the assemblies. Here is what I added below in case this helps someone in the future:
If refDoc.DocumentType = DocumentTypeEnum.kPartDocumentObject Then Try oPartsList = oSheet.PartsLists(1) Catch oPartsList = oSheet.PartsLists.Add(baseView, placementPoint) End Try Else If refDoc.DocumentType = DocumentTypeEnum.kAssemblyDocumentObject Then Try oPartsList = oSheet.PartsLists(1) Catch Try oPartsList = oSheet.PartsLists.Add(baseView, placementPoint, kFirstLevelComponents) Catch oPartsList = oSheet.PartsLists.Add(baseView, placementPoint, kPartsOnly) End Try End Try End If
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
This code is for the part more interesting. The Part List comes with both number part and quantity.
This code is for the part more interesting. The Part List comes with both number part and quantity.
Sub Main
Dim invDoc As DrawingDocument = ThisApplication.ActiveDocument
Dim oSheet As Sheet = invDoc.ActiveSheet
Dim oSheet1 As Sheet = invDoc.Sheets.Item(1)
Dim oDrawingView As DrawingView = oSheet1.DrawingViews(1)
Dim oBorder As Border = oSheet.Border
Dim oPlacementPoint As Point2d
If Not oBorder Is Nothing Then
oPlacementPoint = oBorder.RangeBox.MaxPoint
Else
oPlacementPoint = ThisApplication.TransientGeometry.CreatePoint2d(oSheet.Width, oSheet.Height) 'Kur ideti partlista
End If
Dim partsListBomType As PartsListLevelEnum = 46593
Dim oPartsList_G As PartsList = oSheet.PartsLists.Add(oDrawingView, oPlacementPoint, partsListBomType)
For Each oRow In oPartsList_G.PartsListRows
oRow.Visible = True
Next
Dim oView As DrawingView = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kDrawingViewFilter, "pick drawing view.")
Dim oSheet2 As Sheet = oView.Parent
Dim RefDoc As Document = oView.ReferencedDocumentDescriptor.ReferencedDocument
Dim RefDocName As String = RefDoc.FullFileName
Dim oPartList As PartsList = oPartsList_G
Dim PLRows As PartsListRows = oPartList.PartsListRows
For Each PLRow As PartsListRow In PLRows
Dim ListDoc As Document = PLRow.ReferencedRows.Item(1).BOMRow.ComponentDefinitions.Item(1).Document()
If Not ListDoc.FullFileName = RefDocName Then
PLRow.Visible = False
End If
Next
ThisApplication.CommandManager.ControlDefinitions.Item("DrawingUpdateAllSheetsCmd").Execute
End Sub
If for example, @A.Acheson or @JelteDeJong I adjusted it so that it reacts to both Subassembly and Assembly, it would be generally ideal.