If I have a blank drawing file, can I paste a view in from another drawing file?
I would like to keep all the dimensions. I can do this in the UI with a simple copy paste, can this be done in iLogic?
Solved! Go to Solution.
Solved by Curtis_Waguespack. Go to Solution.
Solved by Curtis_Waguespack. Go to Solution.
Here is just a very small portion of my code that revolves around copying views.
Call oOpenLugDrawing(oLugCollection, oLugDoc)
'Establish variables to hold the two specific lug collection items for the time being
Dim oPage4ViewA As DrawingView = Nothing
Dim oPage4ViewB As DrawingView = Nothing
Dim IncorrectTriesIndex As Integer = 0
Call SetLugCollectionItems(LugIndexA, LugIndexB, IncorrectTriesIndex) 'selects correct views from selection based on index
MessageBox.Show(oLugCollection.Item(LugIndexA).name & " " & oLugCollection.item(LugIndexB).name)
oPage4ViewA = oLugCollection.Item(LugIndexA).Copyto(oPage4)
oPage4ViewB = oLugCollection.Item(LugIndexB).Copyto(oPage4)
Sub oOpenLugDrawing(ByRef oLugCollection As ObjectCollection, ByRef oLugDoc As DrawingDocument)
Dim oTG As TransientGeometry = ThisApplication.TransientGeometry
Dim oTO As TransientObjects = ThisApplication.TransientObjects
Dim LugTemplateDWG As DrawingDocument
Dim LugTemplatePath As String = "FILE PATH NAME"
Dim LugTemplateName As String = "FILE ITEM NAME"
Dim LugIndex As Integer = 1
Dim oSourceDrawing As DrawingView
oLugCollection = oTO.CreateObjectCollection
oLugDoc = ThisApplication.Documents.Open(LugTemplatePath & LugTemplateName)
LugTemplateDWG = ThisApplication.ActiveDocument
Dim oSheet As Sheet = oLugDoc.Sheets.Item(1)
For Each oSourceDrawing In oSheet.DrawingViews
oLugCollection.Add(oSourceDrawing)
LugIndex = LugIndex + 1
Next
End Sub
A couple of things to note, depending on the object that holds the view itself you may run into issues. If an item you wish to copy from one sheet to another is a base view you'll have no problems. However if your view/ multiple views are a parent child relationship you run into a limitation. It seems that people have solved this by using select set and Command manager to copy views as if you ctr+c and ctr+v. I have not found that to work on my end.
If you need to work with a child view, I found you can do the DrawingView.MoveTo method from within the drawing document itself. Currently I have an entire temporary page that holds section views to be moved based upon a selection, then the page is deleted. A work around that may help you, not sure the exact situation.
Adding to the previous replies, here are some examples.
I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com
Copy a view to a new drawing
Dim Sheet_1 = ThisDrawing.Sheets.ItemByName("Sheet:1") Dim VIEW1 = Sheet_1.DrawingViews.ItemByName("VIEW1") 'create new drawing Dim Drawing2 As DrawingDocument = ThisApplication.Documents.Add(DocumentTypeEnum.kDrawingDocumentObject) VIEW1.View.CopyTo(Drawing2.Sheets.Item(1))
Copy view to existing open drawing ( assumes it is the 2nd drawing open)
Dim Sheet_1 = ThisDrawing.Sheets.ItemByName("Sheet:1") Dim VIEW1 = Sheet_1.DrawingViews.ItemByName("VIEW1") 'get other drawing ( second drawing in the open/visible drawing collection) Dim Drawing2 As DrawingDocument = ThisApplication.Documents.VisibleDocuments.Item(2) VIEW1.View.CopyTo(Drawing2.Sheets.Item(1)) Drawing2.Activate
same as above, but get target drawing by name
Dim Sheet_1 = ThisDrawing.Sheets.ItemByName("Sheet:1") Dim VIEW1 = Sheet_1.DrawingViews.ItemByName("VIEW1") 'get other drawing by name Dim Drawing2 As DrawingDocument = ThisApplication.Documents.ItemByName("C:\Temp\Drawing55.idw") VIEW1.View.CopyTo(Drawing2.Sheets.Item(1)) Drawing2.Activate
Copy sheet ( all views on sheet) to new drawing
'get sheet from active drawing Dim Sheet_1 = ThisDrawing.Sheets.ItemByName("Sheet:1") 'create new drawing Dim Drawing2 As DrawingDocument = ThisApplication.Documents.Add(DocumentTypeEnum.kDrawingDocumentObject) 'copy sheet from active drawing to new drawing Sheet_1.Sheet.CopyTo(Drawing2) 'delete blank sheet that is created from template Drawing2.Sheets.Item(1).Delete
Copy sheet ( all views on sheet) to new drawing using a specific template
'get sheet from active drawing Dim Sheet_1 = ThisDrawing.Sheets.ItemByName("Sheet:1") 'create new drawing Dim Drawing2 As DrawingDocument Drawing2 = ThisApplication.Documents.Add(DocumentTypeEnum.kDrawingDocumentObject, "C:\Templates\Standard.idw") 'copy sheet from active drawing to new drawing Sheet_1.Sheet.CopyTo(Drawing2) 'delete blank sheet that is created from template Drawing2.Sheets.Item(1).Delete
Copy sheet ( all views on sheet) then remove some of the views
'get sheet from active drawing Dim Sheet_1 = ThisDrawing.Sheets.ItemByName("Sheet:1") 'create new drawing Dim Drawing2 As DrawingDocument = ThisApplication.Documents.Add(DocumentTypeEnum.kDrawingDocumentObject) 'copy sheet from active drawing to new drawing Sheet_1.Sheet.CopyTo(Drawing2) 'get new sheet Dim NewSheet As Sheet = Drawing2.Sheets.Item(2) 'delete some unneeded views NewSheet.DrawingViews.Item(2).Delete NewSheet.DrawingViews.Item(3).Delete 'delete blank sheet that is created from template Drawing2.Sheets.Item(1).Delete
hi@Curtis_Waguespack ,could these copy a sectionview or other view which isnot base view to another sheet or another drawingdocument?
Hi @Stakin
I think we are limited to copying child views such as section views only if we copy the parent views also.
So I typically use something like the example that copies the entire sheet and then just delete any views that I don't need. Leaving the section view and it's parent.
If I don't want to see the parent I will suppress it, as shown below.
Copying the sheet just provides a straight forward way to copy the parent and the child views, when that is needed. If no dependent child/parent views are involved, I tend to just copy the views as needed ( not the entire sheet).
'get sheet from active drawing Dim Sheet_1 = ThisDrawing.Sheets.ItemByName("Sheet:1") 'create new drawing Dim Drawing2 As DrawingDocument = ThisApplication.Documents.Add(DocumentTypeEnum.kDrawingDocumentObject) 'copy sheet from active drawing to new drawing Sheet_1.Sheet.CopyTo(Drawing2) 'get new sheet Dim NewSheet As Sheet = Drawing2.Sheets.Item(2) 'delete some unneeded views NewSheet.DrawingViews.Item(2).Delete 'suppress parent view NewSheet.DrawingViews.Item(1).Suppressed = True 'delete blank sheet that is created from template Drawing2.Sheets.Item(1).Delete
original drawing
new drawing
@Curtis_Waguespack ,That is a good way to bypass this restriction,learnt,thank you。
Thank you Curtis,
All very useful code and your second reply about copying of child views accidently solved the next problem I ran into.
Harvey
Can't find what you're looking for? Ask the community or share your knowledge.