API add partslist on drawing

API add partslist on drawing

Anonymous
Not applicable
2,583 Views
11 Replies
Message 1 of 12

API add partslist on drawing

Anonymous
Not applicable

Hi,

 

I'm trying to create a partslist on drawing. I managed to achieve this for getting the partslist for the first object on sheet (got the rule from Programming help).

 

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 Sub

 

But this does not serve my need, I want to get the partslist from the first object on sheet1. How can i adjust to do this?

Or can i just replace "oDrawingView" with my object location? (tried it but this does not generate anything.)

0 Likes
2,584 Views
11 Replies
Replies (11)
Message 2 of 12

BrandonBG
Collaborator
Collaborator

Try changing

 

  Set oDrawingView = oSheet.DrawingViews(1)

 

to

 

  Set oDrawingView = oSheet.DrawingViews.Item(1)

Brandon

0 Likes
Message 3 of 12

Anonymous
Not applicable

Format:HTML Format Version:1.0 StartHTML: 165 EndHTML: 10712 StartFragment: 314 EndFragment: 10680 StartSelection: 314 EndSelection: 314SyntaxEditor Code Snippet

    On Error Resume Next
    
    ' Set a reference to the drawing document.
    ' This assumes a drawing document is active.
    Dim oDrawDoc As DrawingDocument
    oDrawDoc = ThisApplication.ActiveDocument

    'Set a reference to the active sheet.
    Dim oSheet As Sheet
    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
    oDrawingView = oSheet.DrawingViews.Item(3)
    
    ' Set a reference to th sheet's border
    Dim oBorder As Border
    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.
        oPlacementPoint = oBorder.RangeBox.MaxPoint
    Else
        ' There is no border. The placement point
        ' is the top-right corner of the sheet.
        oPlacementPoint = ThisApplication.TransientGeometry.CreatePoint2d(oSheet.Width, oSheet.Height)
    End If
    
    ' Create the parts list.
    Dim oPartsList As PartsList
    oPartsList = oSheet.PartsLists.Add(oDrawingView, oPlacementPoint)

 

This still gives me the first view on the current sheet, but this is not the one i need.

 

I'm trying to make a "production book"

Page 1 has the full assembly on it, and all the other sheets just have single parts that need to be made before assembly.

But for each sheet i want to make a reference to the partslist of the main assembly.

So i want to add a partslist from sheet 1,object 1 on sheet x (and then filter the parts i need based on item number).

0 Likes
Message 4 of 12

dominiek_vanwest
Advocate
Advocate

This is a couple of months old, but I just came across this.

 

If I understand it correctly: you want a partslist on sheet x that references the assembly on sheet1?

 

If that's the case you should make 2 sheet variables.

Dim oSheet As Sheet
oSheet = oDrawDoc.ActiveSheet

Dim oMainSheet As Sheet
oMainSheet = oDrawDoc.Sheets.Item(1)

 

And then change this too:

Dim oDrawingView As DrawingView
oDrawingView = oMainSheet.DrawingViews.Item(3)

 

0 Likes
Message 5 of 12

MechMachineMan
Advisor
Advisor
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.Sheets.Item(1) 'Change the 1 to be whatever sheet you want.
    
    ' 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) 'The first view is usually the best one to use, so keep this.
    
    ' 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 Sub

--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.

Justin K
Inventor 2018.2.3, Build 227 | Excel 2013+ VBA
ERP/CAD Communication | Custom Scripting
Machine Design | Process Optimization


iLogic/Inventor API: Autodesk Online Help | API Shortcut In Google Chrome | iLogic API Documentation
Vb.Net/VBA Programming: MSDN | Stackoverflow | Excel Object Model
Inventor API/VBA/Vb.Net Learning Resources: Forum Thread

Sample Solutions:Debugging in iLogic ( and Batch PDF Export Sample ) | API HasSaveCopyAs Issues |
BOM Export & Column Reorder | Reorient Skewed Part | Add Internal Profile Dogbones |
Run iLogic From VBA | Batch File Renaming| Continuous Pick/Rename Objects

