Message 1 of 8
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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.
- One code that can copy the view to a new sheet from a template.
- One code that can place a parts list that is then sorted.
- One code that can copy the parts list to another drawing.
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.