Inventor General Discussion

Inventor General Discussion

Reply
Contributor
craigzcool
Posts: 14
Registered: ‎09-12-2012
Message 1 of 3 (1,039 Views)
Accepted Solution

ilogic generate parts list

1039 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")

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

*Expert Elite*
Curtis_Waguespack
Posts: 2,955
Registered: ‎03-08-2006
Message 2 of 3 (1,031 Views)

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.





Contributor
craigzcool
Posts: 14
Registered: ‎09-12-2012
Message 3 of 3 (1,027 Views)

Re: ilogic generate parts list

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

The code works perfectly!

 

Thanks :smileyhappy:

Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Need installation help?

Start with some of our most frequented solutions or visit the Installation and Licensing Forum to get help installing your software.