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")
Solved! Go to Solution.
Solved by Curtis_Waguespack. Go to Solution.
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
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
@Anonymous 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 ).
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
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
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
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
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
It works with loaded PARTmodel, but if I have an ASSEMBLY I get this error:
INV 2018.2.3, Build 227
please HELP me
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)
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:
and with insert assy other BOM:
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:
and with insert assy other BOM: