I'm working on some iLogic to copy a view from one drawing to a new drawing then place a parts list from that view. Once the parts list is place to copy it back to the source drawing. Currently I have 3 different iLogic codes.
So I'm looking for some help on how to combine these. I would like to have the last code call back the source drawing to copy the parts list to but I'm having some difficulty figuring that out. I'm not sure if I need to do subs or move this to VBA. Any help would be appreciated.
''Copy View to new drawing
Dim oSrcDwg As DrawingDocument
oSrcDwg = ThisApplication.ActiveDocument
oBaseSheet = oSrcDwg.Sheets(1)
Dim oDestDwg As DrawingDocument
''File Location to be Decided
oDestDwg = ThisApplication.Documents.Open("C:\CA Workspace\CAD Standards\Templates\English\BOM DRAWING.idw")
Dim oView As DrawingView
'Check to see if drawing is on the cover page.
Try
oView = oBaseSheet.DrawingViews(1)
Catch
MessageBox.Show("There is no view on the cover page", "Place a view", MessageBoxButtons.OK, MessageBoxIcon.Error)
Return
End Try
If oSrcDwg.ActiveSheet.DrawingViews.Count < 1 Then
MsgBox("No views found in the source drawing!")
Return
End If
oModelDoc = oBaseSheet.DrawingViews(1)
Dim oSheet As Sheet
For Each oSheet In oDestDwg.Sheets
oSheet.Activate
Call oView.CopyTo(oSheet)
Exit For
Next
'Used to save destination file
'Call oDestDwg.Save
'Used to close destination file
'Call oDestDwg.Close(True)
''Places Parts in drawing from view placed
Dim oDestDwg As DrawingDocument = ThisApplication.ActiveDocument
oSheet = oDestDwg.Sheets(1)
Dim oBOM As BOM
Dim oView As DrawingView
Dim oPartsLists As PartsLists
Dim oPartsList As PartsList
'Try to get the first view on the sheet
Try
oView = oSheet.DrawingViews(1)
Catch
MessageBox.Show("There is no view on the cover page","Place a view", MessageBoxButtons.OK, MessageBoxIcon.Error)
Return
End Try
'get the model that the view is looking at
oModelDoc =ThisDrawing.Sheet(“COVER:1”).View(oView.Name).ModelDocument
'get the BOM database
oBOM = oModelDoc.ComponentDefinition.BOM
' Make sure the BOM view is enabled
oBOM.PartsOnlyViewEnabled = True
'get the PartsLists collection
oPartsLists = oSheet.PartsLists
'clean up existing parts lists
For Each oPartsList In oPartsLists
oPartsList.Delete
Next
'Setting BOM position
Dim BomPlacementPoint As Point2d
Dim oBorder As Border = oSheet.Border
''Location of bom on border
BomPlacementPoint = ThisApplication.TransientGeometry.CreatePoint2d (oBorder.RangeBox.MaxPoint.X-20, oBorder.RangeBox.MaxPoint.Y-.95)
'Create new partsList
oPartsList = oPartsLists.Add(oView, BomPlacementPoint, PartsListLevelEnum.kPartsOnly)
'Changes parts list to new style.
oPartsList.Style = oDestDwg.StylesManager.PartsListStyles.Item("BOM (Purchasing)")
''Sort Parts List
Dim oPartsList1 As PartsList
oPartsList1 = oDestDwg.ActiveSheet.PartsLists.Item(1)
oPartsList1.Sort2("VENDOR",1,"STOCK NUMBER",1,"SIZE",1,AutoSortOnUpdate,True)
oPartsList1.Renumber
oPartsList1.SaveItemOverridesToBOM
'PartsList copy to destination folder
Dim oSrcDwg As DrawingDocument
oSrcDwg = ThisApplication.ActiveDocument
oBaseSheet = oSrcDwg.Sheets(1)
Dim oDestDwg As DrawingDocument
oDestDwg = ThisApplication.Documents.Open("C:\CA Workspace\CAD Standards\Templates\English\BOM DRAWING.idw")
Dim oPartsList As PartsList
'Checks to see if there is a parts list.
Try
oPartsList = oBaseSheet.PartsLists.Item(1)
Catch
MessageBox.Show("There is no parts list on the cover page", "Place a parts list", MessageBoxButtons.OK, MessageBoxIcon.Error)
Return
End Try
oModelDoc = oBaseSheet.PartsLists.Item(1)
'Moves parts list to oDestDwg
Dim oSheet As Sheet
For Each oSheet In oDestDwg.Sheets
oSheet.Activate
Call oPartsList.CopyTo(oSheet)
Exit For
Next
Solved! Go to Solution.
I'm working on some iLogic to copy a view from one drawing to a new drawing then place a parts list from that view. Once the parts list is place to copy it back to the source drawing. Currently I have 3 different iLogic codes.
So I'm looking for some help on how to combine these. I would like to have the last code call back the source drawing to copy the parts list to but I'm having some difficulty figuring that out. I'm not sure if I need to do subs or move this to VBA. Any help would be appreciated.
''Copy View to new drawing
Dim oSrcDwg As DrawingDocument
oSrcDwg = ThisApplication.ActiveDocument
oBaseSheet = oSrcDwg.Sheets(1)
Dim oDestDwg As DrawingDocument
''File Location to be Decided
oDestDwg = ThisApplication.Documents.Open("C:\CA Workspace\CAD Standards\Templates\English\BOM DRAWING.idw")
Dim oView As DrawingView
'Check to see if drawing is on the cover page.
Try
oView = oBaseSheet.DrawingViews(1)
Catch
MessageBox.Show("There is no view on the cover page", "Place a view", MessageBoxButtons.OK, MessageBoxIcon.Error)
Return
End Try
If oSrcDwg.ActiveSheet.DrawingViews.Count < 1 Then
MsgBox("No views found in the source drawing!")
Return
End If
oModelDoc = oBaseSheet.DrawingViews(1)
Dim oSheet As Sheet
For Each oSheet In oDestDwg.Sheets
oSheet.Activate
Call oView.CopyTo(oSheet)
Exit For
Next
'Used to save destination file
'Call oDestDwg.Save
'Used to close destination file
'Call oDestDwg.Close(True)
''Places Parts in drawing from view placed
Dim oDestDwg As DrawingDocument = ThisApplication.ActiveDocument
oSheet = oDestDwg.Sheets(1)
Dim oBOM As BOM
Dim oView As DrawingView
Dim oPartsLists As PartsLists
Dim oPartsList As PartsList
'Try to get the first view on the sheet
Try
oView = oSheet.DrawingViews(1)
Catch
MessageBox.Show("There is no view on the cover page","Place a view", MessageBoxButtons.OK, MessageBoxIcon.Error)
Return
End Try
'get the model that the view is looking at
oModelDoc =ThisDrawing.Sheet(“COVER:1”).View(oView.Name).ModelDocument
'get the BOM database
oBOM = oModelDoc.ComponentDefinition.BOM
' Make sure the BOM view is enabled
oBOM.PartsOnlyViewEnabled = True
'get the PartsLists collection
oPartsLists = oSheet.PartsLists
'clean up existing parts lists
For Each oPartsList In oPartsLists
oPartsList.Delete
Next
'Setting BOM position
Dim BomPlacementPoint As Point2d
Dim oBorder As Border = oSheet.Border
''Location of bom on border
BomPlacementPoint = ThisApplication.TransientGeometry.CreatePoint2d (oBorder.RangeBox.MaxPoint.X-20, oBorder.RangeBox.MaxPoint.Y-.95)
'Create new partsList
oPartsList = oPartsLists.Add(oView, BomPlacementPoint, PartsListLevelEnum.kPartsOnly)
'Changes parts list to new style.
oPartsList.Style = oDestDwg.StylesManager.PartsListStyles.Item("BOM (Purchasing)")
''Sort Parts List
Dim oPartsList1 As PartsList
oPartsList1 = oDestDwg.ActiveSheet.PartsLists.Item(1)
oPartsList1.Sort2("VENDOR",1,"STOCK NUMBER",1,"SIZE",1,AutoSortOnUpdate,True)
oPartsList1.Renumber
oPartsList1.SaveItemOverridesToBOM
'PartsList copy to destination folder
Dim oSrcDwg As DrawingDocument
oSrcDwg = ThisApplication.ActiveDocument
oBaseSheet = oSrcDwg.Sheets(1)
Dim oDestDwg As DrawingDocument
oDestDwg = ThisApplication.Documents.Open("C:\CA Workspace\CAD Standards\Templates\English\BOM DRAWING.idw")
Dim oPartsList As PartsList
'Checks to see if there is a parts list.
Try
oPartsList = oBaseSheet.PartsLists.Item(1)
Catch
MessageBox.Show("There is no parts list on the cover page", "Place a parts list", MessageBoxButtons.OK, MessageBoxIcon.Error)
Return
End Try
oModelDoc = oBaseSheet.PartsLists.Item(1)
'Moves parts list to oDestDwg
Dim oSheet As Sheet
For Each oSheet In oDestDwg.Sheets
oSheet.Activate
Call oPartsList.CopyTo(oSheet)
Exit For
Next
Solved! Go to Solution.
Solved by A.Acheson. Go to Solution.
Solved by Cadkunde.nl. Go to Solution.
The first question would be do you want to keep this all as separate rules or to create one rule with individual subs? Just looking at what you have it is only a matter of passing each drawing document in as a variable and launch the next sub routine at the end of each or combine them where possible the operations happening on the same document.
The first question would be do you want to keep this all as separate rules or to create one rule with individual subs? Just looking at what you have it is only a matter of passing each drawing document in as a variable and launch the next sub routine at the end of each or combine them where possible the operations happening on the same document.
I would like to have them in the same rule. Each rule would have to run once the rule before it finishes.
I would like to have them in the same rule. Each rule would have to run once the rule before it finishes.
I think you want something like this:
Class iRule Public test As String = "This variable works in every sub" Sub Main() Rule1() Rule2() Rule3() End Sub Sub Rule1() 'Copy paste content of your first rule here End Sub Sub Rule2() 'Copy paste content of your second rule here End Sub Sub Rule3() 'Copy paste content of your third rule here End Sub End Class
I think you want something like this:
Class iRule Public test As String = "This variable works in every sub" Sub Main() Rule1() Rule2() Rule3() End Sub Sub Rule1() 'Copy paste content of your first rule here End Sub Sub Rule2() 'Copy paste content of your second rule here End Sub Sub Rule3() 'Copy paste content of your third rule here End Sub End Class
This AU Course can help understand some of the differences between functions, subs, classes. See Tips #4-6. There is a video to go along with the documentation.
This AU Course can help understand some of the differences between functions, subs, classes. See Tips #4-6. There is a video to go along with the documentation.
Thank you @Cadkunde.nl and @tyler.warner this is getting me in the right directions. Right now I just trying to get the first 2 rules to work together and keep getting an error on line 65 that no view with the name "View9" was found but there is a view shown on the new sheet. I feel like I'm missing something.
Class iRule
'Public test As String = "This variable works in every sub"
Public oSrcDWG As DrawingDocument
Public oDestDwg As DrawingDocument
Public oView As DrawingView
Public oSheet As Sheet
Sub Main()
oSrcDWG = ThisApplication.ActiveDocument
''File Location to be Decided
oDestDwg = ThisApplication.Documents.Open("C:\CA Workspace\CAD Standards\Templates\English\BOM DRAWING.idw")
Rule1()
Rule2()
'Rule3()
End Sub
Sub Rule1()
''Copy View to new drawing
oBaseSheet = oSrcDWG.Sheets(1)
'Check to see if drawing is on the cover page.
Try
oView = oBaseSheet.DrawingViews(1)
Catch
MessageBox.Show("There is no view on the cover page", "Place a view", MessageBoxButtons.OK, MessageBoxIcon.Error)
Return
End Try
If oSrcDwg.ActiveSheet.DrawingViews.Count < 1 Then
MsgBox("No views found in the source drawing!")
Return
End If
oModelDoc = oBaseSheet.DrawingViews(1)
'Dim oSheet As Sheet
For Each oSheet In oDestDwg.Sheets
oSheet.Activate
Call oView.CopyTo(oSheet)
Exit For
Next
End Sub
Sub Rule2()
''Places Parts in drawing from view placed
'Dim oDestDwg As DrawingDocument = ThisApplication.ActiveDocument
oSheet = oDestDwg.Sheets(1)
Dim oBOM As BOM
'Dim oView As DrawingView
Dim oPartsLists As PartsLists
Dim oPartsList As PartsList
'Try to get the first view on the sheet
Try
oView = oSheet.DrawingViews(1)
Catch
MessageBox.Show("There is no view on the cover page", "Place a view", MessageBoxButtons.OK, MessageBoxIcon.Error)
Return
End Try
'get the model that the view is looking at
oModelDoc = ThisDrawing.Sheet(“COVER:1”).View(oView.Name).ModelDocument
'get the BOM database
oBOM = oModelDoc.ComponentDefinition.BOM
' Make sure the BOM view is enabled
oBOM.PartsOnlyViewEnabled = True
'get the PartsLists collection
oPartsLists = oSheet.PartsLists
'clean up existing parts lists
For Each oPartsList In oPartsLists
oPartsList.Delete
Next
'Setting BOM position
Dim BomPlacementPoint As Point2d
Dim oBorder As Border = oSheet.Border
''Location of bom on border
BomPlacementPoint = ThisApplication.TransientGeometry.CreatePoint2d(oBorder.RangeBox.MaxPoint.X - 20, oBorder.RangeBox.MaxPoint.Y - .95)
'Create new partsList
oPartsList = oPartsLists.Add(oView, BomPlacementPoint, PartsListLevelEnum.kPartsOnly)
'Changes parts list to new style.
oPartsList.Style = oDestDwg.StylesManager.PartsListStyles.Item("BOM (Purchasing)")
''Sort Parts List
Dim oPartsList1 As PartsList
oPartsList1 = oDestDwg.ActiveSheet.PartsLists.Item(1)
oPartsList1.Sort2("VENDOR", 1, "STOCK NUMBER", 1, "SIZE", 1, AutoSortOnUpdate, True)
oPartsList1.Renumber
oPartsList1.SaveItemOverridesToBOM
End Sub
' Sub Rule3()
' 'PartsList copy to destination folder
' Dim oSrcDwg As DrawingDocument
' oSrcDwg = ThisApplication.ActiveDocument
' oBaseSheet = oSrcDwg.Sheets(1)
' Dim oDestDwg As DrawingDocument
' oDestDwg = ThisApplication.Documents.Open("C:\CA Workspace\CAD Standards\Templates\English\BOM DRAWING.idw")
' Dim oPartsList As PartsList
' 'Checks to see if there is a parts list.
' Try
' oPartsList = oBaseSheet.PartsLists.Item(1)
' Catch
' MessageBox.Show("There is no parts list on the cover page", "Place a parts list", MessageBoxButtons.OK, MessageBoxIcon.Error)
' Return
' End Try
' oModelDoc = oBaseSheet.PartsLists.Item(1)
' 'Moves parts list to oDestDwg
' Dim oSheet As Sheet
' For Each oSheet In oDestDwg.Sheets
' oSheet.Activate
' Call oPartsList.CopyTo(oSheet)
' Exit For
' Next
' End Sub
End Class
Thank you @Cadkunde.nl and @tyler.warner this is getting me in the right directions. Right now I just trying to get the first 2 rules to work together and keep getting an error on line 65 that no view with the name "View9" was found but there is a view shown on the new sheet. I feel like I'm missing something.
Class iRule
'Public test As String = "This variable works in every sub"
Public oSrcDWG As DrawingDocument
Public oDestDwg As DrawingDocument
Public oView As DrawingView
Public oSheet As Sheet
Sub Main()
oSrcDWG = ThisApplication.ActiveDocument
''File Location to be Decided
oDestDwg = ThisApplication.Documents.Open("C:\CA Workspace\CAD Standards\Templates\English\BOM DRAWING.idw")
Rule1()
Rule2()
'Rule3()
End Sub
Sub Rule1()
''Copy View to new drawing
oBaseSheet = oSrcDWG.Sheets(1)
'Check to see if drawing is on the cover page.
Try
oView = oBaseSheet.DrawingViews(1)
Catch
MessageBox.Show("There is no view on the cover page", "Place a view", MessageBoxButtons.OK, MessageBoxIcon.Error)
Return
End Try
If oSrcDwg.ActiveSheet.DrawingViews.Count < 1 Then
MsgBox("No views found in the source drawing!")
Return
End If
oModelDoc = oBaseSheet.DrawingViews(1)
'Dim oSheet As Sheet
For Each oSheet In oDestDwg.Sheets
oSheet.Activate
Call oView.CopyTo(oSheet)
Exit For
Next
End Sub
Sub Rule2()
''Places Parts in drawing from view placed
'Dim oDestDwg As DrawingDocument = ThisApplication.ActiveDocument
oSheet = oDestDwg.Sheets(1)
Dim oBOM As BOM
'Dim oView As DrawingView
Dim oPartsLists As PartsLists
Dim oPartsList As PartsList
'Try to get the first view on the sheet
Try
oView = oSheet.DrawingViews(1)
Catch
MessageBox.Show("There is no view on the cover page", "Place a view", MessageBoxButtons.OK, MessageBoxIcon.Error)
Return
End Try
'get the model that the view is looking at
oModelDoc = ThisDrawing.Sheet(“COVER:1”).View(oView.Name).ModelDocument
'get the BOM database
oBOM = oModelDoc.ComponentDefinition.BOM
' Make sure the BOM view is enabled
oBOM.PartsOnlyViewEnabled = True
'get the PartsLists collection
oPartsLists = oSheet.PartsLists
'clean up existing parts lists
For Each oPartsList In oPartsLists
oPartsList.Delete
Next
'Setting BOM position
Dim BomPlacementPoint As Point2d
Dim oBorder As Border = oSheet.Border
''Location of bom on border
BomPlacementPoint = ThisApplication.TransientGeometry.CreatePoint2d(oBorder.RangeBox.MaxPoint.X - 20, oBorder.RangeBox.MaxPoint.Y - .95)
'Create new partsList
oPartsList = oPartsLists.Add(oView, BomPlacementPoint, PartsListLevelEnum.kPartsOnly)
'Changes parts list to new style.
oPartsList.Style = oDestDwg.StylesManager.PartsListStyles.Item("BOM (Purchasing)")
''Sort Parts List
Dim oPartsList1 As PartsList
oPartsList1 = oDestDwg.ActiveSheet.PartsLists.Item(1)
oPartsList1.Sort2("VENDOR", 1, "STOCK NUMBER", 1, "SIZE", 1, AutoSortOnUpdate, True)
oPartsList1.Renumber
oPartsList1.SaveItemOverridesToBOM
End Sub
' Sub Rule3()
' 'PartsList copy to destination folder
' Dim oSrcDwg As DrawingDocument
' oSrcDwg = ThisApplication.ActiveDocument
' oBaseSheet = oSrcDwg.Sheets(1)
' Dim oDestDwg As DrawingDocument
' oDestDwg = ThisApplication.Documents.Open("C:\CA Workspace\CAD Standards\Templates\English\BOM DRAWING.idw")
' Dim oPartsList As PartsList
' 'Checks to see if there is a parts list.
' Try
' oPartsList = oBaseSheet.PartsLists.Item(1)
' Catch
' MessageBox.Show("There is no parts list on the cover page", "Place a parts list", MessageBoxButtons.OK, MessageBoxIcon.Error)
' Return
' End Try
' oModelDoc = oBaseSheet.PartsLists.Item(1)
' 'Moves parts list to oDestDwg
' Dim oSheet As Sheet
' For Each oSheet In oDestDwg.Sheets
' oSheet.Activate
' Call oPartsList.CopyTo(oSheet)
' Exit For
' Next
' End Sub
End Class
You will need to remove the reference to ilogic model Document. If you look at object reference of this it will be for the the document you originally launched the rule from and not the document your currently in which should be the temporary drawing. Use the API method instead. You may have to "activate" the drawing document/ sheet as well.
Dim assyDocName As String = oView.ReferencedDocumentDescriptor.FullDocumentName 'open assembly doc invisibly Dim oModelDoc As AssemblyDocument = ThisApplication.Documents.Open(assyDocName, False)
You will need to remove the reference to ilogic model Document. If you look at object reference of this it will be for the the document you originally launched the rule from and not the document your currently in which should be the temporary drawing. Use the API method instead. You may have to "activate" the drawing document/ sheet as well.
Dim assyDocName As String = oView.ReferencedDocumentDescriptor.FullDocumentName 'open assembly doc invisibly Dim oModelDoc As AssemblyDocument = ThisApplication.Documents.Open(assyDocName, False)
@A.Acheson That did the trick. It is now working correctly just need to add a few checks so no one runs it if there already is a parts only parts list. Thank you for the help!
@A.Acheson That did the trick. It is now working correctly just need to add a few checks so no one runs it if there already is a parts only parts list. Thank you for the help!
Can't find what you're looking for? Ask the community or share your knowledge.