- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I am trying to write a macro to first run the place Parts List command in a drawing. Once that parts list is place on the drawing it then runs an iLogic rule I wrote.
The ilogic run runs fine when I run the macro but I can't figure out how to run the place parts list command first and then run the ilogic rule under after it is placed.
I'm not sure how to even add the "DrawingPartsListCmd"(I'm guessing this is the API call to place aparts list) to VB to make it run the command. Any help would be a huge help and I appreciate your time very much. If there is anything else wrong with the code I wrote or is not needed to run the ilogic rule please let me know. I basically put this together based on others posts in here.
My Code so far:
Sub BOMSort()
RuniLogic "BOMSort"
End Sub
Public Sub RuniLogic(ByVal RuleName As String)
Dim iLogicAuto As Object
Dim oDoc As Document
Set oDoc = ThisApplication.ActiveDocument
If oDoc Is Nothing Then
MsgBox "Missing Inventor Document"
Exit Sub
End If
Set iLogicAuto = GetiLogicAddin(ThisApplication)
If (iLogicAuto Is Nothing) Then Exit Sub
iLogicAuto.RunExternalRule oDoc, RuleName
End Sub
Function GetiLogicAddin(oApplication As Inventor.Application) As Object
Set addIns = oApplication.ApplicationAddIns
'Find the add-in you are looking for
Dim addIn As ApplicationAddIn
On Error GoTo NotFound
Set addIn = oApplication.ApplicationAddIns.ItemById("{3bdd8d79-2179-4b11-8a5a-257b1c0263ac}")
If (addIn Is Nothing) Then Exit Function
addIn.Activate
Set GetiLogicAddin = addIn.Automation
Exit Function
NotFound:
End Function
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
It might be better to add the partslist directly with the API as with the command you would still need to position and set the style manually. Here is a forum post for that
There is lots of settings to set up the parts list so here is the API help as well.
Below is the API sample.
Public Sub CreatePartsList()
On Error Resume Next
' Set a reference to the drawing document.
' This assumes a drawing document is active.
Dim oDrawDoc As DrawingDocument
Set oDrawDoc = ThisApplication.ActiveDocument
'Set a reference to the active sheet.
Dim oSheet As Sheet
Set oSheet = oDrawDoc.ActiveSheet
' 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
Set oDrawingView = oSheet.DrawingViews(1)
' Set a reference to th sheet's border
Dim oBorder As Border
Set oBorder = oSheet.Border
Dim oPlacementPoint As Point2d
If Not oBorder Is Nothing Then
' A border exists. The placement point
' is the top-right corner of the border.
Set oPlacementPoint = oBorder.RangeBox.MaxPoint
Else
' There is no border. The placement point
' is the top-right corner of the sheet.
Set oPlacementPoint = ThisApplication.TransientGeometry.CreatePoint2d(oSheet.Width, oSheet.height)
End If
' Create the parts list.
Dim oPartsList As PartsList
Set oPartsList = oSheet.PartsLists.Add(oDrawingView, oPlacementPoint)
End SubOr if this helped you, please, click (like)
Regards
Alan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
That is working perfectly, except one thing, I can't figure out is how to get it to go into the lower left corner instead.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
You will need to get the bottom left corner and then subtract the length of the revision block. Here is a sub routine to do that. Hopefully that works for you.
Private Sub Positiontable(oSheet As Sheet) Dim oPartsTable As PartsList Set oPartsTable = oSheet.PartsLists.Item(1) Dim oWidthPartsTable As Double oWidthPartsTable = oPartsTable.RangeBox.MaxPoint.X - oPartsTable.RangeBox.MinPoint.X Dim oHeightPartsTable As Double oHeightPartsTable = oPartsTable.RangeBox.MaxPoint.Y - oPartsTable.RangeBox.MinPoint.Y Set oTablePt = ThisApplication.TransientGeometry.CreatePoint2d(oSheet.Border.RangeBox.MinPoint.X + oWidthPartsTable, oSheet.TitleBlock.RangeBox.MinPoint.Y + oHeightPartsTable) oPartsTable.Position = oTablePt End Sub
Or if this helped you, please, click (like)
Regards
Alan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Got this all up and running. Figured I'd post this here in case anyone else wanted the code. Also added the option to Sort and enable "autosortonupdate".
Public Sub PlacePartsList()
On Error Resume Next
' Set a reference to the drawing document.
' This assumes a drawing document is active.
Dim oDrawDoc As DrawingDocument
Set oDrawDoc = ThisApplication.ActiveDocument
'Set a reference to the active sheet.
Dim oSheet As Sheet
Set oSheet = oDrawDoc.ActiveSheet
' 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
Set oDrawingView = oSheet.DrawingViews(1)
' Set a reference to th sheet's border
Dim oBorder As Border
Set oBorder = oSheet.Border
Dim oPlacementPoint As Point2d
If Not oBorder Is Nothing Then
' A border exists. The placement point
' is the bottom-left corner of the border.
Set oPlacementPoint = oBorder.RangeBox.MinPoint
Else
' There is no border. The placement point
' is the bottom-left corner of the sheet.
Set oPlacementPoint = ThisApplication.TransientGeometry.CreatePoint2d(0, 0)
End If
' Create the parts list.
Dim oPartsList As PartsList
If oSheet.PartsLists.Count = 0 Then
Set oPartsList = oSheet.PartsLists.Add(oDrawingView, oPlacementPoint)
Else
Set oPartsList = oSheet.PartsLists.Item(1)
End If
Dim oPartsListSize As Vector2d
Set oPartsListSize = ThisApplication.TransientGeometry.CreateVector2d(0, 0)
oPartsListSize.X = oPartsList.RangeBox.MaxPoint.X - oPartsList.RangeBox.MinPoint.X
oPartsListSize.Y = oPartsList.RangeBox.MaxPoint.Y - oPartsList.RangeBox.MinPoint.Y
oPlacementPoint.X = oPlacementPoint.X + oPartsListSize.X
oPlacementPoint.Y = oPlacementPoint.Y + oPartsListSize.Y
oPartsList.Position = oPlacementPoint
'PartsList.Sort2( PrimaryColumnTitle As String, [PrimaryColumnAscending] As Boolean, [SecondaryColumnTitle] As String, [SecondaryColumnAscending] As Boolean, [TertiaryColumnTitle] As String, [TertiaryColumnAscending] As Boolean, [SortByString] As Boolean, [AutoSortOnUpdate] As Boolean )
Call oPartsList.Sort2("ITEM", True, "PART NUMBER", True, "QTY", True, True, True)
'Call oPartsList.Sort2("ITEM", True, AutoSortOnUpdate, True)
End Sub