Ilogic Copy and Paste View 1

Ilogic Copy and Paste View 1

Anonymous
Not applicable
1,451 Views
4 Replies
Message 1 of 5

Ilogic Copy and Paste View 1

Anonymous
Not applicable

Hi,

After various IF statements my code opens a certain file depending on variables with given code below.

CreateObject("Shell.Application").Open("C:\Users\smeric\Desktop\iLogic Inventor\SekilB_ID900_40t80.dwg")

This file opens a certain drawing in which I would like to Copy and Paste "View1" into my main drawing.I've had some trouble trying to write the code on my own. What the code needs to do after the drawing has been opened is:

1.Copy View1

2.Activate Main Drawing Sheet

3.Paste View1 onto main drawing

4. Activate the recently opened drawing.

5.Close the drawing.

 

Thanks in advance 🙂

0 Likes
Accepted solutions (1)
1,452 Views
4 Replies
Replies (4)
Message 2 of 5

JaneFan
Autodesk
Autodesk

Hey @Anonymous , 

 

DrawingView has CopyTo method can be used in your case: 

CopyTo(TargetSheet As Sheet) As DrawingView

 

Like if your source view is View1, target sheet is MainSheet2: 

View2.CopyTo(MainSheet2)

 




Jane Fan
Inventor/Fusion QA Engineer
0 Likes
Message 3 of 5

J-Camper
Advisor
Advisor

The code below should do what you are asking:

Dim mainDWG As DrawingDocument = ThisDoc.Document

Dim templateDWG As DrawingDocument
Dim templatePath As String = "C:\Users\smeric\Desktop\iLogic Inventor\"
Dim templateName As String = "SekilB_ID900_40t80.dwg"

'Open Template drawing
	ThisApplication.Documents.Open(templatePath & templateName, True)
	templateDWG = ThisApplication.ActiveDocument
'Copy View from template drawing
Dim copyView As DrawingView
	copyView = templateDWG.Sheets.Item(1).DrawingViews.Item(1) 'replace with desired view on desired sheet
	'MessageBox.Show(copyView.Name, "Drawing View Selection")
	templateDWG.SelectSet.Clear
	templateDWG.SelectSet.Select(copyView)
Dim oCopyControlDef As ControlDefinition
    oCopyControlDef = ThisApplication.CommandManager.ControlDefinitions.Item("AppCopyCmd")
    oCopyControlDef.Execute	
'Paste View in main drawing
	mainDWG.Activate
	mainDWG.Sheets.Item(1).Activate
Dim oPasteControlDef As ControlDefinition
    oPasteControlDef = ThisApplication.CommandManager.ControlDefinitions.Item("AppPasteCmd")
    oPasteControlDef.Execute
'Close Template drawing
	templateDWG.Close(True)'True to skip save on template drawing
'Save Main drawing
	mainDWG.Save
0 Likes
Message 4 of 5

J-Camper
Advisor
Advisor
Accepted solution

I didn't see @JaneFan's relpy at first, that is another way to do it with less code too:

 

Dim mainDWG As DrawingDocument = ThisDoc.Document

Dim templateDWG As DrawingDocument
Dim templatePath As String = "C:\Users\smeric\Desktop\iLogic Inventor\"
Dim templateName As String = "SekilB_ID900_40t80.dwg" 'Open Template drawing ThisApplication.Documents.Open(templatePath & templateName, True) templateDWG = ThisApplication.ActiveDocument 'Copy View from template drawing to Main drawing Dim copyView As DrawingView copyView = templateDWG.Sheets.Item(1).DrawingViews.Item(1) 'MessageBox.Show(copyView.Name, "Drawing View Selection") copyView.CopyTo(mainDWG.Sheets.Item(1)) 'Close Template drawing templateDWG.Close(True)'Skip save on template drawing 'Save Main drawing mainDWG.Save

 

 

Message 5 of 5

Anonymous
Not applicable

@J-Camper @JaneFan  Thank you both for replying I appreciate it.

The code seems to be exactly what I want to do and works perfectly, thanks for the assistance 🙂

0 Likes