Hi All,
When placing a base view, I would like to have the part list inmediatly placed on the top right border. I have different parts list styles. One for assemblies, and one for individual parts. Is there a way to also incorporate this in the Ilogic rule?
Thanks
Solved! Go to Solution.
Hi All,
When placing a base view, I would like to have the part list inmediatly placed on the top right border. I have different parts list styles. One for assemblies, and one for individual parts. Is there a way to also incorporate this in the Ilogic rule?
Thanks
Solved! Go to Solution.
Solved by waynehelley. Go to Solution.
Solved by waynehelley. Go to Solution.
Sorry that its a bit messy but here is some logic I wrote a long time ago for placing a Parts List. I'm not quite sure how you would go about getting the logic to automatically trigger when you place a drawing view.
Dim oDrawingDoc As DrawingDocument oDrawingDoc = ThisApplication.ActiveDocument Dim oSheet As Sheet oSheet = oDrawingDoc.ActiveSheet 'Detect if the template has a parts list Try Dim oPartslistCheck As PartsList oPartslistCheck = oSheet.PartsLists(1) partslistpresent=True Catch partslistpresent=False End Try If partslistpresent=True 'Delete the current parts list Dim oPartsList As PartsList oPartsList = oDrawingDoc.ActiveSheet.PartsLists.Item(1) oPartsList.Delete End If ' 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 the sheet's border Dim oBorder As Border oBorder = oSheet.Border Dim oPlacementPoint As Point2d xrev = oBorder.RangeBox.MaxPoint.X yrev = oBorder.RangeBox.MaxPoint.Y oPlacementPoint = ThisApplication.TransientGeometry.CreatePoint2d(xrev, yrev) ' Create the parts list. Dim oPartsList1 As PartsList oPartsList1 = oSheet.PartsLists.Add(oDrawingView, oPlacementPoint) oPartsLis1t = oDrawingDoc.ActiveSheet.PartsLists.Item(1) oPartsList1.Sort("PART NUMBER") oPartsList1.Renumber oPartsList1.Style.UpdateFromGlobal
'Switch style back and forth to ensure style is up-to-date oPartsList1.Style = oDrawingDoc.StylesManager.PartsListStyles.Item("Parts List (ANSI)") oPartsList1.Style = oDrawingDoc.StylesManager.PartsListStyles.Item("Parts List (ISO)") InventorVb.DocumentUpdate()
Sorry that its a bit messy but here is some logic I wrote a long time ago for placing a Parts List. I'm not quite sure how you would go about getting the logic to automatically trigger when you place a drawing view.
Dim oDrawingDoc As DrawingDocument oDrawingDoc = ThisApplication.ActiveDocument Dim oSheet As Sheet oSheet = oDrawingDoc.ActiveSheet 'Detect if the template has a parts list Try Dim oPartslistCheck As PartsList oPartslistCheck = oSheet.PartsLists(1) partslistpresent=True Catch partslistpresent=False End Try If partslistpresent=True 'Delete the current parts list Dim oPartsList As PartsList oPartsList = oDrawingDoc.ActiveSheet.PartsLists.Item(1) oPartsList.Delete End If ' 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 the sheet's border Dim oBorder As Border oBorder = oSheet.Border Dim oPlacementPoint As Point2d xrev = oBorder.RangeBox.MaxPoint.X yrev = oBorder.RangeBox.MaxPoint.Y oPlacementPoint = ThisApplication.TransientGeometry.CreatePoint2d(xrev, yrev) ' Create the parts list. Dim oPartsList1 As PartsList oPartsList1 = oSheet.PartsLists.Add(oDrawingView, oPlacementPoint) oPartsLis1t = oDrawingDoc.ActiveSheet.PartsLists.Item(1) oPartsList1.Sort("PART NUMBER") oPartsList1.Renumber oPartsList1.Style.UpdateFromGlobal
'Switch style back and forth to ensure style is up-to-date oPartsList1.Style = oDrawingDoc.StylesManager.PartsListStyles.Item("Parts List (ANSI)") oPartsList1.Style = oDrawingDoc.StylesManager.PartsListStyles.Item("Parts List (ISO)") InventorVb.DocumentUpdate()
Thank you for this code. Placing the parts list works well. But regardless if it is an .iam or .ipt, it still places the parts list with the same style. Can you help me with that last part
Thank you for this code. Placing the parts list works well. But regardless if it is an .iam or .ipt, it still places the parts list with the same style. Can you help me with that last part
Using something like this should work.
Dim oRefDocType As DocumentTypeEnum
oRefDocType = oDrawingView.ReferencedDocumentDescriptor.ReferencedDocumentType
Select Case oRefDocType
Case DocumentTypeEnum.kPartDocumentObject
MsgBox("This is a part")
Case DocumentTypeEnum.kAssemblyDocumentObject
MsgBox("This is an assembly")
End Select
Using something like this should work.
Dim oRefDocType As DocumentTypeEnum
oRefDocType = oDrawingView.ReferencedDocumentDescriptor.ReferencedDocumentType
Select Case oRefDocType
Case DocumentTypeEnum.kPartDocumentObject
MsgBox("This is a part")
Case DocumentTypeEnum.kAssemblyDocumentObject
MsgBox("This is an assembly")
End Select
Thanks!!!
Any idea's why this wouldn't work with Inventor 2018?
It fails on this line
oPartsList1 = oSheet.PartsLists.Add(oDrawingView, oPlacementPoint)
Any idea's why this wouldn't work with Inventor 2018?
It fails on this line
oPartsList1 = oSheet.PartsLists.Add(oDrawingView, oPlacementPoint)
@Anonymous
There could be a lot of reasons, which I addressed in the other thread. But a more wordy reasoning of why it might not work:
1. The variable you are trying to assign it to is not the proper type for what the function returns - or the function may not even be a function, and may have no return value, in which case it also wouldn't work. If you were to have oPartsList1 typed as anything but a parts list somewhere else in the code, it wouldn't work.
2. You are not providing a proper "parent" for the function call. If oSheet is not in fact a Sheet, it would not work.
3. The parameters you are trying to pass the method call are not proper. You need to look up the documentation in the API regarding this as it is different for every method, and there are often exceptions that are documented there ****** THIS IS VERY OFTEN THE CASE****
4. You could have things spelled wrong.
5. There could be invisible characters on the line
6. Syntax could be wrong depending if you are using VB or VBA
7. It could just be an invalid method/operation - which kind of goes back to Item 2. If the oSheet belongs to a drawing document that already has a different type of partslist placed somewhere, it could also fail.
8. The things you are doing are not possible through the UI for valid reasons... Sometimes you can do extra things through API that you can't through UI, but the default assumption should be that if you can't do the steps through the UI without error, then you probably can't do it through the API without error.
@Anonymous
There could be a lot of reasons, which I addressed in the other thread. But a more wordy reasoning of why it might not work:
1. The variable you are trying to assign it to is not the proper type for what the function returns - or the function may not even be a function, and may have no return value, in which case it also wouldn't work. If you were to have oPartsList1 typed as anything but a parts list somewhere else in the code, it wouldn't work.
2. You are not providing a proper "parent" for the function call. If oSheet is not in fact a Sheet, it would not work.
3. The parameters you are trying to pass the method call are not proper. You need to look up the documentation in the API regarding this as it is different for every method, and there are often exceptions that are documented there ****** THIS IS VERY OFTEN THE CASE****
4. You could have things spelled wrong.
5. There could be invisible characters on the line
6. Syntax could be wrong depending if you are using VB or VBA
7. It could just be an invalid method/operation - which kind of goes back to Item 2. If the oSheet belongs to a drawing document that already has a different type of partslist placed somewhere, it could also fail.
8. The things you are doing are not possible through the UI for valid reasons... Sometimes you can do extra things through API that you can't through UI, but the default assumption should be that if you can't do the steps through the UI without error, then you probably can't do it through the API without error.
HI,
My name is Milan.
I am new to API and codes, recently tried this code for BOM placing in inventor but didnot work for me.
Can anyone guide me how to exactly run this code.
Regads,
Milan Kantaria
HI,
My name is Milan.
I am new to API and codes, recently tried this code for BOM placing in inventor but didnot work for me.
Can anyone guide me how to exactly run this code.
Regads,
Milan Kantaria
@milan5 Google is the most powerful tool of the 21st century, and if you use proper keywords, you can usually find answers to your questions.
For Example, if I google "Autodesk Inventor + iLogic + how to use rule"
the first link that pops up is quite valuable. As is the 2nd link, and so on and so forth.
There are also tutorials done by Autodesk on the topic.
However, noted below is also pretty much the exact same steps that
Step 1: Identify if code is VB or VBA:
- There are no variable assignment lines that begin with "set", so we can guess this is likely vb.net - which is used in the rule environment.
Step 2: Enable the iLogic browser.
- In the ribbon bar: Tools > Addins. Ensure iLogic is set to load automatically, and is loaded.
- Also in the ribbon bar (while you have a document open:): View > User Interface. Ensure iLogic Browser is checked
Step 3:
- Copy the code from the forums.
Step 4:
- In the iLogic Browser, go to the external rules tab.
- Right click the "Standard Directories"
- Click "Create New External Rule"
- Establish the file name
- Paste the copied code from the forums into the rule editor window that pops up.
- Click Save
- Close the rule dialog
Step 5:
- Right click the rule name in the iLogic browser
- Click "Run Rule"
@milan5 Google is the most powerful tool of the 21st century, and if you use proper keywords, you can usually find answers to your questions.
For Example, if I google "Autodesk Inventor + iLogic + how to use rule"
the first link that pops up is quite valuable. As is the 2nd link, and so on and so forth.
There are also tutorials done by Autodesk on the topic.
However, noted below is also pretty much the exact same steps that
Step 1: Identify if code is VB or VBA:
- There are no variable assignment lines that begin with "set", so we can guess this is likely vb.net - which is used in the rule environment.
Step 2: Enable the iLogic browser.
- In the ribbon bar: Tools > Addins. Ensure iLogic is set to load automatically, and is loaded.
- Also in the ribbon bar (while you have a document open:): View > User Interface. Ensure iLogic Browser is checked
Step 3:
- Copy the code from the forums.
Step 4:
- In the iLogic Browser, go to the external rules tab.
- Right click the "Standard Directories"
- Click "Create New External Rule"
- Establish the file name
- Paste the copied code from the forums into the rule editor window that pops up.
- Click Save
- Close the rule dialog
Step 5:
- Right click the rule name in the iLogic browser
- Click "Run Rule"
I know this is an old thread but I was reading through and saw that the question regarding the error on the "PartsLists.Add()" line may not have gotten an answer. If you're doing this in VBA you'll need to put a "Set" keyword in front of that line. It should look something like this:
Set oPartsList1 = oSheet.PartsLists.Add(oDrawingView, oPlacementPoint)
I know this is an old thread but I was reading through and saw that the question regarding the error on the "PartsLists.Add()" line may not have gotten an answer. If you're doing this in VBA you'll need to put a "Set" keyword in front of that line. It should look something like this:
Set oPartsList1 = oSheet.PartsLists.Add(oDrawingView, oPlacementPoint)
Try this code instead of the short one.
oPartsList1 = oSheet.PartsLists.Add(oDrawingView, oPlacementPoint, PartsListLevelEnum.kStructuredAllLevels)
It works in my case. You need to add "PartsListLevelEnum. ...." .
Try this code instead of the short one.
oPartsList1 = oSheet.PartsLists.Add(oDrawingView, oPlacementPoint, PartsListLevelEnum.kStructuredAllLevels)
It works in my case. You need to add "PartsListLevelEnum. ...." .
@waynehelley , What i have to do to move partlist to top left corner.
Thank
@waynehelley , What i have to do to move partlist to top left corner.
Thank
Hi,
I think you would just need to replace 'MaxPoint' with 'MinPoint' for the x-axis.
Hi,
I think you would just need to replace 'MaxPoint' with 'MinPoint' for the x-axis.
@waynehelley , i already repalced but the position seems still wrong like this
I think we need to calculate partlists frame size then + with it, but when i replaced this
xrev = oBorder.RangeBox.MinPoint.X
by this one
xrev = oBorder.RangeBox.MinPoint.X + (oPartsList.RangeBox.MaxPoint.X - oPartsList.RangeBox.MinPoint.X)
then run rule it said
Error on Line 37 : 'oPartsList' is not declared. It may be inaccessible due to its protection level.
here is my code
Dim oDrawingDoc As DrawingDocument
oDrawingDoc = ThisApplication.ActiveDocument
Dim oSheet As Sheet
oSheet = oDrawingDoc.ActiveSheet
'Detect if the template has a parts list
Try
Dim oPartslistCheck As PartsList
oPartslistCheck = oSheet.PartsLists(1)
partslistpresent=True
Catch
partslistpresent=False
End Try
If partslistpresent=True
'Delete the current parts list
Dim oPartsList As PartsList
oPartsList = oDrawingDoc.ActiveSheet.PartsLists.Item(1)
oPartsList.Delete
End If
' 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 the sheet's border
Dim oBorder As Border
oBorder = oSheet.Border
Dim oPlacementPoint As Point2d
xrev = oBorder.RangeBox.MinPoint.X + (oPartsList.RangeBox.MaxPoint.X - oPartsList.RangeBox.MinPoint.X)
yrev = oBorder.RangeBox.MaxPoint.Y
oPlacementPoint = ThisApplication.TransientGeometry.CreatePoint2d(xrev, yrev)
' Create the parts list.
Dim oPartsList1 As PartsList
oPartsList1 = oSheet.PartsLists.Add(oDrawingView, oPlacementPoint)
oPartsLis1t = oDrawingDoc.ActiveSheet.PartsLists.Item(1)
oPartsList1.Sort("PART NUMBER")
oPartsList1.Renumber
oPartsList1.Style.UpdateFromGlobal
'Switch style back and forth to ensure style is up-to-date
oPartsList1.Style = oDrawingDoc.StylesManager.PartsListStyles.Item("Parts List (ANSI)")
oPartsList1.Style = oDrawingDoc.StylesManager.PartsListStyles.Item("Parts List (ISO)")
InventorVb.DocumentUpdate()
@waynehelley , i already repalced but the position seems still wrong like this
I think we need to calculate partlists frame size then + with it, but when i replaced this
xrev = oBorder.RangeBox.MinPoint.X
by this one
xrev = oBorder.RangeBox.MinPoint.X + (oPartsList.RangeBox.MaxPoint.X - oPartsList.RangeBox.MinPoint.X)
then run rule it said
Error on Line 37 : 'oPartsList' is not declared. It may be inaccessible due to its protection level.
here is my code
Dim oDrawingDoc As DrawingDocument
oDrawingDoc = ThisApplication.ActiveDocument
Dim oSheet As Sheet
oSheet = oDrawingDoc.ActiveSheet
'Detect if the template has a parts list
Try
Dim oPartslistCheck As PartsList
oPartslistCheck = oSheet.PartsLists(1)
partslistpresent=True
Catch
partslistpresent=False
End Try
If partslistpresent=True
'Delete the current parts list
Dim oPartsList As PartsList
oPartsList = oDrawingDoc.ActiveSheet.PartsLists.Item(1)
oPartsList.Delete
End If
' 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 the sheet's border
Dim oBorder As Border
oBorder = oSheet.Border
Dim oPlacementPoint As Point2d
xrev = oBorder.RangeBox.MinPoint.X + (oPartsList.RangeBox.MaxPoint.X - oPartsList.RangeBox.MinPoint.X)
yrev = oBorder.RangeBox.MaxPoint.Y
oPlacementPoint = ThisApplication.TransientGeometry.CreatePoint2d(xrev, yrev)
' Create the parts list.
Dim oPartsList1 As PartsList
oPartsList1 = oSheet.PartsLists.Add(oDrawingView, oPlacementPoint)
oPartsLis1t = oDrawingDoc.ActiveSheet.PartsLists.Item(1)
oPartsList1.Sort("PART NUMBER")
oPartsList1.Renumber
oPartsList1.Style.UpdateFromGlobal
'Switch style back and forth to ensure style is up-to-date
oPartsList1.Style = oDrawingDoc.StylesManager.PartsListStyles.Item("Parts List (ANSI)")
oPartsList1.Style = oDrawingDoc.StylesManager.PartsListStyles.Item("Parts List (ISO)")
InventorVb.DocumentUpdate()
Thomas Fitzgerald has written some code with the same outcome. The partlist is positioned in the upright corner of the active document.
https://github.com/AlexFielder/iLogic/blob/master/Autodesk/Thomas%20Fitzgerald/Parts%20List.iLogicVb
Thomas Fitzgerald has written some code with the same outcome. The partlist is positioned in the upright corner of the active document.
https://github.com/AlexFielder/iLogic/blob/master/Autodesk/Thomas%20Fitzgerald/Parts%20List.iLogicVb
This is the code I am using now. The list is located on the up left corner of the drawing. If you want it is pretty easy to change the position with use of lines 12 and 13.
Sub Main Dim invDoc As DrawingDocument = ThisApplication.ActiveDocument Dim oSheet As Sheet = invDoc.ActiveSheet Try DeletePartsList(oSheet) Catch End Try Dim oDrawingView As DrawingView = oSheet.DrawingViews(1) Dim oBorder As Border = oSheet.Border Dim oPlacementPoint As Point2d If Not oBorder Is Nothing Then xrev = oBorder.RangeBox.MinPoint.X+"17" yrev = oBorder.RangeBox.MaxPoint.Y oPlacementPoint = ThisApplication.TransientGeometry.CreatePoint2d(xrev, yrev) End If Dim partsListBomType As PartsListLevelEnum = 46593 Dim oPartsList As PartsList = oSheet.PartsLists.Add(oDrawingView, oPlacementPoint, partsListBomType) End Sub Private Sub DeletePartsList(oSheet As Sheet) Dim oPartList As PartsList For Each oPartList In oSheet.PartsLists oPartList.Delete() Next End Sub
This is the code I am using now. The list is located on the up left corner of the drawing. If you want it is pretty easy to change the position with use of lines 12 and 13.
Sub Main Dim invDoc As DrawingDocument = ThisApplication.ActiveDocument Dim oSheet As Sheet = invDoc.ActiveSheet Try DeletePartsList(oSheet) Catch End Try Dim oDrawingView As DrawingView = oSheet.DrawingViews(1) Dim oBorder As Border = oSheet.Border Dim oPlacementPoint As Point2d If Not oBorder Is Nothing Then xrev = oBorder.RangeBox.MinPoint.X+"17" yrev = oBorder.RangeBox.MaxPoint.Y oPlacementPoint = ThisApplication.TransientGeometry.CreatePoint2d(xrev, yrev) End If Dim partsListBomType As PartsListLevelEnum = 46593 Dim oPartsList As PartsList = oSheet.PartsLists.Add(oDrawingView, oPlacementPoint, partsListBomType) End Sub Private Sub DeletePartsList(oSheet As Sheet) Dim oPartList As PartsList For Each oPartList In oSheet.PartsLists oPartList.Delete() Next End Sub
@MichaëlStienstrathis Ilogic rule worked well for me, however I want to change the style as I have 3 different part list but can i identify the correct PartsListLevelEnum = ?????
thank you
as you can see in the picture, the ilogic rule add the parts list (iso) template, but I want to add the Cut list (ISO) templete for all drawing that are frames
@MichaëlStienstrathis Ilogic rule worked well for me, however I want to change the style as I have 3 different part list but can i identify the correct PartsListLevelEnum = ?????
thank you
as you can see in the picture, the ilogic rule add the parts list (iso) template, but I want to add the Cut list (ISO) templete for all drawing that are frames
Can't find what you're looking for? Ask the community or share your knowledge.