Local Help: %PUBLIC%\Documents\Autodesk\Inventor 2018\Local Help

Ideas: Dockable/Customizable Property Browser | Section Line API/Thread Feature in Assembly/PartsList API Static Cells | Fourth BOM Type
0 Likes
Message 6 of 12

GosponZ
Collaborator
Collaborator
 
'activating this command part list table will be inserted and will sit on top of title block on lower right corner

' add partslist table

oDrawDoc = ThisDoc.Document
 'Set a reference to the active sheet.
    Dim oSheet As Sheet
      oSheet = oDrawDoc.ActiveSheet
    Dim oBorder As Border = oSheet.Border
    ' Set a reference to the first drawing view 

 
    Dim oDrawingView As DrawingView
      oDrawingView = oSheet.DrawingViews(1)
      
If Not oBorder Is Nothing Then
	oPlacementPoint = oBorder.RangeBox.MaxPoint
Else
	oPlacementPoint = ThisApplication.TransientGeometry.CreatePoint2d(oSheet.Width, oSheet.Height)
End If


    
   
    ' Create the parts list.
    Dim oPartsList As PartsList
     oPartsList = oSheet.PartsLists.Add(oDrawingView, oPlacementPoint)

     
   
minXpoint = oSheet.TitleBlock.RangeBox.MinPoint.x
minYpoint = oSheet.TitleBlock.RangeBox.MaxPoint.Y
maxXpoint = oPlacementPoint.x
dPointx = oSheet.PartsLists.Item(1).RangeBox.MinPoint.X - minXpoint
dPointY = oSheet.PartsLists.Item(1).RangeBox.MinPoint.Y - minYpoint
maxYpoint = oPlacementPoint.Y - dPointY
    
Dim newmin, newmax As Point2d
newmin = ThisApplication.TransientGeometry.CreatePoint2d(minXpoint, minYpoint)
newmax = ThisApplication.TransientGeometry.CreatePoint2d(maxXpoint, maxYpoint)
oSheet.PartsLists.Item(1).Delete
oPartsList = oSheet.PartsLists.Add(oDrawingView, newmax)

 

 

 

0 Likes
Message 7 of 12

dominiek_vanwest
Advocate
Advocate

MisterZS,

Your post is just how to add a partslist to a drawing, right?

But that's not the question of the topic starter, he already knows how to add a partslist, but he wants a reference to another sheet.

0 Likes
Message 8 of 12

Anonymous
Not applicable

Thanks. Removed the (Set) and it worked fine. So many Places to look

0 Likes
Message 9 of 12

o.sassen
Participant
Participant

Hi All, 

I don't get it right. i still get an error on: Newmin, "Compile error: Agrument not optional"

What can I do? 

 

 

' Create the parts list.
Dim oPartsList As PartsList
oPartsList = oSheet.PartsLists.Add(oDrawingView, oPlacementPoint)



minXpoint = oSheet.TitleBlock.RangeBox.MinPoint.X
minYpoint = oSheet.TitleBlock.RangeBox.MaxPoint.Y
maxXpoint = oPlacementPoint.X
dPointx = oSheet.PartsLists.Item(1).RangeBox.MinPoint.X - minXpoint
dPointY = oSheet.PartsLists.Item(1).RangeBox.MinPoint.Y - minYpoint
maxYpoint = oPlacementPoint.Y - dPointY

Dim newmin As Point2d
Dim newmax As Point2d

newmin = ThisApplication.TransientGeometry.CreatePoint2d(minXpoint, minYpoint)
newmax = ThisApplication.TransientGeometry.CreatePoint2d(maxXpoint, maxYpoint)
oSheet.PartsLists.Item(1).Delete
oPartsList = oSheet.PartsLists.Add(oDrawingView, newmax)
End Sub

0 Likes
Message 10 of 12

