Copy and Paste Drawing Sheet Example (C#)
This example shows how to copy and paste drawing sheets.
//-----------------------------------------------------------------------------
// Preconditions:
// 1. Open a drawing document.
// 2. Open an Immediate Window.
// 3. Rename the namespace of this macro to match the name of your C#
project.
//
// Postconditions:
// Sheet1 is copied and pasted to three locations in the drawing document.
//------------------------------------
using
SolidWorks.Interop.sldworks;
using
SolidWorks.Interop.swconst;
using
System;
using
System.Diagnostics;
namespace
PasteSheet_CSharp.csproj
{
partial
class
SolidWorksMacro
{
DrawingDoc
Part;
ModelDoc2
swModel;
bool
boolstatus;
public
void Main()
{
swModel = (ModelDoc2)swApp.ActiveDoc;
Part = (DrawingDoc)swModel;
if
((Part == null))
{
Debug.Print("
Please Open Drawing Document ");
}
else
{
Sheet
currentsheet = default(Sheet);
currentsheet = (Sheet)Part.GetCurrentSheet();
swModel.EditCopy();
boolstatus = swModel.Extension.SelectByID2("Sheet1",
"SHEET",
0, 0, 0, false,
0, null,
0);
boolstatus = Part.PasteSheet((int)swInsertOptions_e.swInsertOption_BeforeSelectedSheet,
(int)swRenameOptions_e.swRenameOption_Yes);
Part.ActivateSheet(currentsheet.GetName());
boolstatus = Part.PasteSheet((int)swInsertOptions_e.swInsertOption_AfterSelectedSheet,
(int)swRenameOptions_e.swRenameOption_No);
Part.ActivateSheet(currentsheet.GetName());
boolstatus = Part.PasteSheet((int)swInsertOptions_e.swInsertOption_MoveToEnd,
(int)swRenameOptions_e.swRenameOption_Yes);
}
}
public
SldWorks
swApp;
}
}