Community
Inventor Forum
Welcome to Autodesk’s Inventor Forums. Share your knowledge, ask questions, and explore popular Inventor topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

ilogic generate parts list

18 REPLIES 18
SOLVED
Reply
Message 1 of 19
craigzcool
8640 Views, 18 Replies

ilogic generate parts list

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")
18 REPLIES 18
Message 2 of 19

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

Message 3 of 19
craigzcool
in reply to: craigzcool

The code works perfectly!

 

Thanks 🙂

Message 4 of 19

Im super new to ILOGIC, how do I combine the above codes to run. I cant even get the parts list generator to work. I created a rule, and copied the text, but when I run, nothing happens.
Message 5 of 19

Hi PhilLindsay4781,

 

Are you using Inventor 2015, 2016 or 2017? If so I can create a quick example file for you to look at.

 

In the mean time there is a line that reads "On Error Resume Next", if you delete that line it will present you with an error that might tell you what the issue is. That like skips the error, and acts like it isn't running.

 

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

Message 6 of 19

Im actually using 2012
Message 7 of 19

I deleted the error code line ... This is the "Error Message" Error in rule: INTERNAL PARTS LIST, in document: Edwards_ANSI_V3-REV-1.dwg The parameter is incorrect. (Exception from HRESULT: 0x80070057 (E_INVALIDARG)) This is the "More Info" System.ArgumentException: The parameter is incorrect. (Exception from HRESULT: 0x80070057 (E_INVALIDARG)) at Microsoft.VisualBasic.CompilerServices.LateBinding.LateGet(Object o, Type objType, String name, Object[] args, String[] paramnames, Boolean[] CopyBack) at Microsoft.VisualBasic.CompilerServices.NewLateBinding.LateGet(Object Instance, Type Type, String MemberName, Object[] Arguments, String[] ArgumentNames, Type[] TypeArguments, Boolean[] CopyBack) at LmiRuleScript.Main() at Autodesk.iLogic.Exec.AppDomExec.ExecRuleInAssembly(Assembly assem) at iLogic.RuleEvalContainer.ExecRuleEval(String execRule)
Message 8 of 19


@PhilLindsay4781 wrote:
Im actually using 2012

Hi PhilLindsay4781,

 

 

See if this code will run for you. Sometimes this forum has copy/paste errors, so post back if you see some "weirdness" with the code (all other "weirdness" you see, you should keep to yourself or blame on the person sitting next to you  Smiley Happy ).

 

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

 

iLogicVb.UpdateWhenDone = True   

' 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

Try
	oDrawingView = oSheet.DrawingViews(1)
Catch
	MessageBox.Show("No View found. Can not continue", "iLogic")
	Return 'return exits the rule
End Try

' 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 	 
	oPlacementPoint = ThisApplication.TransientGeometry.CreatePoint2d(20, 20)     
     
End If

Dim oPartslist As PartsList

Try		
	'look for the first parts list found on the sheet 
	'if succesful finding it, 
	'tell the user,then Do Nothing
	oPartslist = oSheet.PartsLists(1)
	MessageBox.Show("There is an existing Parts List", "iLogic")
	
Catch
	'if one is not found, Create it
	oPartsList = oSheet.PartsLists.Add(oDrawingView, oPlacementPoint)
End Try

 

Message 9 of 19

This is working 90% for me ... How can I offset to the left from the defined "MaxPoint"? If Not oBorder Is Nothing Then ' A border exists. The placement point ' is the top-right corner of the border. oPlacementPoint = oBorder.RangeBox.MaxPoint
Message 10 of 19

Hi PhilLindsay4781,

 

So I added an offset value called oOffset. to adjust the X coordinate location.

 

It's set at -5 in this example, so you can changes just that number and it should work for you.

 

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

 

 

iLogicVb.UpdateWhenDone = True   

' 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

Try
	oDrawingView = oSheet.DrawingViews(1)
Catch
	MessageBox.Show("No View found. Can not continue", "iLogic")
	Return
End Try

' Set a reference to th sheet's border    
Dim oBorder As Border
oBorder = oSheet.Border

Dim oPlacePoint As Point2d

If Not oBorder Is Nothing Then
    ' A border exists. The placement point        
	' is the top-right corner of the border. 
	oOffset = -5 'user defined offset
	oX = oBorder.RangeBox.MaxPoint.X + oOffset
	oY = oBorder.RangeBox.MaxPoint.Y
	oPlacePoint = ThisApplication.TransientGeometry.CreatePoint2d(oX,oY)
Else
    ' There is no border 
	 
	oPlacementPoint = ThisApplication.TransientGeometry.CreatePoint2d(20, 20)
     
     iLogicVb.UpdateWhenDone = True
End If

Dim oPartslist As PartsList

Try		
	'look for the first parts list found on the sheet 
	'if succesful finding it, 
	'tell the user,then Do Nothing
	oPartslist = oSheet.PartsLists(1)
	MessageBox.Show("There is an existing Parts List", "iLogic")
	
