• Industries
  • Products
  • Buy
  • Services & Support
  • Communities
  • Discussion Groups

    Autodesk Inventor

    Reply
    Contributor
    Posts: 14
    Registered: ‎09-12-2012
    Accepted Solution

    ilogic generate parts list

    422 Views, 2 Replies
    10-04-2012 02:34 AM

    Hi, I curently have a rule that generates a part list automatically in a drawing. the problem is that I want the rule to be continuisly running but it keeps generating 2,3,5... parts lists. I need an if statment to check if a parts list already exists.

     

    iLogicVb.UpdateWhenDone = True   
        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(1)
        
        ' 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(0, 0)
             
             iLogicVb.UpdateWhenDone = True
        End If
        
        ' Create the parts list.    Dim oPartsList As PartsList
        oPartsList = oSheet.PartsLists.Add(oDrawingView, oPlacementPoint)
    
    iLogicVb.UpdateWhenDone = True
    
    iLogicVb.RunRule("SortPartsList")
    Please use plain text.
    *Expert Elite*
    Curtis_Waguespack
    Posts: 1,964
    Registered: ‎03-08-2006

    Re: ilogic generate parts list

    10-04-2012 04:56 AM in reply to: craigzcool

    Hi craigzcool,

     

    Here's a quick rule that checks for an existing parts list:

     

    Dim oDoc As Inventor.DrawingDocument
    oDoc = ThisDoc.Document
    
    'specify the drawing sheet as the first sheet in the collection
    oSheet = oDoc.Sheets(1) 
    
    Try 
    Dim oPartslist As PartsList
    'set as the first parts list found on sheet 1
    oPartslist = oSheet.PartsLists(1)
    MessageBox.Show("There is an existing Parts List", "iLogic")
    Catch 
    MessageBox.Show("There is NOT an existing Parts List", "iLogic")
    End Try

     

    You could also use an Error check to catch the case where no parts list is found, as in this example:

    http://inventortrenches.blogspot.com/2011/02/ilogic-code-for-parts-lists-title.html

     

     I hope this helps.
    Best of luck to you in all of your Inventor pursuits,
    Curtis
    http://inventortrenches.blogspot.com



      solution.png  Did you find this reply helpful ? If so please use the Accept as Solution or  Kudos button below.

    Please use plain text.
    Contributor
    Posts: 14
    Registered: ‎09-12-2012

    Re: ilogic generate parts list

    10-04-2012 05:04 AM in reply to: craigzcool

    The code works perfectly!

     

    Thanks :smileyhappy:

    Please use plain text.