dgreatice
Collaborator
Collaborator

Hi.

 

I think do you want to create new Part list base on Main Parts (example: 2 item inside) list in Sheet 1 (example named Assy:1) --> it become Detail Part list per item per sheet (new Part list each item from main partlist then save in another sheet (With new sheet)) ?

 

are my assumption are right?

 

1. Capture.JPG

2. Capture1.JPGCapture2.JPG

 

Please use the ACCEPT AS SOLUTION or KUDOS button if my Idea helped you to solve the problem.

Autodesk Inventor Professional Certified 2014
0 Likes
Message 11 of 12

JamieSENG
Advocate
Advocate

I use this with success...

 

'iLogic rule CreatePartsList places the parts list 
'at the top right corner of the border if one exists, 
'else it is placed at the top right corner of the sheet.

Try
'drawing document should be active, 
'the first view should be tied to the assembly model
'set a reference to the active sheet
oDrawDoc = ThisApplication.ActiveDocument
oSheet = oDrawDoc.ActiveSheet

'set a reference to the sheet's border
Dim oBorder As Border = oSheet.Border
Dim oPlacementPoint As Point2d
'a border exists. The placement point
'is the top-right corner of the border
If oBorder IsNot Nothing Then
oPlacementPoint = oBorder.RangeBox.MaxPoint
Else
'there is no border. The placement point
'is the top-right corner of the sheet
oPlacementPoint = ThisApplication.TransientGeometry.CreatePoint2d(oSheet.Width, oSheet.Height)
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
'create the parts list
Dim viw As DrawingView = oDrawDoc.ActiveSheet.DrawingViews.Item(1)
oDrawDoc.Sheets(1).PartsLists.Add(viw, oPlacementPoint, PartsListLevelEnum.kStructuredAllLevels, Nothing, 1, True)

Dim oPartsList1 As PartsList
oPartsList1 = oDrawDoc.ActiveSheet.PartsLists.Item(1)
'If oPartsList1 Is Nothing Then Resume Next

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

Catch
'if an error occurs message box appears
    MessageBox.Show("Something went wrong!" & vbLf & "Create Manually", "Oops!!")

End Try
Message 12 of 12

GosponZ
Collaborator
Collaborator

ok this one will put parts list on left upper corner

Format:HTML Format Version:1.0 StartHTML: 165 EndHTML: 11332 StartFragment: 314 EndFragment: 11300 StartSelection: 314 EndSelection: 314SyntaxEditor Code Snippet

Sub Main()

'Declare local variables
Dim oDrawDoc As DrawingDocument
Dim oSheet As Sheet
Dim oDrawingView As DrawingView
Dim oPlacementPoint As Point2d
Dim oPartsList As PartsList 
Dim oBorder As Border
Dim oStyle As String
Dim oPlaceX As Double
Dim oPlaceY As Double

'initialize variables
oDrawDoc = ThisApplication.ActiveDocument
oSheet = oDrawDoc.ActiveSheet
oDrawingView = oSheet.DrawingViews(1)
oBorder = oSheet.Border

'user input - select parts list style
'oStyle = InputListBox("Choose Parts List Style", MultiValue.List("PartsListStyle"), "Custom Parts List (ANSI)", "Parts List Style", "List Prompt") 

'create parts list
oPartsList = oSheet.PartsLists.Add(oDrawingView, oBorder.RangeBox.MinPoint)
'oPartsList.Style = oDrawDoc.StylesManager.PartsListStyles.Item(oStyle)

'reposition parts list to top left
oPlaceX = oBorder.RangeBox.MinPoint.X + (oPartsList.RangeBox.MaxPoint.X - oPartsList.RangeBox.MinPoint.X)+(1.27)
oPlaceY = oBorder.RangeBox.MaxPoint.Y 
oPlacementPoint = ThisApplication.TransientGeometry.CreatePoint2d(oPlaceX,oPlaceY)
oPartslist.position = oPlacementPoint

End Sub
0 Likes