Catch
	' Create the parts list.  
	oPartsList = oSheet.PartsLists.Add(oDrawingView, oPlacePoint)
End Try
Message 11 of 19

This worked perfectly, I was able to offset this from my corner. I have a couple more things ... How can I edit the BOM columns created using illogic? The current BOM is ok for one style of drawings I do. ITEM, QTY, DESCRIPTION, PART NUMBER However sometimes I use the following ITEM, QTY, DESCRIPTION, STOCK NUMBER, VENDOR Can this be done?
Message 12 of 19

Hi PhilLindsay4781,

 

If I understand correctly, you'll want to set up 2 parts list styles (I think... I seem to recall something about not being able to set the parts list style? ).

 

I recommend you start a new topic on the Inventor Customization forum and ask this new question:
http://forums.autodesk.com/t5/Autodesk-Inventor-Customization/bd-p/120

 

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

Message 13 of 19

OK thanks, I hope they can help.
Message 14 of 19

iLogicVb.UpdateWhenDone = True   

' 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

Try
	oDrawingView = oSheet.DrawingViews(1)
Catch
	MessageBox.Show("No View found. Can not continue", "iLogic")
	Return
End Try

' Set a reference to th sheet's border    
Dim oBorder As Border
oBorder = oSheet.Border

Dim oPlacePoint As Point2d

If Not oBorder Is Nothing Then
    ' A border exists. The placement point        
	' is the top-right corner of the border. 
	oOffset = +29.7 'user defined offset
	oX = oBorder.RangeBox.MinPoint.X + oOffset
	oY = oBorder.RangeBox.MinPoint.Y
	oPlacePoint = ThisApplication.TransientGeometry.CreatePoint2d(oX,oY)
Else
    ' There is no border 
	 
	oPlacementPoint = ThisApplication.TransientGeometry.CreatePoint2d(20, 20)
     
     iLogicVb.UpdateWhenDone = True
End If

Dim oPartslist As PartsList

Try		
	'look for the first parts list found on the sheet 
	'if succesful finding it, 
	'tell the user,Then Do Nothing
	oPartslist = oSheet.PartsLists(1)
	MessageBox.Show("There is an existing Parts List", "iLogic")
	
Catch
	' Create the parts list.  
	oPartsList = oSheet.PartsLists.Add(oDrawingView, oPlacePoint)
	'set parts list to a specific layer
	oPartsList.Layer = oDrawDoc.StylesManager.Layers.Item("COSTING")
	'set parts list to a specific style
	oPartsList.Style = oDrawDoc.StylesManager.PartsListStyles.Item("TENDER - COSTING")
	
	' Create the parts list.  
	oPartsList = oSheet.PartsLists.Add(oDrawingView, oPlacePoint)
	'set parts list to a specific layer
	oPartsList.Layer = oDrawDoc.StylesManager.Layers.Item("TENDER")
	'set parts list to a specific style
	oPartsList.Style = oDrawDoc.StylesManager.PartsListStyles.Item("TENDER - EXPORT")

End Try

Capture.PNG

It will work for me, & edited your code to create two style of part list, i want to place my part list in Arrow marked orgin point.

and both layer merged to same orgin. 


@Curtis_Waguespack wrote:

Hi PhilLindsay4781,

 

So I added an offset value called oOffset. to adjust the X coordinate location.

 

It's set at -5 in this example, so you can changes just that number and it should work for you.

 

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

 

 

iLogicVb.UpdateWhenDone = True   

' 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

Try
	oDrawingView = oSheet.DrawingViews(1)
Catch
	MessageBox.Show("No View found. Can not continue", "iLogic")
	Return
End Try

' Set a reference to th sheet's border    
Dim oBorder As Border
oBorder = oSheet.Border

Dim oPlacePoint As Point2d

If Not oBorder Is Nothing Then
    ' A border exists. The placement point        
	' is the top-right corner of the border. 
	oOffset = -5 'user defined offset
	oX = oBorder.RangeBox.MaxPoint.X + oOffset
	oY = oBorder.RangeBox.MaxPoint.Y
	oPlacePoint = ThisApplication.TransientGeometry.CreatePoint2d(oX,oY)
Else
    ' There is no border 
	 
	oPlacementPoint = ThisApplication.TransientGeometry.CreatePoint2d(20, 20)
     
     iLogicVb.UpdateWhenDone = True
End If

Dim oPartslist As PartsList

Try		
	'look for the first parts list found on the sheet 
	'if succesful finding it, 
	'tell the user,then Do Nothing
	oPartslist = oSheet.PartsLists(1)
	MessageBox.Show("There is an existing Parts List", "iLogic")
	
Catch
	' Create the parts list.  
	oPartsList = oSheet.PartsLists.Add(oDrawingView, oPlacePoint)
End Try

Message 15 of 19

