Announcements

Starting in December, we will archive content from the community that is 10 years and older. This FAQ provides more information.

Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How do I check Parts List exists vba?

3 REPLIES 3
SOLVED
Reply
Message 1 of 4
Anonymous
954 Views, 3 Replies

How do I check Parts List exists vba?

I find this code. It's good work.

 

https://forums.autodesk.com/t5/inventor-customization/place-parts-list/m-p/5841794/highlight/true#M5...

 

but Do not check  Parts List exists.

 

I want to add a check function.

 

 

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

 

 Thank you.

 

 

Tags (4)
3 REPLIES 3
Message 2 of 4
dgreatice
in reply to: Anonymous

Hi,

 

To check if partslist table already exist add more code:

 

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

on error resume next

Set oPartsList = oSheet.PartsLists.item(1)

if err.number <> 0 then
Set oPartsList = oSheet.PartsLists.Add(oDrawingView, oPlacementPoint)

else

'Do Nothing or if you want to edit existing partlist

end if
End Sub

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

Autodesk Inventor Professional Certified 2014
Message 3 of 4
Anonymous
in reply to: dgreatice

Thank you~

 

it's work. Very well.

 

 

Message 4 of 4
dgreatice
in reply to: Anonymous

Accept as solution?

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

Autodesk Inventor Professional Certified 2014

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report