It works with loaded PARTmodel, but if I have an ASSEMBLY I get this error:

 

2018-01-26_11h08_32.png2018-01-26_11h10_01.png

 

INV 2018.2.3, Build 227

 

please HELP me

Message 16 of 19

1. What code are you using?

 

2. What you posted doesn't make sense. Parts DO NOT have associated BOMs - Assemblies DO.

 

3. Depending on what type of partslist you are trying to place, you must ensure the BOM has the assosciated BOM View ENABLED (structured bom view and Parts Only bom view)


--------------------------------------
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
Message 17 of 19

Hi,

I use this code:

iLogicVb.UpdateWhenDone = True
Dim bStyle As Boolean
'bStyle = InputRadioBox("Select one:", "Part", "Assy", True, "iLogic")
Dim sStye As String
''set the parts list style names to use
'If bStyle = True Then

doc = ThisDoc.ModelDocument
If doc.DocumentType = kPartDocumentObject Then
sStyle = "AWG Part"
Else
sStyle = "AWG Assy"
End If
' 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
Try
oDrawingView = oSheet.DrawingViews(1)
Catch
MessageBox.Show("No View found. Can not continue", "iLogic")
Return
End Try
' Set a reference to th sheet's border
Dim oBorder As Border
oBorder = oSheet.Border
Dim oPlacePoint As Point2d
If Not oBorder Is Nothing Then
' A border exists. The placement point
' is the top-right corner of the border.
oOffset = 4.97 'user defined offset
oX = oBorder.RangeBox.MaxPoint.X
oY = oBorder.RangeBox.MinPoint.Y + oOffset
oPlacePoint = ThisApplication.TransientGeometry.CreatePoint2d(oX,oY)
Else
' There is no border
oPlacementPoint = ThisApplication.TransientGeometry.CreatePoint2d(20, 20)
iLogicVb.UpdateWhenDone = True
End If
' Get the style.
Dim oStyle As Style
For Each aStyle As Style In oDrawDoc.StylesManager.PartsListStyles
If aStyle.Name = sStyle Then
oStyle = aStyle
Exit For
End If
Next
Dim oPartslist As PartsList
Try
'look for the first parts list found on the sheet
'if succesful finding it,
'tell the user,then Do Nothing
oPartslist = oSheet.PartsLists(1)
Catch
' Create the parts list.
oPartslist = oSheet.PartsLists.Add(oDrawingView, oPlacePoint)
End Try
'set the style
oPartslist.Style = oStyle

I'd like insert BOM automatically before save.

I paste BOM in drw with part:

 

2018-01-26_16h11_41.png

 

and with insert assy other BOM:

 

2018-01-26_16h13_28.png

Message 18 of 19

Hi,

I use This code:

 

iLogicVb.UpdateWhenDone = True
Dim bStyle As Boolean
'bStyle = InputRadioBox("Select one:", "Part", "Assy", True, "iLogic")
Dim sStye As String
''set the parts list style names to use
'If bStyle = True Then

doc = ThisDoc.ModelDocument
If doc.DocumentType = kPartDocumentObject Then
sStyle = "AWG Part"
Else
sStyle = "AWG Assy"
End If
' 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
Try
oDrawingView = oSheet.DrawingViews(1)
Catch
MessageBox.Show("No View found. Can not continue", "iLogic")
Return
End Try
' Set a reference to th sheet's border
Dim oBorder As Border
oBorder = oSheet.Border
Dim oPlacePoint As Point2d
If Not oBorder Is Nothing Then
' A border exists. The placement point
' is the top-right corner of the border.
oOffset = 4.97 'user defined offset
oX = oBorder.RangeBox.MaxPoint.X
oY = oBorder.RangeBox.MinPoint.Y + oOffset
oPlacePoint = ThisApplication.TransientGeometry.CreatePoint2d(oX,oY)
Else
' There is no border
oPlacementPoint = ThisApplication.TransientGeometry.CreatePoint2d(20, 20)
iLogicVb.UpdateWhenDone = True
End If
' Get the style.
Dim oStyle As Style
For Each aStyle As Style In oDrawDoc.StylesManager.PartsListStyles
If aStyle.Name = sStyle Then
oStyle = aStyle
Exit For
End If
Next
Dim oPartslist As PartsList
Try
'look for the first parts list found on the sheet
'if succesful finding it,
'tell the user,then Do Nothing
oPartslist = oSheet.PartsLists(1)
Catch
' Create the parts list.
oPartslist = oSheet.PartsLists.Add(oDrawingView, oPlacePoint)
End Try
'set the style
oPartslist.Style = oStyle

I'd like insert BOM automatically before save.

I paste BOM in drw with part:

 

2018-01-26_16h11_41.png

 

and with insert assy other BOM:

 

2018-01-26_16h13_28.png

Message 19 of 19

Hello.

Can i actually generate a filtered partslist by Design View Representation using Ilogic?

 

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

Post to forums  

Autodesk Design & Make Report