IDrawingDoc Interface 学习笔记
Solidworks學習筆記-鏈接Solidworks
在此基礎上
允許訪問執行繪圖操作的函數。
屬性
| Name | Description | 備注 | 
| ActiveDrawingView | Gets the currently active drawing view. ? | 獲取當前活動的圖紙視圖。 | 
| AutomaticViewUpdate | Gets or sets whether the drawing views in this drawing are automatically updated if the underlying model in that drawing view changes. ? | 獲取或設置該工程圖中的工程視圖是否在該工程視圖中的基礎模型發生更改時自動更新。 | 
| BackgroundProcessingOption | Gets or sets the background processing option for this drawing. ? | 獲取或設置此繪圖的后臺處理選項。 | 
| HiddenViewsVisible | Shows or hides all of the hidden drawing views. ? | 顯示或隱藏所有隱藏的圖紙視圖。 | 
| IActiveDrawingView | Gets the currently active drawing view. ? | 獲取當前活動的圖紙視圖。 | 
| Sheet | Gets the specified sheet. ? | 獲取指定的工作表。 | 
System.int BackgroundProcessingOption {get; set;}
This example shows how to fire notifications when background processing events occur.//---------------------------------------------------------------------------- // Preconditions: // 1. Create a VSTA C# macro. // a. Copy and paste SolidWorksMacro.cs code in the macro. // b. Create a form, Form1, that contains the following // controls: // * CheckBox1 with caption Enable background processing and open // drawing. // * button1 with caption Close after background processing end event // fires". // c. Copy and paste Form1.cs code in your form's code window. // d. Modify the path in Form1.cs to open a huge drawing document that // contains many parts. // 2. Press F5 to start and close the debugger. // 3. Click Build > Build macro_name to build a DLL for the macro. // 4. Save and close the macro. // // Postconditions: // 1. Open the Windows Task manager, click the Processes tab, and click the CPU column // header to sort the processes in descending order. // 2. In SOLIDWORKS, click Tools > Macro > Run. // a. Locate your macro's \SwMacro\bin\Debug folder. // b. Select macro_name.dll. // c. Click Open to open the form. // 3. Select the Enable background processing and open drawing checkbox on the form. // 4. Displays a checkmark in the check box. // 5. Click OK to close the Background processing enabled message box. // 6. Opens the specified drawing. // 7. Fires the background processing start events. // 8. Click OK to close the Background processing start event fired message box. // 9. In the Windows Task Manager, observe that several sldbgproc.exe processes are // occupying most of the CPU. // 10. Click OK to close the Background processing stop event fired message box. // 11. Click Close after background processing end event fired button on the form. // 12. Unloads Form1. //----------------------------------------------------------------------------------//SolidWorksMacro.csusing SolidWorks.Interop.sldworks; using System.Runtime.InteropServices; using System; using System.Windows.Forms;namespace BackgroundProcessingEventsCSharp.csproj {public partial class SolidWorksMacro{public SldWorks swApp;public void Main(){//Create and show an instance of the formForm1 myForm = new Form1();myForm.Show();}} }//Form1using SolidWorks.Interop.sldworks; using SolidWorks.Interop.swconst; using System.Windows.Forms; using System.Diagnostics; using System.Collections; using System.Runtime.InteropServices; using System; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text;namespace BackgroundProcessingEventsCSharp.csproj {public partial class Form1 : Form{public Form1(){InitializeComponent();}public SldWorks swApp;public bool checkBoxClicked;private void checkBox1_CheckedChanged(object sender, EventArgs e){try{swApp = (SldWorks)System.Runtime.InteropServices.Marshal.GetActiveObject("SldWorks.Application");}catch (Exception ex){MessageBox.Show(ex.Message);return;}ModelDoc2 swModelDoc = default(ModelDoc2);DrawingDoc swDrawingDoc = default(DrawingDoc);string filePath = null;filePath = "path_and_filename_of_huge_drawing";DocumentSpecification docSpecification = default(DocumentSpecification);// Set up eventsAttachEventHandlers();// Enable background processingswApp.EnableBackgroundProcessing = true;MessageBox.Show("Background processing enabled");// Open huge drawingdocSpecification = (DocumentSpecification)swApp.GetOpenDocSpec(filePath);docSpecification.Silent = true;swModelDoc = (ModelDoc2)swApp.OpenDoc7(docSpecification);swDrawingDoc = (DrawingDoc)swModelDoc;// Set document background processing to application settingswDrawingDoc.BackgroundProcessingOption = (int)swBackgroundProcessOption_e.swBackgroundProcessing_DeferToApplication;}public void AttachEventHandlers(){AttachSWEvents();}public void AttachSWEvents(){swApp.BackgroundProcessingStartNotify += this.mySwApp_BackgroundProcessingStartNotify;swApp.BackgroundProcessingEndNotify += this.mySwApp_BackgroundProcessingEndNotify;}private int mySwApp_BackgroundProcessingStartNotify(string filename){MessageBox.Show("Background processing start event fired");return 1;}private int mySwApp_BackgroundProcessingEndNotify(string filename){MessageBox.Show("Background processing end event fired");swApp.EnableBackgroundProcessing = false;return 1;}public void CheckBox1_Click(object sender, System.EventArgs e){checkBoxClicked = true;}private void button1_Click(object sender, EventArgs e){this.Close();}} }Sheet Sheet( System.string Name) {get;}
This example shows how to get each sheet in a multi-sheet drawing document regardless whether the sheet is loaded.//---------------------------------------------------------------------- // Preconditions: // 1. Click File > Open. // 2. Open public_documents\samples\tutorial\advdrawings\foodprocessor.sldrw. // 3. Click Select sheets to open > Selected > Sheet1* (load) > OK >Open. // 4. Open the Immediate window. // // Postconditions: // 1. Loads Sheet1 only. // 2. Mouse over Sheet2, Sheet3, and Sheet4 tabs and examine the // Immediate window. // // NOTE: Because this drawing is used elsewhere, do not save changes. //--------------------------------------------------------------------- using SolidWorks.Interop.sldworks; using SolidWorks.Interop.swconst; using System; using System.Diagnostics;namespace SheetDrawingDocCSharp.csproj {partial class SolidWorksMacro{public void Main(){ModelDoc2 swModel = default(ModelDoc2);DrawingDoc swDraw = default(DrawingDoc);string[] vSheetName = null;int i = 0;bool bRet = false;string sheetName; swModel = (ModelDoc2)swApp.ActiveDoc;swDraw = (DrawingDoc)swModel; // Get the sheets in the drawing document vSheetName = (string[])swDraw.GetSheetNames();// Traverse the sheets and determine whether // they're loaded for (i = 0; i < vSheetName.Length; i++){sheetName = (string)vSheetName[i];bRet = swDraw.ActivateSheet(sheetName);Sheet swSheet = default(Sheet);swSheet = (Sheet)swDraw.get_Sheet(vSheetName[i]);if ((swSheet.IsLoaded())){Debug.Print(vSheetName[i] + " is loaded.");}else{Debug.Print(vSheetName[i] + " is not loaded.");}}}/// <summary> /// The SldWorks swApp variable is pre-assigned for you. /// </summary> public SldWorks swApp;} }方法
| Name | Description | 備注 | 
| ActivateSheet | Activates the specified drawing sheet. ? | 激活指定的圖紙。 | 
| ActivateView | Activates the specified drawing view. ? | 激活指定的圖紙視圖。 | 
| AddChamferDim | Adds a chamfer dimension. ? | 添加倒角尺寸。 | 
| AddHoleCallout2 | Adds a?hole callout at the specified position to the hole whose edge is selected. ? | 將指定位置的孔標注添加到其邊緣被選中的孔中。 | 
| AddLineStyle | Adds a line style to the current drawing. ? | 向當前圖形添加線型。 | 
| AlignHorz | Uses the selected edge to align the current drawing view. ? | 使用選定邊對齊當前工程視圖。 | 
| AlignOrdinate | Aligns the ordinate dimension. ? | 對齊縱坐標尺寸。 | 
| AlignVert | Uses the selected edge to align the current drawing view. ? | 使用選定邊對齊當前工程視圖。 | 
| AttachAnnotation | Attaches an existing annotation to a drawing sheet or view. ? | 將現有注釋附加到工程圖圖紙或視圖。 | 
| AttachDimensions | Attaches unattached dimensions. ? | 附加未附加的尺寸。 | 
| AutoBalloon5 | Automatically inserts BOM balloons in selected drawing views. ? | 在選定的工程視圖中自動插入 BOM 球標。 | 
| AutoDimension | Automatically dimensions the selected drawing view. ? | 自動標注選定的工程視圖。 | 
| BreakView | Breaks the drawing view along the existing break lines. ? | 沿現有斷開線斷開工程視圖。 | 
| ChangeComponentLayer | Puts the selected components on the specified layer. ? | 將選定的組件放在指定的層上。 | 
| ChangeOrdDir | Changes the ordinate direction. ? | 改變縱坐標方向。 | 
| ChangeRefConfigurationOfFlatPatternView | Changes the referenced configuration of the flat-pattern view. ? | 更改平面模式視圖的參考配置。 | 
| Create1stAngleViews2 | Creates standard three orthographic views (first angle projection) for the specified model. ? | 為指定模型創建標準的三個正交視圖(第一角度投影)。 | 
| Create3rdAngleViews2 | Creates standard three orthographic views (third angle projection) for the specified model. ? | 為指定模型創建標準的三個正交視圖(第三角度投影)。 | 
| CreateAngDim4 | Creates a non-associative angular dimension. ? | 創建非關聯角度尺寸。 | 
| CreateAutoBalloonOptions | Creates an object that stores auto balloon options. ? | 創建一個存儲自動氣球選項的對象。 | 
| CreateAuxiliaryViewAt2 | Creates an auxiliary view based on a selected edge in a drawing view. ? | 基于工程視圖中的選定邊創建輔助視圖。 | 
| CreateBreakOutSection | Creates a broken-out section in a drawing document. ? | 在工程圖文檔中創建斷開的部分。 | 
| CreateConstructionGeometry | Sets?the selected sketch segments to?be construction geometry instead of sketch geometry. ? | 將選定的草圖段設置為構造幾何體而不是草圖幾何體。 | 
| CreateDetailViewAt4 | Creates a detail view in a drawing document. ? | 在工程圖文檔中創建局部視圖。 | 
| CreateDiamDim4 | Creates a non-associative diameter dimension. ? | 創建非關聯直徑尺寸。 | 
| CreateDrawViewFromModelView3 | Creates a drawing view on the current drawing sheet using the specified model view. ? | 使用指定的模型視圖在當前工程圖紙上創建工程視圖。 | 
| CreateFlatPatternViewFromModelView3 | Creates a flat-pattern view from a model view. ? | 從模型視圖創建平面圖案視圖。 | 
| CreateLayer2 | Creates a layer for this document. ? | 為此文檔創建一個圖層。 | 
| CreateLinearDim4 | Creates a non-associative linear dimension. ? | 創建非關聯線性標注。 | 
| CreateOrdinateDim4 | Creates a non-associative ordinate dimension. ? | 創建非關聯的縱坐標標注。 | 
| CreateRelativeView | Creates a relative drawing?view. ? | 創建相對繪圖視圖。 | 
| CreateSectionView | Creates a section view in the drawing using the selected section line. ? | 使用選定的剖面線在工程圖中創建剖面視圖。 | 
| CreateSectionViewAt5 | Creates the specified section view. ? | 創建指定的剖面視圖。 | 
| CreateText2 | Creates a?note?containing the specified text at a given location. ? | 在給定位置創建包含指定文本的注釋。 | 
| CreateUnfoldedViewAt3 | Creates an unfolded drawing view from the selected drawing view and places it in the drawing at the specified location. ? | 從選定的圖紙視圖創建展開的圖紙視圖,并將其放置在圖紙中的指定位置。 | 
| CreateViewport3 | Creates a an empty view in a drawing. ? | 在工程圖中創建一個空視圖。 | 
| DeleteAllCosmeticThreads | Deletes all cosmetic threads, which do not have callouts,?in a drawing of an assembly only. ? | 僅在裝配體的工程圖中刪除所有沒有標注的裝飾螺紋。 | 
| DeleteLineStyle | Deletes the specified line style from the current drawing. ? | 從當前圖形中刪除指定的線型。 | 
| Dimensions | Adds dimensions to the drawing from model. ? | 從模型向工程圖中添加尺寸。 | 
| DragModelDimension | Copies or moves dimensions to a different drawing view. ? | 將尺寸復制或移動到不同的工程視圖。 | 
| DrawingViewRotate | Rotates the selected drawing view. ? | 旋轉選定的工程視圖。 | 
| DropDrawingViewFromPalette2 | Moves the specified drawing view from the View Palette to the current drawing sheet. ? | 將指定的工程視圖從視圖調色板移動到當前工程圖紙。 | 
| EditCenterMarkProperties | Edits center mark properties. ? | 編輯中心標記屬性。 | 
| EditOrdinate | Edits an ordinate dimension. ? | 編輯縱坐標尺寸。 | 
| EditSelectedGtol | Gets the?selected GTol to edit. ? | 獲取要編輯的選定 GTol。 | 
| EditSheet | Puts the current drawing sheet in edit mode. ? | 將當前圖紙置于編輯模式。 | 
| EditSketch | Allows editing of?a sketch?in?the selected drawing view or sheet. ? | 允許在選定的圖紙視圖或圖紙中編輯草圖。 | 
| EditTemplate | Puts the template of the current drawing sheet in edit mode. ? | 將當前圖紙的模板置于編輯模式。 | 
| EndDrawing | Provides faster creation of entities in a drawing when used with?IDrawingDoc::StartDrawing. ? | 與 IDrawingDoc::StartDrawing 一起使用時,可以更快地在繪圖中創建實體。 | 
| FeatureByName | Gets?the specified feature in the drawing. ? | 獲取繪圖中的指定特征。 | 
| FlipSectionLine | Flips the cut direction of the selected section line. ? | 翻轉選定剖面線的切割方向。 | 
| GenerateViewPaletteViews | Adds the specified document's predefined drawing views to the View Palette. ? | 將指定文檔的預定義工程視圖添加到視圖調色板。 | 
| GetCurrentSheet | Gets the currently active drawing sheet. ? | 獲取當前活動的圖紙。 | 
| GetDrawingPaletteViewNames | Gets the names of drawing views in the View Palette for the active drawing sheet. ? | 獲取活動圖紙的視圖調色板中圖紙視圖的名稱。 | 
| GetEditSheet | Gets whether the current drawing is in edit sheet mode or edit template mode. ? | 獲取當前圖形是處于編輯圖紙模式還是編輯模板模式。 | 
| GetFirstView | Gets the first drawing?view?on the current sheet. ? | 獲取當前圖紙上的第一個繪圖視圖。 | 
| GetInsertionPoint | Gets the current insertion (pick) point in a drawing. ? | 獲取繪圖中的當前插入(拾取)點。 | 
| GetLineFontCount2 | Gets the a number line fonts supported by this drawing. ? | 獲取此繪圖支持的數字線字體。 | 
| GetLineFontId | Gets the associated line font ID. ? | 獲取關聯的行字體 ID。 | 
| GetLineFontInfo2 | Gets the detailed information about the specified line font. ? | 獲取指定線條字體的詳細信息。 | 
| GetLineFontName2 | Gets the name of the specified line font. ? | 獲取指定線條字體的名稱。 | 
| GetLineStyles | Gets all of the line styles used in the current document. ? | 獲取當前文檔中使用的所有線條樣式。 | 
| GetPenCount | Gets the number of pens currently defined in SOLIDWORKS. ? | 獲取當前在 SOLIDWORKS 中定義的筆數。 | 
| GetPenInfo | Gets information about the pens used in SOLIDWORKS. ? | 獲取有關 SOLIDWORKS 中使用的筆的信息。 | 
| GetSheetCount | Gets the number of drawing sheets in this drawing. ? | 獲取此繪圖中的繪圖頁數。 | 
| GetSheetNames | Gets a list of the names of the drawing sheets in this drawing. ? | 獲取此圖紙中圖紙名稱的列表。 | 
| GetViewCount | Gets all of the number of all of?views, including the number of?sheets, in this drawing document. ? | 獲取此繪圖文檔中所有視圖的所有數量,包括圖紙數量。 | 
| GetViews | Gets the all of the views, including the?sheets, in this drawing document. ? | 獲取此繪圖文檔中的所有視圖,包括圖紙。 | 
| HideEdge | Hides selected visible edges in a drawing document. ? | 在工程圖文檔中隱藏選定的可見邊。 | 
| HideShowDimensions | Sets whether to display?suppressed dimensions as dimmed and hide them. ? | 設置是否將抑制的尺寸顯示為灰色并隱藏它們。 | 
| HideShowDrawingViews | Sets whether to hide or show hidden drawing views. ? | 設置是隱藏還是顯示隱藏的工程視圖。 | 
| IAddChamferDim | Adds a chamfer dimension. ? | 添加倒角尺寸。 | 
| IAddHoleCallout2 | Adds a?hole callout at the specified position to the hole whose edge is selected. ? | 將指定位置的孔標注添加到其邊緣被選中的孔中。 | 
| ICreateAngDim4 | Creates a non-associative angular dimension. ? | 創建非關聯角度尺寸。 | 
| ICreateAuxiliaryViewAt2 | Creates an auxiliary view based on a selected edge in a drawing view. ? | 基于工程視圖中的選定邊創建輔助視圖。 | 
| ICreateDiamDim4 | Creates a non-associative diameter dimension. ? | 創建非關聯直徑尺寸。 | 
| ICreateLinearDim4 | Creates a non-associative linear dimension. ? | 創建非關聯線性標注。 | 
| ICreateOrdinateDim4 | Creates a non-associative ordinate dimension. ? | 創建非關聯的縱坐標標注。 | 
| ICreateSectionViewAt5 | Creates a section view from the section line?up to the specified distance at the specified distance. ? | 在指定距離處創建從剖面線到指定距離的剖面視圖。 | 
| ICreateText2 | Creates a?note?containing the specified text at a given location. ? | 在給定位置創建包含指定文本的注釋。 | 
| IEditSelectedGtol | Gets the?selected GTol to edit. ? | 獲取要編輯的選定 GTol。 | 
| IFeatureByName | Gets?the specified feature in the drawing. ? | 獲取繪圖中的指定特征。 | 
| IGetCurrentSheet | Gets the currently active drawing sheet. ? | 獲取當前活動的圖紙。 | 
| IGetFirstView | Gets the first drawing?view?on the current sheet. ? | 獲取當前圖紙上的第一個繪圖視圖。 | 
| IGetInsertionPoint | Gets the current insertion (pick) point in a drawing. ? | 獲取繪圖中的當前插入(拾取)點。 | 
| IGetPenInfo | Gets information about the pens used in SOLIDWORKS. ? | 獲取有關 SOLIDWORKS 中使用的筆的信息。 | 
| IGetSheetNames | Gets a list of the names of the drawing sheets in this drawing. ? | 獲取此圖紙中圖紙名稱的列表。 | 
| IInsertDowelSymbol | Inserts a dowel pin symbol on the currently selected edge or edges. ? | 在當前選定的一條或多條邊上插入定位銷符號。 | 
| IInsertMultiJogLeader3 | Inserts a multi-jog leader. ? | 插入多轉折引線。 | 
| IInsertRevisionCloud | Inserts a revision cloud annotation with the specified shape into a view or sheet. ? | 將具有指定形狀的修訂云線注釋插入到視圖或圖紙中。 | 
| INewGtol | Creates a new GTol. ? | 創建一個新的幾何公差。 | 
| InsertAngularRunningDim | Inserts an angular running dimension into this drawing. ? | 在此工程圖中插入角度運行尺寸。 | 
| InsertBaseDim | Inserts the base model dimensions into this drawing. ? | 將基礎模型尺寸插入此工程圖中。 | 
| InsertBreakHorizontal | Inserts a horizontal break in the drawing view. ? | 在工程視圖中插入水平中斷。 | 
| InsertBreakVertical | Inserts a vertical break in this drawing. ? | 在此圖形中插入垂直中斷。 | 
| InsertCenterLine2 | Inserts a centerline on the selected entities. ? | 在選定實體上插入中心線。 | 
| InsertCenterMark3 | Inserts a center mark in a drawing document. ? | 在工程圖文檔中插入中心標記。 | 
| InsertCircularNotePattern | Inserts a circular note pattern using the selected?note. ? | 使用所選筆記插入圓形筆記模式。 | 
| InsertDowelSymbol | Inserts a dowel pin symbol on the currently selected edge or edges in this drawing. ? | 在此圖形中當前選定的一條或多條邊上插入定位銷符號。 | 
| InsertGroup | Inserts the currently selected items into a group (or view). ? | 將當前選定的項目插入到一個組(或視圖)中。 | 
| InsertHorizontalOrdinate | Inserts a horizontal ordinate dimension into this drawing. ? | 在此圖形中插入水平坐標尺寸。 | 
| InsertLinearNotePattern | Inserts a linear note pattern using the selected?note. ? | 使用選定的音符插入線性音符模式。 | 
| InsertModelAnnotations3 | Inserts model annotations into this drawing document in the currently selected drawing view. ? | 在當前選定的工程圖視圖中將模型注釋插入到此工程圖文檔中。 | 
| InsertModelDimensions | Inserts model dimensions into the selected drawing view according to the option specified. ? | 根據指定的選項將模型尺寸插入選定的工程視圖中。 | 
| InsertModelInPredefinedView | Inserts the model into the predefined drawing views in the active drawing sheet. ? | 將模型插入到活動圖紙中的預定義圖紙視圖中。 | 
| InsertMultiJogLeader3 | Inserts a multi-jog leader. ? | 插入多轉折引線。 | 
| InsertNewNote2 | Creates a new note in this drawing. ? | 在此繪圖中創建一個新注釋。 | 
| InsertOrdinate | Inserts an ordinate dimension into this drawing. ? | 在此工程圖中插入縱坐標尺寸。 | 
| InsertRefDim | Inserts reference dimensions in this drawing. ? | 在此工程圖中插入參考尺寸。 | 
| InsertRevisionCloud | Inserts a revision cloud annotation with the specified shape into a view or sheet. ? | 將具有指定形狀的修訂云線注釋插入到視圖或圖紙中。 | 
| InsertRevisionSymbol | Inserts a revision symbol note in this drawing. ? | 在此工程圖中插入修訂符號注釋。 | 
| InsertTableAnnotation2 | Inserts a table annotation in this drawing. ? | 在此圖形中插入表格注釋。 | 
| InsertThreadCallout | Inserts a thread callout into this drawing. ? | 在此圖形中插入螺紋標注。 | 
| InsertVerticalOrdinate | Inserts a vertical ordinate dimension in this drawing. ? | 在此圖形中插入垂直縱坐標尺寸。 | 
| InsertWeldSymbol | Creates a weld symbol located at the last edge selection. ? | 在最后一個邊選擇處創建一個焊接符號。 | 
| IReorderSheets | Reorders the drawing sheets per their positions in the input array. ? | 根據它們在輸入數組中的位置對圖紙重新排序。 | 
| IsolateChangedDimensions | Isolates changed dimensions. ? | 隔離更改的尺寸。 | 
| LoadLineStyles | Loads the specified line styles into the current drawing. ? | 將指定的線型加載到當前圖形中。 | 
| MakeSectionLine | Makes a section line from a set of connected sketch lines. ? | 從一組連接的草圖線制作剖面線。 | 
| ModifySurfaceFinishSymbol | Modifies the selected surface finish symbol. ? | 修改選定的表面粗糙度符號。 | 
| NewGtol | Creates a new GTol object and returns the pointer to that object. ? | 創建一個新的 GTol 對象并返回指向該對象的指針。 | 
| NewNote | Creates a new note at the selected location. ? | 在選定位置創建新筆記。 | 
| NewSheet4 | Creates a new drawing sheet in this drawing document. ? | 在此工程圖文檔中創建新的工程圖圖紙。 | 
| OnComponentProperties | Displays the?Component Properties?dialog for the selected view. ? | 顯示所選視圖的組件屬性對話框。 | 
| PasteSheet | Copies and pastes a drawing sheet?to the specified location of the drawing document, optionally renaming whenever duplicate names occur. ? | 將工程圖復制并粘貼到工程圖文檔的指定位置,可以在出現重復名稱時選擇重命名。 | 
| ReorderSheets | Reorders the drawing sheets per their positions in the input array. ? | 根據它們在輸入數組中的位置對圖紙重新排序。 | 
| ReplaceViewModel | Replaces the specified instances of a model in the specified drawing views. ? | 替換指定工程視圖中模型的指定實例。 | 
| ResolveOutOfDateLightWeightComponents | Resolves out-of-date lightweight components in the selected drawing view or drawing sheet. ? | 解決選定工程視圖或工程圖紙中過時的輕化零部件。 | 
| RestoreRotation | Restores rotation for the selected drawing view. ? | 恢復選定工程視圖的旋轉。 | 
| SaveLineStyles | Exports to a file the specified line styles in the current drawing. ? | 將當前圖形中指定的線型導出到文件。 | 
| SetCurrentLayer | Sets the current layer used by this document. ? | 設置此文檔使用的當前層。 | 
| SetLineColor | Sets the line color for a selected edge or sketch entity. ? | 設置選定邊線或草圖實體的線條顏色。 | 
| SetLineStyle | Sets the style or font for the line for a selected edge or sketch entity. ? | 為選定邊線或草圖實體設置線條的樣式或字體。 | 
| SetLineWidth | Sets the line thickness for a selected edge or sketch entity to a SOLIDWORKS-supplied weight (width). ? | 將選定邊線或草圖實體的線寬設置為 SOLIDWORKS 提供的粗細(寬度)。 | 
| SetLineWidthCustom | Sets the line thickness to the specified custom width for a selected edge or sketch entity. ? | 將線條粗細設置為選定邊線或草圖實體的指定自定義寬度。 | 
| SetSheetsSelected | Sets the specified drawing sheets whose setups to modify. ? | 設置要修改其設置的指定圖紙。 | 
| SetupSheet6 | Sets up?the specified?drawing sheet. ? | 設置指定的圖紙。 | 
| SheetNext | Moves to the next sheet in the drawing. ? | 移動到工程圖中的下一張圖紙。 | 
| SheetPrevious | Returns to the previous sheet in a drawing. ? | 返回到工程圖中的上一張圖紙。 | 
| ShowEdge | Shows the selected hidden edges in a drawing document. ? | 顯示工程圖文檔中選定的隱藏邊。 | 
| SketchDim | Inserts a sketch dimension in this drawing. ? | 在此工程圖中插入草圖尺寸。 | 
| StartDrawing | Provides faster creation of entities within a drawing. ? | 提供在繪圖中更快地創建實體。 | 
| SuppressView | Hides the selected drawing view. ? | 隱藏選定的工程視圖。 | 
| TranslateDrawing | Translates the entire drawing. ? | 翻譯整個繪圖。 | 
| UnBreakView | Removes a break in the selected drawing view. ? | 刪除選定工程視圖中的中斷。 | 
| UnsuppressView | Hides the selected drawing view. ? | 隱藏選定的工程視圖。 | 
| ViewDisplayHidden | Sets the current display mode?to?Hidden Lines Removed. ? | 將當前顯示模式設置為隱藏線已刪除。 | 
| ViewDisplayHiddengreyed | Sets the current display mode to?Hidden Lines Visible. ? | 將當前顯示模式設置為隱藏線可見。 | 
| ViewDisplayShaded | Sets the current display mode to?Shaded. ? | 將當前顯示模式設置為陰影。 | 
| ViewDisplayWireframe | Sets the current display mode to?Wireframe. ? | 將當前顯示模式設置為線框。 | 
| ViewFullPage | Fits the drawing to the full page. ? | 使繪圖適合整頁。 | 
| ViewHlrQuality | Toggles the?Hidden Lines Removed?mode for the drawing view. ? | 切換繪圖視圖的隱藏線刪除模式。 | 
| ViewModelEdges | Toggles the mode for viewing model edges when in shaded mode. ? | 在著色模式下切換查看模型邊緣的模式。 | 
| ViewTangentEdges | Toggles display of tangent edges in the selected drawing view. ? | 在選定工程視圖中切換相切邊的顯示。 | 
System.bool ActivateSheet( System.string Name)
This example shows how to copy and paste drawing sheets. //---------------------------------------------------------- // Preconditions: // 1. Open a drawing document containing one sheet // named Sheet1. // 2. Open the Immediate window. // // Postconditions: // 1. Activates Sheet1. // 2. Copy and pastes Sheet1 as Sheet1(2) and activates Sheet1(2). // 3. Copy and pastes Sheet1 as Sheet1(3) and activates Sheet1(3). // 4. Examine the FeatureManager design tree and Immediate window. //---------------------------------------------------------- using SolidWorks.Interop.sldworks; using SolidWorks.Interop.swconst; using System.Runtime.InteropServices; using System; using System.Diagnostics;namespace Macro1CSharp.csproj {public partial class SolidWorksMacro{public void Main(){DrawingDoc Part = default(DrawingDoc);ModelDoc2 swModel = default(ModelDoc2);bool boolstatus = false;swModel = (ModelDoc2)swApp.ActiveDoc;Part = (DrawingDoc)swModel;if ((Part == null)){Debug.Print(" Please open a drawing document. ");return;}Sheet currentsheet = default(Sheet);currentsheet = (Sheet)Part.GetCurrentSheet();Part.ActivateSheet(currentsheet.GetName());Debug.Print("Active sheet: " + currentsheet.GetName());boolstatus = swModel.Extension.SelectByID2("Sheet1", "SHEET", 0.09205356547875, 0.10872368523, 0, false, 0, null, 0);swModel.EditCopy();boolstatus = Part.PasteSheet((int)swInsertOptions_e.swInsertOption_BeforeSelectedSheet, (int)swRenameOptions_e.swRenameOption_No);currentsheet = (Sheet)Part.GetCurrentSheet();Part.ActivateSheet(currentsheet.GetName());Debug.Print("Active sheet: " + currentsheet.GetName());boolstatus = swModel.Extension.SelectByID2("Sheet1", "SHEET", 0.09205356547875, 0.10872368523, 0, false, 0, null, 0);swModel.EditCopy();boolstatus = Part.PasteSheet((int)swInsertOptions_e.swInsertOption_AfterSelectedSheet, (int)swRenameOptions_e.swRenameOption_No);currentsheet = (Sheet)Part.GetCurrentSheet();Part.ActivateSheet(currentsheet.GetName());Debug.Print("Active sheet: " + currentsheet.GetName());}/// <summary>/// The SldWorks swApp variable is pre-assigned for you./// </summary>public SldWorks swApp;} } This example shows how to determine which sheets in a drawing are loaded.//---------------------------------------------- // Preconditions: // 1. Click File > Open. // 2. Browse to public_documents\samples\tutorial\advdrawings. // 3. Select foodprocessor.slddrw. // 4. Click Select sheets to open > Selected > Sheet1* (Load) > OK > Open. // 5. Open the Immediate window. // // Postconditions: // 1. Loads Sheet1 only. // 2. Mouse over the Sheet2, Sheet3, and Sheet4 tabs and // examine the Immediate window to verify step 1. // // NOTE: Because this drawing is used elsewhere, do not save // changes. //----------------------------------------------using SolidWorks.Interop.sldworks; using SolidWorks.Interop.swconst; using System; using System.Diagnostics; namespace IsLoadedSheetCSharp.csproj {partial class SolidWorksMacro{public void Main(){ModelDoc2 swModel = default(ModelDoc2);DrawingDoc swDraw = default(DrawingDoc);object[] vSheetName = null;int i = 0;bool bRet = false;string sheetName;swModel = (ModelDoc2)swApp.ActiveDoc;swDraw = (DrawingDoc)swModel;// Get the sheets in the drawing document vSheetName = (object[])swDraw.GetSheetNames(); // Traverse the sheets and determine whether // they're loaded for (i = 0; i < vSheetName.Length; i++){sheetName = (string)vSheetName[i];bRet = swDraw.ActivateSheet(sheetName);Sheet swSheet = default(Sheet);swSheet = (Sheet)swDraw.GetCurrentSheet();if ((swSheet.IsLoaded())){Debug.Print(vSheetName[i] + " is loaded.");}else{Debug.Print(vSheetName[i] + " is not loaded.");}}}/// <summary> /// The SldWorks swApp variable is pre-assigned for you. /// </summary> public SldWorks swApp;} }System.bool ActivateView( System.string ViewName)
This example demonstrates firing Undo pre- and post-notification events in a drawing document.//--------------------------------------------------------------------------- // Preconditions: Open public_documents\samples\tutorial\AutoCAD\7550-021.slddrw. // // Postconditions: // 1. Selects and deletes the note in Drawing View1. // 2. Undoes the deleted note. // 3. Fires pre-notification event indicating that an undo action is about to // occur and fires post-notification event indicating that an undo // action occurred. // 4. Click OK to close each message box. // // NOTE: Because the drawing is used elsewhere, do not save changes. //---------------------------------------------------------------------------using SolidWorks.Interop.sldworks; using SolidWorks.Interop.swconst; using System; using System.Collections; using System.Windows.Forms;namespace UndoPostNotifyDrawingCSharp.csproj { partial class SolidWorksMacro {public DrawingDoc swDrawing;public void Main(){ModelDoc2 swModel = default(ModelDoc2);ModelDocExtension swModelDocExt = default(ModelDocExtension);bool boolstatus = false;Hashtable openDrawing = default(Hashtable);swModel = (ModelDoc2)swApp.ActiveDoc;swModelDocExt = (ModelDocExtension)swModel.Extension; // Event notification swDrawing = (DrawingDoc)swModel;openDrawing = new Hashtable();AttachEventHandlers(); // Activate the drawing view that contains // the note you want to delete boolstatus = swDrawing.ActivateView("Drawing View3");boolstatus = swModelDocExt.SelectByID2("DetailItem77@Drawing View3", "NOTE", 0.3058741216774, 0.1870419466786, 0, false, 0, null, 0); // Delete the selected note swModel.EditDelete(); // Undo deletion of note swModel.EditUndo2(1); // Post-notification is fired // Rebuild the drawing swModel.ForceRebuild3(true);} public void AttachEventHandlers(){AttachSWEvents();}public void AttachSWEvents(){swDrawing.UndoPostNotify += this.swDrawing_UndoPostNotify;swDrawing.UndoPreNotify += this.swDrawing_UndoPreNotify;} private int swDrawing_UndoPostNotify(){// Display message after Undo// NOTE: Because the message box may be displayed // behind an opened window, you might not see it. // If so, then check the Taskbar. MessageBox.Show("An undo post-notification event has been fired.");return 1;} private int b(){// Display message after Undo// NOTE: Because the message box may be displayed // behind an opened window, you might not see it. // If so, then check the Taskbar. MessageBox.Show("An Undo pre-notification event has been fired.");return 1;} /// <summary> /// The SldWorks swApp variable is pre-assigned for you. /// </summary> public SldWorks swApp; } } //This example shows how to automatically insert a model's dimensions marked for drawings //into a drawing.//--------------------------------------------------------------------------- // Preconditions: // 1. Assembly document to open exists. // 2. Run the macro. // // Postconditions: // 1. A new drawing document is opened. // 2. A drawing view of the assembly document is created. // 3. The dimensions in the assembly document that are marked for drawings, // including any duplicate dimensions, appear in the drawing view. // 4. The dimensions in the drawing, which are annotations, // are selected and marked. //--------------------------------------------------------------------------- using SolidWorks.Interop.sldworks; using SolidWorks.Interop.swconst; using System.Runtime.InteropServices; using System;namespace SelectAnnotationsCSharp.csproj {public partial class SolidWorksMacro{public void Main(){ModelDoc2 swModel;ModelDocExtension swModelDocExt;DrawingDoc swDrawing;SelectionMgr swSelmgr;View swView;object[] annotations;object selAnnot;Annotation swAnnotation;SelectData swSelData;int mark;string retval;bool status;retval = swApp.GetUserPreferenceStringValue((int)swUserPreferenceStringValue_e.swDefaultTemplateDrawing);swModel = (ModelDoc2)swApp.NewDocument(retval, 0, 0, 0);swDrawing = (DrawingDoc)swModel;swModelDocExt = (ModelDocExtension)swModel.Extension;swSelmgr = (SelectionMgr)swModel.SelectionManager;// Create drawing from assemblyswView = (View)swDrawing.CreateDrawViewFromModelView3("C:\\Users\\Public\\Documents\\SOLIDWORKS\\SOLIDWORKS 2018\\samples\\tutorial\\api\\wrench.sldasm", "*Front", 0.1314541543147, 0.1407887187817, 0);// Select and activate the viewstatus = swModelDocExt.SelectByID2("Drawing View1", "DRAWINGVIEW", 0, 0, 0, false, 0, null, 0);status = swDrawing.ActivateView("Drawing View1");swModel.ClearSelection2(true);// Insert the annotations marked for the drawingannotations = (object[])swDrawing.InsertModelAnnotations3((int)swImportModelItemsSource_e.swImportModelItemsFromEntireModel, (int)swInsertAnnotation_e.swInsertDimensionsMarkedForDrawing, true, false, false, false);// Select and mark each annotationswSelData = swSelmgr.CreateSelectData();mark = 0;foreach (object annot in annotations){selAnnot = annot;swAnnotation = (Annotation)selAnnot;status = swAnnotation.Select3(true, swSelData);swSelData.Mark = mark;mark = mark + 1;}}/// <summary>/// The SldWorks swApp variable is pre-assigned for you./// </summary>public SldWorks swApp;} }System.bool AttachAnnotation( System.int Option)
//This example shows how to attach an existing annotation to a drawing view.//---------------------------------------------------------------------------- // Preconditions: Open public_documents\samples\tutorial\api\replaceview.slddrw. // // Postconditions: // 1. Inserts a note annotation n the drawing. // 2. Selects the annotation. // 3. Appends a face in a drawing view to the selection list. // 4. Attaches the annotation to the selected face. // 5. Examine the drawing. // 6. Close the drawing without saving it. // --------------------------------------------------------------------------- using SolidWorks.Interop.sldworks; using SolidWorks.Interop.swconst; using System.Runtime.InteropServices; using System; namespace AttachAnnotation_CSharp.csproj {partial class SolidWorksMacro{ModelDoc2 part;DrawingDoc draw;Note aNote;Annotation anAnnot;SelectData selectData = null;int ret;bool boolstatus;public void Main(){part = (ModelDoc2)swApp.ActiveDoc;draw = (DrawingDoc)part;boolstatus = draw.ActivateSheet("Sheet1");aNote = (Note)draw.CreateText2("This is a note.", 0.21, 0.12, 0, 0.005, 0);anAnnot = (Annotation)aNote.GetAnnotation();ret = anAnnot.SetLeader3(swLeaderStyle_e.swBENT, swLeaderSide_e.swLS_SMART, true, false, false, false);anAnnot.Select3(false, selectData);boolstatus = draw.ActivateView("Drawing View1");boolstatus = part.Extension.SelectByID2("", "FACE", 0.0783563575357558, 0.17448024010205, -499.965138294658, true, 0, null, 0);draw.AttachAnnotation(swAttachAnnotationOption_e.swAttachAnnotationOption_View);}public SldWorks swApp;} }System.object AutoBalloon5( AutoBalloonOptions BalloonOptions)
//This example shows how to automatically add BOM balloons to a drawing view.//------------------------------------------------------------------------------ // Preconditions: Open a drawing with a bill of materials (BOM) table. // // Postconditions: BOM balloons are added to the view. //------------------------------------------------------------------------------ using Microsoft.VisualBasic; using System; using System.Collections; using System.Collections.Generic; using System.Data; using System.Diagnostics; using SolidWorks.Interop.sldworks; using SolidWorks.Interop.swconst; using System.Runtime.InteropServices; namespace AutoBalloon_CSharp.csproj {partial class SolidWorksMacro{ModelDoc2 Part;DrawingDoc Draw;object vNotes;AutoBalloonOptions autoballoonParams;bool boolstatus;public void Main(){Part = (ModelDoc2)swApp.ActiveDoc;Draw = (DrawingDoc)Part;boolstatus = Draw.ActivateView("Drawing View1");boolstatus = Part.Extension.SelectByID2("Drawing View1", "DRAWINGVIEW", 0, 0, 0, false, 0, null, 0);autoballoonParams = Draw.CreateAutoBalloonOptions();autoballoonParams.Layout = (int)swBalloonLayoutType_e.swDetailingBalloonLayout_Square;autoballoonParams.ReverseDirection = false;autoballoonParams.IgnoreMultiple = true;autoballoonParams.InsertMagneticLine = true;autoballoonParams.LeaderAttachmentToFaces = true;autoballoonParams.Style = (int)swBalloonStyle_e.swBS_Circular;autoballoonParams.Size = (int)swBalloonFit_e.swBF_5Chars;autoballoonParams.UpperTextContent = (int)swBalloonTextContent_e.swBalloonTextItemNumber;autoballoonParams.Layername = "-None-";autoballoonParams.ItemNumberStart = 1;autoballoonParams.ItemNumberIncrement = 1;autoballoonParams.ItemOrder = (int)swBalloonItemNumbersOrder_e.swBalloonItemNumbers_DoNotChangeItemNumbers;autoballoonParams.EditBalloons = true;autoballoonParams.EditBalloonOption = (int)swEditBalloonOption_e.swEditBalloonOption_Resequence;vNotes = Draw.AutoBalloon5(autoballoonParams);}public SldWorks swApp;} }System.int AutoDimension(?
 ? ?System.int EntitiesToDimension,
 ? ?System.int HorizontalScheme,
 ? ?System.int HorizontalPlacement,
 ? ?System.int VerticalScheme,
 ? ?System.int VerticalPlacement)
void BreakView()
//This example shows how to create and remove a broken view.//---------------------------------------------------------------------------- // Preconditions: // 1. Verify that the specified file to open exists. // 2. Open the Immediate window. // // Postconditions: // 1. Opens the specified drawing and selects Drawing View1. // 2. Examine the drawing, then press F5. // 3. Inserts break lines in Drawing View1. // 4. Examine the drawing, then press F5. // 5. Modifies the positions of the break lines and breaks the view. // 6. Examine the drawing, then press F5. // 7. Removes the break from Drawing View1. // 8. Examine the drawing and the Immediate window. // // NOTE: Because this drawing document is used elsewhere, // do not save changes. //---------------------------------------------------------------------------- using SolidWorks.Interop.sldworks; using SolidWorks.Interop.swconst; using System.Runtime.InteropServices; using System; using System.Diagnostics;namespace BreakViewDrawingDocCSharp.csproj {public partial class SolidWorksMacro{public void Main(){ModelDoc2 swModel;DrawingDoc swDrawingDoc;ModelDocExtension swModelDocExt;SelectionMgr swSelectionManager;SelectData swSelectData;View swView;BreakLine swBreakLine;string fileName;bool status;int errors = 0;int warnings = 0;fileName = "C:\\Users\\Public\\Documents\\SOLIDWORKS\\SOLIDWORKS 2018\\samples\\tutorial\\api\\box.slddrw";swApp.OpenDoc6(fileName, (int)swDocumentTypes_e.swDocDRAWING, (int)swOpenDocOptions_e.swOpenDocOptions_Silent, "", ref errors, ref warnings);swModel = (ModelDoc2)swApp.ActiveDoc;swDrawingDoc = (DrawingDoc)swModel;swModelDocExt = (ModelDocExtension)swModel.Extension;// Activate and select the view to breakstatus = swDrawingDoc.ActivateView("Drawing View1");status = swModelDocExt.SelectByID2("Drawing View1", "DRAWINGVIEW", 0, 0, 0, false, 0, null, 0);swSelectionManager = (SelectionMgr)swModel.SelectionManager; swSelectData = (SelectData)swSelectionManager.CreateSelectData();swView = (View)swSelectionManager.GetSelectedObject6(1, -1);System.Diagnostics.Debugger.Break();// Examine the drawing; press F5// Insert the break linesswBreakLine = (BreakLine)swView.InsertBreak(0, -0.0291950859897372, 0.0198236302285804, 1);System.Diagnostics.Debugger.Break();// Break lines inserted; press F5// Reset position of break linesstatus = swBreakLine.SetPosition(-0.03, 0.05);swModel.EditRebuild3Debug.Print("Break line: ");Debug.Print(" Selected: " + swBreakLine.Select(true, null));Debug.Print(" Style: " + swBreakLine.Style);Debug.Print(" Orientation: " + swBreakLine.Orientation);Debug.Print(" Position: " + swBreakLine.GetPosition(0));swDrawingDoc.BreakView();System.Diagnostics.Debugger.Break();// Positions of the break lines are modified, and view is broken// Press F5status = swModelDocExt.SelectByID2("Drawing View1", "DRAWINGVIEW", 0, 0, 0, false, 0, null, 0);swDrawingDoc.UnBreakView();// Break is removed}/// <summary>/// The SldWorks swApp variable is pre-assigned for you./// </summary>public SldWorks swApp;} }void ChangeComponentLayer(?
 ? ?System.string Layername,
 ? ?System.bool AllViews)
System.object CreateDetailViewAt4(?
 ? ?System.double X,
 ? ?System.double Y,
 ? ?System.double Z,
 ? ?System.int Style,
 ? ?System.double Scale1,
 ? ?System.double Scale2,
 ? ?System.string LabelIn,
 ? ?System.int Showtype,
 ? ?System.bool FullOutline,
 ? ?System.bool JaggedOutline,
 ? ?System.bool NoOutline,
 ? ?System.int ShapeIntensity)
System.bool CreateBreakOutSection(?
 ? ?System.double Depth)
View CreateRelativeView(?
 ? ?System.string ModelName,
 ? ?System.double XPos,
 ? ?System.double YPos,
 ? ?System.int ViewDirFront,
 ? ?System.int ViewDirRight)
View CreateSectionViewAt5(?
 ? ?System.double X,
 ? ?System.double Y,
 ? ?System.double Z,
 ? ?System.string SectionLabel,
 ? ?System.int Options,
 ? ?System.object ExcludedComponents,
 ? ?System.double SectionDepth)
View CreateUnfoldedViewAt3(?
 ? ?System.double X,
 ? ?System.double Y,
 ? ?System.double Z,
 ? ?System.bool NotAligned)
System.bool DrawingViewRotate(?
 ? ?System.double NewAngle)
View DropDrawingViewFromPalette2(?
 ? ?System.string PaletteViewName,
 ? ?System.double X,
 ? ?System.double Y,
 ? ?System.double Z)
void EditSheet()
This example shows how to place a note behind a drawing sheet.//---------------------------------------------------------- // Preconditions: // 1. Verify that the specified drawing file to open exists. // 2. Open the Immediate window. // // Postconditions: // 1. Places the selected note, 2012-sm in the drawing template, // behind the drawing sheet. // 2. To verify: // a. Examine the Immediate window. // b. Right-click the drawing and click // Edit Sheet Format. // c. Right-click 2012-sm and examine the // the short-cut menu to verify that Display // Note Behind Sheet is selected. // d. Exit drawing sheet edit mode. // // NOTE: Because this drawing is used elsewhere, do not // save changes. //-----------------------------------------------------------using SolidWorks.Interop.sldworks; using SolidWorks.Interop.swconst; using System.Runtime.InteropServices; using System; using System.Diagnostics;namespace NoteBehindSheetCSharp.csproj { partial class SolidWorksMacro{ public void Main(){ModelDoc2 swModel = default(ModelDoc2);ModelDocExtension swModelDocExt = default(ModelDocExtension);DrawingDoc swDrawing = default(DrawingDoc);SelectionMgr swSelectionMgr = default(SelectionMgr);Note swNote = default(Note);string fileName = null;bool status = false;int errors = 0;int warnings = 0;// Open drawingfileName = "C:\\Users\\Public\\Documents\\SOLIDWORKS\\SOLIDWORKS 2018\\samples\\tutorial\\api\\2012-sm.slddrw";swModel = (ModelDoc2)swApp.OpenDoc6(fileName, (int)swDocumentTypes_e.swDocDRAWING, (int)swOpenDocOptions_e.swOpenDocOptions_Silent, "", ref errors, ref warnings);swDrawing = (DrawingDoc)swModel;// Put drawing template and sheet in edit modeswModelDocExt = (ModelDocExtension)swModel.Extension;status = swModelDocExt.SelectByID2("Sheet1", "SHEET", 0.0399580396732789, 0.20594194865811, 0, false, 0, null, 0);swDrawing.EditTemplate();swDrawing.EditSheet();swModel.ClearSelection2(true);// Select note to place behind the sheetstatus = swModelDocExt.SelectByID2("DetailItem3@Sheet Format1", "NOTE", 0.155548914819136, 0.017885845974329, 0, false, 0, null, 0);swSelectionMgr = (SelectionMgr)swModel.SelectionManager;swNote = (Note)swSelectionMgr.GetSelectedObject6(1, -1);swNote.BehindSheet = true;Debug.Print("Was the selected note placed behind the sheet? " + status);}/// <summary>/// The SldWorks swApp variable is pre-assigned for you./// </summary>public SldWorks swApp;} }System.object FeatureByName( System.string Name)
//This example shows how to get and set the table anchor of a hole table in a drawing.//----------------------------------------------------------------- // Preconditions: Verify that the specified drawing to open exists. // // Postconditions: // 1. Opens the drawing. // 2. At System.Diagnostics.Debugger.Break(), examine the position // of the hole table in the drawing. // 3. Click the Continue button in the SOLIDWORKS Visual Studio Tools for // Applications IDE. // 4. Sets the position of the hole table's anchor // to the specified location. // 5. Examine the hole table in the drawing. // // NOTE: If prompted, do not save changes when closing the drawing. //------------------------------------------------------------------ using SolidWorks.Interop.sldworks; using SolidWorks.Interop.swconst; using System; using System.Diagnostics;namespace TableAnchorPositionCSharp.csproj {partial class SolidWorksMacro{public void Main(){string filename = null;filename = "C:\\Users\\Public\\Documents\\SOLIDWORKS\\SOLIDWORKS 2018\\samples\\tutorial\\api\\SimpleHole.slddrw";ModelDoc2 model = default(ModelDoc2);int errors = 0;int warnings = 0;model = (ModelDoc2)swApp.OpenDoc6(filename, (int)swDocumentTypes_e.swDocDRAWING, (int)swOpenDocOptions_e.swOpenDocOptions_Silent, "", ref errors, ref warnings);if (model == null)return;System.Diagnostics.Debugger.Break();TableAnnotation swTable = default(TableAnnotation);// If document is a drawing, then continueswitch (model.GetType()){case (int)swDocumentTypes_e.swDocDRAWING:DrawingDoc drw = default(DrawingDoc);drw = (DrawingDoc)model;// Get the current sheetSheet drwSheet = default(Sheet);drwSheet = (Sheet)drw.GetCurrentSheet();// Select the Sheet2 featureModelDocExtension modeldocext = default(ModelDocExtension);bool status = false;modeldocext = (ModelDocExtension)model.Extension;status = modeldocext.SelectByID2("Sheet2", "SHEET", 0, 0, 0, false, 0, null, 0);// Get the views on Sheet2object[] views = null;views = (object[])drwSheet.GetViews();foreach (object vView in views){View drwView = default(View);drwView = (View)vView;Feature viewFeature = default(Feature);viewFeature = (Feature)drw.FeatureByName(drwView.Name);// Traverse the features in the viewFeature subFeature = default(Feature);subFeature = (Feature)viewFeature.GetFirstSubFeature();// If the feature is HoleTableFeat, then get the table annotationswhile (!(subFeature == null)){if (subFeature.GetTypeName2() == "HoleTableFeat"){HoleTable swHoleTable = default(HoleTable);swHoleTable = (HoleTable)subFeature.GetSpecificFeature2();object[] holeTables = null;holeTables = (object[])swHoleTable.GetTableAnnotations();// If the annotation is a hole table, then continueif ((holeTables != null)){foreach (object table in holeTables){swTable = (TableAnnotation)table;// If the hole table is anchored, then continueif (swTable.Type == (int)swTableAnnotationType_e.swTableAnnotation_HoleChart){if (swTable.Anchored != false){TableAnchor holeTableAnchor = default(TableAnchor);holeTableAnchor = (TableAnchor)drwView.Sheet.get_TableAnchor((int)swTableAnnotationType_e.swTableAnnotation_HoleChart);// Get the position of the table anchordouble[] anchorPosition = null;anchorPosition = (double[])holeTableAnchor.Position;// Determine type of table anchorswBOMConfigurationAnchorType_e newCorner = default(swBOMConfigurationAnchorType_e);string corner = null;switch (swTable.AnchorType){case (int)swBOMConfigurationAnchorType_e.swBOMConfigurationAnchor_BottomLeft:corner = " Bottom-left ";newCorner = swBOMConfigurationAnchorType_e.swBOMConfigurationAnchor_TopRight;break;case (int)swBOMConfigurationAnchorType_e.swBOMConfigurationAnchor_BottomRight:corner = " Bottom-right ";newCorner = swBOMConfigurationAnchorType_e.swBOMConfigurationAnchor_TopLeft;break;case (int)swBOMConfigurationAnchorType_e.swBOMConfigurationAnchor_TopLeft:corner = " Top-left ";newCorner = swBOMConfigurationAnchorType_e.swBOMConfigurationAnchor_BottomRight;break;case (int)swBOMConfigurationAnchorType_e.swBOMConfigurationAnchor_TopRight:corner = " Top-right ";newCorner = swBOMConfigurationAnchorType_e.swBOMConfigurationAnchor_BottomLeft;break;}swTable.AnchorType = (int)newCorner;// Set the new position of the table anchordouble[] dNewPosition = new double[2];dNewPosition[0] = 0.0;dNewPosition[1] = 0.0;holeTableAnchor.Position = dNewPosition;}}}}}subFeature = (Feature)subFeature.GetNextSubFeature();}}break;case (int)swDocumentTypes_e.swDocASSEMBLY:case (int)swDocumentTypes_e.swDocPART:break;}}/// <summary>/// The SldWorks swApp variable is pre-assigned for you./// </summary>public SldWorks swApp;} }System.bool GenerateViewPaletteViews( System.string FileName)
//This example shows how to get and set whether to hide cutting line shoulders in a //section view.//-------------------------------------------------------------------------- // Preconditions: // 1. Verify that the part and templates exist. // 2. Open the Immediate window. // // Postconditions: // 1. Opens the part. // 2. Creates a drawing of the part. // 3. Creates a section view. // 4. Gets and sets whether to hide cutting line shoulders in the section // view. // 5. Examine the Immediate window. // // NOTE: Because the part is used elsewhere, do not save it or the drawing. //-------------------------------------------------------------------------- using SolidWorks.Interop.sldworks; using SolidWorks.Interop.swconst; using System.Runtime.InteropServices; using System; using System.Diagnostics;namespace Macro1CSharp.csproj {public partial class SolidWorksMacro{public void Main(){ModelDoc2 swModel = default(ModelDoc2);DrawingDoc swDrawing = default(DrawingDoc);Sheet swSheet = default(Sheet);View swView = default(View);ModelDocExtension swModelDocExt = default(ModelDocExtension);SketchSegment swSketchSegment = default(SketchSegment);SketchManager swSketchMgr = default(SketchManager);DrSection swSectionView = default(DrSection);bool status = false;int errors = 0;int warnings = 0;string fileName = null;double swSheetWidth = 0;double swSheetHeight = 0;string drawingTemplate = null;string sheetTemplate = null;//Open partfileName = "C:\\Users\\Public\\Documents\\SOLIDWORKS\\SOLIDWORKS 2018\\samples\\tutorial\\api\\cam roller.sldprt";swModel = (ModelDoc2)swApp.OpenDoc6(fileName, (int)swDocumentTypes_e.swDocPART, (int)swOpenDocOptions_e.swOpenDocOptions_Silent, "", ref errors, ref warnings);//Create drawing of partswSheetWidth = 1.189;swSheetHeight = 0.841;drawingTemplate = "C:\\ProgramData\\SolidWorks\\SOLIDWORKS 2017\\templates\\Drawing.drwdot";swDrawing = (DrawingDoc)swApp.NewDocument(drawingTemplate, (int)swDwgPaperSizes_e.swDwgPapersUserDefined, swSheetWidth, swSheetHeight);swSheet = (Sheet)swDrawing.GetCurrentSheet();swSheet.SetProperties2((int)swDwgPaperSizes_e.swDwgPapersUserDefined, (int)swDwgTemplates_e.swDwgTemplateCustom, 1, 2, false, swSheetWidth, swSheetHeight, true);sheetTemplate = "C:\\ProgramData\\SolidWorks\\SOLIDWORKS 2017\\lang\\english\\sheetformat\\a0 - iso.slddrt";swSheet.SetTemplateName(sheetTemplate);swSheet.ReloadTemplate(true);status = swDrawing.GenerateViewPaletteViews(fileName);swView = (View)swDrawing.DropDrawingViewFromPalette2("*Left", 0.580930433566434, 0.431525272727273, 0);//Create section viewswDrawing = (DrawingDoc)swApp.ActiveDoc;status = swDrawing.ActivateView("Drawing View1");swModel.ClearSelection2(true);swModel = (ModelDoc2)swDrawing;swSketchMgr = (SketchManager)swModel.SketchManager;swSketchSegment = (SketchSegment)swSketchMgr.CreateLine(0.0, 0.0, 0.0, 0.012168, 0.021283, 0.0);swSketchSegment = (SketchSegment)swSketchMgr.CreateLine(0.0, 0.0, 0.0, 0.024347, -0.010966, 0.0);swModelDocExt = (ModelDocExtension)swModel.Extension;status = swModelDocExt.SelectByID2("Line1", "SKETCHSEGMENT", 0.690604633175108, 0.625483883858213, 0, false, 0, null, 0);status = swModelDocExt.SelectByID2("Line2", "SKETCHSEGMENT", 0.747211061353527, 0.357889859742052, 0, true, 0, null, 0);swView = (View)swDrawing.CreateSectionViewAt5(0.676815388637685, 0.116110180826413, 0, "A", (int)swCreateSectionViewAtOptions_e.swCreateSectionView_OffsetSection, null, 0);status = swDrawing.ActivateView("Drawing View2");swModel.ClearSelection2(true);//Get section view and get and set whether to hide cutting line shouldersswSectionView = (DrSection)swView.GetSection();if (swSectionView.CuttingLineShoulders){Debug.Print("Hide cutting line shoulders = True");Debug.Print("Setting hide cutting line shoulders to False");swSectionView.CuttingLineShoulders = false;Debug.Print(" Hide cutting line shoulders = " + swSectionView.CuttingLineShoulders);}else{Debug.Print("Hide cutting line shoulders = False");Debug.Print("Setting hide cutting line shoulders to True");swSectionView.CuttingLineShoulders = true;Debug.Print(" Hide cutting line shoulders = " + swSectionView.CuttingLineShoulders);}}/// <summary>/// The SldWorks swApp variable is pre-assigned for you./// </summary>public SldWorks swApp;} }System.object GetCurrentSheet()
This example shows how to create a title block in a drawing, if one does not already exist, and how to get the notes from an existing title block in a drawing.//-------------------------------------------------------- // Preconditions: Drawing document is open. // // Postconditions: If the drawing contains a title block, then // the notes of that block are printed // to the Immediate window. If not, // a title block is created. //-------------------------------------------------------using SolidWorks.Interop.sldworks; using SolidWorks.Interop.swconst; using System; using System.Diagnostics; using System.Runtime.InteropServices; namespace ExampleCS.csproj {public partial class SolidWorksMacro{ModelDoc2 swModel;ModelDocExtension swExt;SelectionMgr swSelMgr;View swView;DrawingDoc swDraw;public void Main(){swModel = swApp.ActiveDoc as ModelDoc2;swExt = swModel.Extension;swSelMgr = swModel.SelectionManager as SelectionMgr;swDraw = swModel as DrawingDoc;Sheet swSheet;swSheet = swDraw.GetCurrentSheet() as Sheet;TitleBlock swTitleBlock;swTitleBlock = swSheet.TitleBlock;object[] vNotes;int i;// Create title block if one doesn't existif (swTitleBlock == null){swView = swDraw.GetFirstView() as View;vNotes = (object[])swView.GetNotes();// Add first two notes to the title blockDispatchWrapper[] notesArray = new DispatchWrapper[2];notesArray[0] = new DispatchWrapper(vNotes[0]);notesArray[1] = new DispatchWrapper(vNotes[1]);swTitleBlock = swSheet.InsertTitleBlock(notesArray);}vNotes = (object[])swTitleBlock.GetNotes();for (i = 0; i < vNotes.Length; i++){Note swNote;swNote = (Note)vNotes[i];Debug.Print("Name: " + swNote.GetName());Debug.Print("Value: " + swNote.GetText());}}/// <summary>/// The SldWorks swApp variable is pre-assigned for you./// </summary>public SldWorks swApp;} }System.object GetFirstView()
//This example shows how to get the drawing view's bounding box, position, and position //lock status.//--------------------------------------------------------- // Preconditions: // 1. Verify that the drawing document to open exists. // 2. Open the Immediate window. // // Postconditions: // 1. Opens the specified drawing document. // 2. Gets each drawing view's: // * origin's x and y positions relative // to the drawing sheet origin // * bounding box // * position lock status // 3. Examine the Immediate window. // // NOTE: Because the drawing is used elsewhere, do not save // changes. //---------------------------------------------------------- using SolidWorks.Interop.sldworks; using SolidWorks.Interop.swconst; using System.Runtime.InteropServices; using System; using System.Diagnostics;namespace Macro1.csproj {public partial class SolidWorksMacro{public void Main(){DrawingDoc swDraw = default(DrawingDoc);View swView = default(View);double[] outline = null;double[] pos = null;string fileName = null;int errors = 0;int warnings = 0;fileName = "C:\\Users\\Public\\Documents\\SOLIDWORKS\\SOLIDWORKS 2018\\samples\\tutorial\\api\\replaceview.slddrw";swDraw = (DrawingDoc)swApp.OpenDoc6(fileName, (int)swDocumentTypes_e.swDocDRAWING, (int)swOpenDocOptions_e.swOpenDocOptions_Silent, "", ref errors, ref warnings);swView = (View)swDraw.GetFirstView();while ((swView != null)){outline = (double[])swView.GetOutline();pos = (double[])swView.Position;Debug.Print("View = " + swView.Name);Debug.Print(" X and Y positions = (" + pos[0] * 1000.0 + ", " + pos[1] * 1000.0 + ") mm");Debug.Print(" X and Y bounding box minimums = (" + outline[0] * 1000.0 + ", " + outline[1] * 1000.0 + ") mm");Debug.Print(" X and Y bounding box maximums = (" + outline[2] * 1000.0 + ", " + outline[3] * 1000.0 + ") mm");Debug.Print(" Position locked?" + swView.PositionLocked);swView = (View)swView.GetNextView();}}/// <summary>/// The SldWorks swApp variable is pre-assigned for you./// </summary>public SldWorks swApp;} }System.object GetSheetNames()
//This example shows how to modify and reload a sheet format template.//------------------------------------------------------------ // Preconditions: // 1. Make a copy of: // C:\ProgramData\SolidWorks\SOLIDWORKS version\lang\english\sheetformat\a0 - iso.slddrt. // 2. Create a new blank drawing using standard sheet size AO (ISO). // 3. Add another blank sheet to the drawing, for a total of two sheets. // 4. Open the Immediate window. // // Postconditions: // 1. Modifies the sheet format template to include a new // note. // 2. Examine Sheet1, Sheet2, and the Immediate window. // 3. Delete: // C:\ProgramData\SolidWorks\SOLIDWORKS version\lang\english\sheetformat\a0 - iso.slddrt. // 4. Rename the copy that you made in Preconditions step 1 to: // C:\ProgramData\SolidWorks\SOLIDWORKS version\lang\english\sheetformat\a0 - iso.slddrt. //------------------------------------------------------------ using SolidWorks.Interop.sldworks; using SolidWorks.Interop.swconst; using System.Runtime.InteropServices; using System; using System.Diagnostics;namespace Macro1CSharp.csproj {public partial class SolidWorksMacro{const bool TEST_APPLY_CHANGES_TO_ALL = true;private string GetReloadResult(swReloadTemplateResult_e result){string functionReturnValue = null;switch (result){case (swReloadTemplateResult_e)swReloadTemplateResult_e.swReloadTemplate_Success:functionReturnValue = "Success";break;case (swReloadTemplateResult_e)swReloadTemplateResult_e.swReloadTemplate_UnknownError:functionReturnValue = "FAIL - Unknown Error";break;case (swReloadTemplateResult_e)swReloadTemplateResult_e.swReloadTemplate_FileNotFound:functionReturnValue = "FAIL - File Not Found";break;case (swReloadTemplateResult_e)swReloadTemplateResult_e.swReloadTemplate_CustomSheet:functionReturnValue = "FAIL - Custom Sheet";break;case (swReloadTemplateResult_e)swReloadTemplateResult_e.swReloadTemplate_ViewOnly:functionReturnValue = "FAIL - View Only";break;default:functionReturnValue = "FAIL - <unrecognized error code - " + result + ">";break;}return functionReturnValue;}public void Main(){ModelDoc2 swModel = default(ModelDoc2);swModel = (ModelDoc2)swApp.ActiveDoc;if (swModel == null){Debug.Print("Create a new empty drawing and add a second sheet to the drawing.");return;}if (swModel.GetType() != (int)swDocumentTypes_e.swDocDRAWING)return;DrawingDoc swDrwng = default(DrawingDoc);swDrwng = (DrawingDoc)swModel;//Get the current sheetSheet activeSheet = default(Sheet);activeSheet = (Sheet)swDrwng.GetCurrentSheet();Debug.Print("Active sheet name: " + activeSheet.GetName());//Get the sheet format templatestring templateName = null;templateName = activeSheet.GetTemplateName();Debug.Print("Sheet format template name to modify: " + templateName);swDrwng.EditTemplate();//Add a new note to the sheet format templateNote swNote = default(Note);swNote = (Note)swModel.InsertNote("A New Note");Annotation swAnno = default(Annotation);swAnno = (Annotation)swNote.GetAnnotation();swAnno.SetPosition2(0, 0.2, 0);TextFormat txtFormat = default(TextFormat);txtFormat = (TextFormat)swAnno.GetTextFormat(0);txtFormat.BackWards = (txtFormat.BackWards == false);txtFormat.Bold = true;txtFormat.CharHeightInPts = 10 * txtFormat.CharHeightInPts;swAnno.SetTextFormat(0, false, txtFormat);swDrwng.EditSheet();//At this point, the active sheet's format has changed if (TEST_APPLY_CHANGES_TO_ALL){//Save sheet format back to original sheet format templateactiveSheet.SaveFormat(templateName);//Reload all other sheets from the updated sheet format templateobject[] vSheetNames = null;vSheetNames = (object[])swDrwng.GetSheetNames();foreach (string vName in vSheetNames){if (vName != (string)activeSheet.GetName()){Debug.Print("Other sheet name: " + vName);Sheet otherSheet = default(Sheet);otherSheet = (Sheet)swDrwng.get_Sheet(vName);if (otherSheet.GetTemplateName() == templateName){swReloadTemplateResult_e reloadResult = default(swReloadTemplateResult_e);//Keep modifications and and reload all other elements//from original sheet format templatereloadResult = (swReloadTemplateResult_e)otherSheet.ReloadTemplate(true);//Discard modifications and reload all elements from//original sheet format template//reloadResult = otherSheet.ReloadTemplate(False) Debug.Print("Reload sheet format for <" + otherSheet.GetName() + ">: " + GetReloadResult(reloadResult));}}}swDrwng.ActivateSheet(activeSheet.GetName());}else{//Discard the changes and reload the original sheet format templateswReloadTemplateResult_e reloadResult = default(swReloadTemplateResult_e);reloadResult = (swReloadTemplateResult_e)activeSheet.ReloadTemplate(false);Debug.Print("Done - " + GetReloadResult(reloadResult));}}/// <summary>/// The SldWorks swApp variable is pre-assigned for you./// </summary>public SldWorks swApp;} }System.int GetViewCount()
This example shows how to get all of the views and notes in a drawing document.'-------------------------------------------- ' Preconditions: Drawing document is open and at least ' one view has some notes. ' ' Postconditions: None ' ' NOTE: IDrawingDoc::GetViews returns both sheets and views. '----------------------------------------------Option Explicit Dim swApp As SldWorks.SldWorks Dim swModel As SldWorks.ModelDoc2 Dim swDrawDoc As SldWorks.DrawingDoc Dim swView As SldWorks.View Dim swNote As SldWorks.Note Dim sheetCount As Long Dim viewCount As Long Dim noteCount As Long Dim i As LongSub main()Set swApp = Application.SldWorks Set swModel = swApp.ActiveDoc Set swDrawDoc = swModel Dim viewCount As Long viewCount = swDrawDoc.GetViewCount Dim ss As Variant ss = swDrawDoc.GetViews For sheetCount = LBound(ss) To UBound(ss)Dim vv As Variantvv = ss(sheetCount)For viewCount = LBound(vv) To UBound(vv)Debug.Print (vv(viewCount).GetName2())Dim vNotes As VariantnoteCount = vv(viewCount).GetNoteCountIf noteCount > 0 ThenvNotes = vv(viewCount).GetNotesFor i = 0 To noteCount - 1Debug.Print " Note text: " & vNotes(i).GetTextNextEnd IfNext viewCount Next sheetCount End Subvoid HideEdge()
//This example shows how to hide and then show all of the edges in the root component in //a drawing view.//--------------------------------------------------------------------------- // Preconditions: // 1. Verify that the specified drawing document to open exists. // 2. Open the Immediate window. // // Postconditions: // 1. Opens the specified drawing document. // 2. Hides and then shows all edges in the root component in // Drawing View1. // 3. Examine the drawing and Immediate window. //---------------------------------------------------------------------------- using Microsoft.VisualBasic; using System; using System.Collections; using System.Collections.Generic; using System.Data; using System.Diagnostics; using SolidWorks.Interop.sldworks; using SolidWorks.Interop.swconst; using System.Runtime.InteropServices; namespace HideShowEdges_CSharp.csproj {partial class SolidWorksMacro{ModelDoc2 swModel;DrawingDoc swDraw;DocumentSpecification swDocSpecification;Sheet swSheet;View swView;DrawingComponent swDrawingComponent;Component2 swComponent;Entity swEntity;object[] vEdges;bool bRet;int i;public void Main(){// Specify the drawing to openswDocSpecification = (DocumentSpecification)swApp.GetOpenDocSpec("C:\\Users\\Public\\Documents\\SOLIDWORKS\\SOLIDWORKS 2018\\samples\\tutorial\\advdrawings\\foodprocessor.SLDDRW");swModel = (ModelDoc2)swApp.ActiveDoc;if (swModel == null){swModel = swApp.OpenDoc7(swDocSpecification);}swModel = (ModelDoc2)swApp.ActiveDoc;swDraw = (DrawingDoc)swModel;// Get the current sheetswSheet = (Sheet)swDraw.GetCurrentSheet();Debug.Print(swSheet.GetName());// Select Drawing View1bRet = swModel.Extension.SelectByID2("Drawing View1", "DRAWINGVIEW", 0.0, 0.0, 0.0, true, 0, null, (int)swSelectOption_e.swSelectOptionDefault);swView = (View)((SelectionMgr)swModel.SelectionManager).GetSelectedObject6(1, -1);// Print the drawing view name and get the component in the drawing viewDebug.Print(swView.GetName2());swDrawingComponent = swView.RootDrawingComponent;swComponent = swDrawingComponent.Component;// Get the component's visible entities in the drawing viewint eCount = 0;eCount = swView.GetVisibleEntityCount2(swComponent, (int)swViewEntityType_e.swViewEntityType_Edge);vEdges = (object[])swView.GetVisibleEntities2(swComponent, (int)swViewEntityType_e.swViewEntityType_Edge);Debug.Print("Number of edges found: " + eCount);// Hide all of the visible edges in the drawing viewfor (i = 0; i <= eCount - 1; i++){swEntity = (Entity)vEdges[i];swEntity.Select4(true, null);swDraw.HideEdge();}// Clear all selectionsswModel.ClearSelection2(true);// Show all hidden edgesswView.HiddenEdges = vEdges;}public SldWorks swApp;} }void HideShowDrawingViews()
//This example shows how to set the display mode of a drawing view.//---------------------------------------------------------------------------- // Preconditions: // 1. Open a drawing document. // 2. Select a view. // 3. Inspect the graphics area and press F5 six times. // // Postconditions: The display mode, hide/show, and suppression // settings for the document are modified as specified. //----------------------------------------------------------------------------using Microsoft.VisualBasic; using System; using System.Collections; using System.Collections.Generic; using System.Data; using System.Diagnostics; using SolidWorks.Interop.sldworks; using SolidWorks.Interop.swconst; using System.Runtime.InteropServices; namespace DisplayHiddenLinesinDrawing_CSharp.csproj {partial class SolidWorksMacro{public void Main(){ModelDoc2 swModel = default(ModelDoc2);DrawingDoc swDraw = default(DrawingDoc);swModel = (ModelDoc2)swApp.ActiveDoc;swDraw = (DrawingDoc)swModel;swDraw.ViewDisplayHidden();System.Diagnostics.Debugger.Break();swDraw.ViewDisplayHiddengreyed();System.Diagnostics.Debugger.Break();swDraw.ViewDisplayWireframe();System.Diagnostics.Debugger.Break();swDraw.ViewDisplayShaded();System.Diagnostics.Debugger.Break();// Suppress viewswDraw.SuppressView();System.Diagnostics.Debugger.Break();// Display an X where the view was suppressedswDraw.HideShowDrawingViews();System.Diagnostics.Debugger.Break();// Unsuppress viewswDraw.UnsuppressView();}public SldWorks swApp;} }Centerline InsertCenterLine2()
//This example shows how to get all of the centerlines in all of the drawing views in a //drawing.//------------------------------------ // Preconditions: // 1. Verify that the drawing document to open exists. // 2. Open the Immediate window. // // Postconditions: // 1. Opens the specified drawing. // 2. Inserts a centerline annotation. // 3. Prints the path and file name of the drawing document // to the Immediate window. // 4. Iterates the sheet and drawing view, prints their names, and // prints the name of the centerline annotation to // the Immediate window. // 5. Examine the Immediate window. // // NOTE: Because this drawing document is used elsewhere, // do not save any changes. //------------------------------------ using SolidWorks.Interop.sldworks; using SolidWorks.Interop.swconst; using System.Runtime.InteropServices; using System; using System.Diagnostics;namespace CenterLinesCSharp.csproj {public partial class SolidWorksMacro{public void Main(){ModelDoc2 swModel = default(ModelDoc2);ModelDocExtension swModelDocExt = default(ModelDocExtension);DrawingDoc swDrawing = default(DrawingDoc);View swView = default(View);Centerline swCenterLine = default(Centerline);Annotation swAnnotation = default(Annotation);bool status = false;int errors = 0;int warnings = 0;string fileName = null;fileName = "C:\\Users\\Public\\Documents\\SOLIDWORKS\\SOLIDWORKS 2018\\samples\\tutorial\\api\\cylinder20.SLDDRW";swModel = (ModelDoc2)swApp.OpenDoc6(fileName, (int)swDocumentTypes_e.swDocDRAWING, (int)swOpenDocOptions_e.swOpenDocOptions_Silent, "", ref errors, ref warnings);swDrawing = (DrawingDoc)swModel;swModelDocExt = (ModelDocExtension)swModel.Extension;status = swDrawing.ActivateView("Drawing View1");status = swModelDocExt.SelectByID2("cylinder20-9@Drawing View1", "COMPONENT", 0, 0, 0, false, 0, null, 0);status = swModelDocExt.SelectByID2("", "FACE", 0.513454307125032, 0.454946591641617, 250.013794595267, false, 0, null, 0);swCenterLine = (Centerline)swDrawing.InsertCenterLine2();swModel.ClearSelection2(true);swView = (View)swDrawing.GetFirstView();Debug.Print("File = " + swModel.GetPathName());while ((swView != null)){Debug.Print(" View = " + swView.GetName2());swCenterLine = (Centerline)swView.GetFirstCenterLine();while ((swCenterLine != null)){swAnnotation = (Annotation)swCenterLine.GetAnnotation();Debug.Print(" Name = " + swAnnotation.GetName());swCenterLine = swCenterLine.GetNext();}swView = (View)swView.GetNextView();}}/// <summary>/// The SldWorks swApp variable is pre-assigned for you./// </summary>public SldWorks swApp;} }System.bool InsertCircularNotePattern(?
 ? ?System.double ArcRadius,
 ? ?System.double ArcAngle,
 ? ?System.int PatternNum,
 ? ?System.double PatternSpacing,
 ? ?System.bool PatternRotate,
 ? ?System.string DeleteInstances)
System.object InsertRevisionCloud(?System.int CloudShape)
//This example shows how to insert revision clouds into a drawing and access revision //cloud data.//---------------------------------------------------------------------------- // Preconditions: Open public_documents\samples\tutorial\api\resetsketchvisibility.slddrw. // // Postconditions: // 1. Inserts an elliptical revision cloud in the drawing. // 2. Examine the Immediate window. // // NOTE: Because the drawing is used elsewhere, do not save changes. // --------------------------------------------------------------------------- using Microsoft.VisualBasic; using System; using System.Collections; using System.Collections.Generic; using System.Data; using System.Diagnostics; using SolidWorks.Interop.sldworks; using SolidWorks.Interop.swconst; using System.Runtime.InteropServices; namespace InsertRevisionCloud_CSharp.csproj {partial class SolidWorksMacro{DrawingDoc Part;RevisionCloud RevCloud;Annotation RevCloudAnno;bool boolstatus;public void Main(){Part = (DrawingDoc)swApp.ActiveDoc;boolstatus = Part.ActivateView("Drawing View1");// Create a revision cloud with an elliptical shapeRevCloud = (RevisionCloud)Part.InsertRevisionCloud(1);if ((RevCloud != null)){RevCloudAnno = (Annotation)RevCloud.GetAnnotation();if ((RevCloudAnno != null)){// Position the center of the elliptical revision cloudboolstatus = RevCloudAnno.SetPosition(0.270847371964905, 0.553263328912467, 0);RevCloud.ArcRadius = 0.00508;// Create a path point on the corner of an ellipse-inscribed rectangleboolstatus = RevCloud.SetPathPointAtIndex(-1, 0.378419710263212, 0.511051398694144, 0);// Close the revision cloud pathboolstatus = RevCloud.Finalize();}}}public SldWorks swApp;} }TableAnnotation InsertTableAnnotation2(?
 ? ?System.bool UseAnchorPoint,
 ? ?System.double X,
 ? ?System.double Y,
 ? ?System.int AnchorType,
 ? ?System.string TableTemplate,
 ? ?System.int Rows,
 ? ?System.int Columns)
 ?
void IsolateChangedDimensions()
This example shows how to isolate a changed dimension.//------------------------------------------------------ // Preconditions: The specified drawing and part // documents exist. // // Postconditions: // 1. Opens the drawing document. // 2. Sets the system option to display // changed dimensions in the color selected // for Tools > Options > System Options > // Colors > Color scheme settings > // Drawings, Changed dimensions. // 3. Saves and closes the drawing document. // 4. Opens the part document of the drawing document. // 5. Changes a dimension. // 6. Saves and closes the part document. // 7. Opens the previously saved drawing document. // 8. Examine the drawing document to verify that // the changed dimension is displayed in the // changed-dimension color. Place your cursor over // the dimension to see its previous value. //------------------------------------------------------- using SolidWorks.Interop.sldworks; using SolidWorks.Interop.swconst; using System;namespace IsolateChangedDimensionsDrawingDocCSharp.csproj {partial class SolidWorksMacro{public void Main(){ModelDoc2 swModel = default(ModelDoc2);ModelDocExtension swModelDocExt = default(ModelDocExtension);DrawingDoc swDrawing = default(DrawingDoc);string fileName = null;string saveFileName = null;int errors = 0;int warnings = 0;bool status = false;// Open drawing document fileName = "C:\\Users\\Public\\Documents\\SOLIDWORKS\\SOLIDWORKS 2018\\samples\\tutorial\\api\\box.slddrw";swModel = (ModelDoc2)swApp.OpenDoc6(fileName, (int)swDocumentTypes_e.swDocDRAWING, (int)swOpenDocOptions_e.swOpenDocOptions_Silent, "", ref errors, ref warnings);// Isolate changed dimensions // Equivalent to selecting Tools > Options > System Options > Colors > // Use specified color for changed drawing dimensions on openswApp.SetUserPreferenceToggle((int)swUserPreferenceToggle_e.swUseChangedDimensions, true);swDrawing = (DrawingDoc)swModel;swDrawing.IsolateChangedDimensions();// Save drawing document to another namesaveFileName = "C:\\Users\\Public\\Documents\\SOLIDWORKS\\SOLIDWORKS 2018\\samples\\tutorial\\api\\box_changed.slddrw";swModelDocExt = (ModelDocExtension)swModel.Extension;status = swModelDocExt.SaveAs(saveFileName, (int)swSaveAsVersion_e.swSaveAsCurrentVersion, (int)swSaveAsOptions_e.swSaveAsOptions_Silent, null, ref errors, ref warnings);swApp.CloseDoc(saveFileName);// Open the part document referenced by the drawing document,// change a dimension, and save the documentfileName = "C:\\Users\\Public\\Documents\\SOLIDWORKS\\SOLIDWORKS 2018\\samples\\tutorial\\api\\box.sldprt";swModel = (ModelDoc2)swApp.OpenDoc6(fileName, (int)swDocumentTypes_e.swDocPART, (int)swOpenDocOptions_e.swOpenDocOptions_Silent, "", ref errors, ref warnings);swModelDocExt = (ModelDocExtension)swModel.Extension;status = swModelDocExt.SelectByID2("Sketch1", "SKETCH", 0, 0, 0, true, 0, null, 0);status = swModelDocExt.SelectByID2("D2@Sketch1@box.SLDPRT", "DIMENSION", -0.03613329319351, -0.02215939491444, 0.02938582119709, true, 0, null, 0);Dimension swDimension = default(Dimension);swDimension = (Dimension)swModel.Parameter("D2@Sketch1");swDimension.SystemValue = 0.185;swModel.ClearSelection2(true);status = swModel.EditRebuild3();status = swModel.Save3((int)swSaveAsOptions_e.swSaveAsOptions_Silent, ref errors, ref warnings);swApp.CloseDoc(fileName);// Open the previously saved drawing document// and place your cursor on the changed dimension,// which displays in the color specified for// changed dimensions, to see its previous valueswModel = (ModelDoc2)swApp.OpenDoc6(saveFileName, (int)swDocumentTypes_e.swDocDRAWING, (int)swOpenDocOptions_e.swOpenDocOptions_Silent, "", ref errors, ref warnings);}/// <summary>/// The SldWorks swApp variable is pre-assigned for you./// </summary>public SldWorks swApp;} }System.bool NewSheet4(?
 ? ?System.string Name,
 ? ?System.int PaperSize,
 ? ?System.int TemplateIn,
 ? ?System.double Scale1,
 ? ?System.double Scale2,
 ? ?System.bool FirstAngle,
 ? ?System.string TemplateName,
 ? ?System.double Width,
 ? ?System.double Height,
 ? ?System.string PropertyViewName,
 ? ?System.double ZoneLeftMargin,
 ? ?System.double ZoneRightMargin,
 ? ?System.double ZoneTopMargin,
 ? ?System.double ZoneBottomMargin,
 ? ?System.int ZoneRow,
 ? ?System.int ZoneCol)
System.bool ReplaceViewModel(?
 ? ?System.string NewModelPathName,
 ? ?System.object Views,
 ? ?System.object Instances)
void SetSheetsSelected( System.object NewSheetList)
//This example shows how to modify the setups of multiple drawing sheets.//-------------------------------------------------------- // Preconditions: // 1. Verify that the drawing and sheet format files exist. // 2. Open the Immediate window. // // Postconditions: // 1. Opens the drawing. // 2. Sets Sheet1, Sheet2 and Sheet3 drawing sheet formats // to portrait. // 3. Rebuilds the drawing. // 4. Click each sheet tab, click Zoom to Fit, and examine // the sheet. // // NOTE: Because the drawing is used elsewhere, do not // save changes. //--------------------------------------------------------- using SolidWorks.Interop.sldworks; using SolidWorks.Interop.swconst; using System.Runtime.InteropServices; using System;namespace Macro1CSharp.csproj {public partial class SolidWorksMacro{public void Main(){ModelDoc2 swModel = default(ModelDoc2);ModelDocExtension swModelDocExt = default(ModelDocExtension);DrawingDoc swDrawing = default(DrawingDoc);string fileName = null;bool status = false;int errors = 0;int warnings = 0;object sheetNameArray = null;string[] sheetNames = new string[2];fileName = "C:\\Users\\Public\\Documents\\SOLIDWORKS\\SOLIDWORKS 2018\\samples\\tutorial\\advdrawings\\foodprocessor.slddrw";swModel = (ModelDoc2)swApp.OpenDoc6(fileName, (int)swDocumentTypes_e.swDocDRAWING, (int)swOpenDocOptions_e.swOpenDocOptions_Silent, "", ref errors, ref warnings);swModelDocExt = (ModelDocExtension)swModel.Extension;swDrawing = (DrawingDoc)swModel;sheetNames[0] = "Sheet2";sheetNames[1] = "Sheet3";sheetNameArray = sheetNames;swDrawing.SetSheetsSelected(sheetNameArray);status = swDrawing.SetupSheet6("Sheet3", (int)swDwgPaperSizes_e.swDwgPapersUserDefined, (int)swDwgTemplates_e.swDwgTemplateCustom, 1, 1, true, "C:\\ProgramData\\SOLIDWORKS\\SOLIDWORKS 2017\\lang\\english\\sheetformat\\a4 - portrait.slddrt", 0.2794, 0.2159, "Default",true, 0, 0, 0, 0, 0, 0);swModel.ForceRebuild3(true);swModel.ViewZoomtofit2();}/// <summary>/// The SldWorks swApp variable is pre-assigned for you./// </summary>public SldWorks swApp;} }void SuppressView()
//This example shows how to automatically insert center marks in multiple drawing views.//---------------------------------------------------------------------------- // Preconditions: Open public_documents\samples\tutorial\advdrawings\foodprocessor.slddrw. // // Postconditions: // 1. Clears the Tools > Options > Document Properties > Centerlines/Center Marks > // Scale by view scale check box. // 2. Activates Sheet3. // 3. Suppresses Drawing View9. // 4. Inserts center marks in Drawing View9 and Drawing View11. // 5. Unsuppresses Drawing View9. // 6. Examine the drawing. // // NOTE: Because the drawing is used elsewhere, do not save changes. // --------------------------------------------------------------------------- using System; using SolidWorks.Interop.sldworks; using SolidWorks.Interop.swconst;namespace AutoInsertCenterMarks_CSharp.csproj {partial class SolidWorksMacro{ModelDoc2 Part;DrawingDoc Draw;ModelDocExtension ModelDocExt;View swActiveView;bool boolstatus;public void Main(){Part = (ModelDoc2)swApp.ActiveDoc;Draw = (DrawingDoc)Part;ModelDocExt = (ModelDocExtension)Part.Extension;// Clear the Scale by view scale check box to set gapModelDocExt.SetUserPreferenceToggle((int)swUserPreferenceToggle_e.swDetailingCenterMarkScaleByViewScale, (int)swUserPreferenceOption_e.swDetailingNoOptionSpecified, false);Draw.ActivateSheet("Sheet3");// Suppress Drawing View9 boolstatus = ModelDocExt.SelectByID2("Drawing View9", "DRAWINGVIEW", 0, 0, 0, false, 0, null, 0);Draw.SuppressView();// Insert center marks for all holes, fillets, and slots in the specified viewboolstatus = Draw.ActivateView("Drawing View9");swActiveView = (View)Draw.ActiveDrawingView;boolstatus = swActiveView.AutoInsertCenterMarks2(7, 11, true, true, true, 0.0025, 0.0025, true, true, 0);boolstatus = Draw.ActivateView("Drawing View11");swActiveView = (View)Draw.ActiveDrawingView;boolstatus = swActiveView.AutoInsertCenterMarks2(7, 11, true, true, false, 0.005, 0.005, true, false, 0);Part.ClearSelection2(true);// Unsuppress Drawing View9boolstatus = ModelDocExt.SelectByID2("Drawing View9", "DRAWINGVIEW", 0, 0, 0, false, 0, null, 0);Draw.UnsuppressView();}public SldWorks swApp;}}
 ?
總結
以上是生活随笔為你收集整理的IDrawingDoc Interface 学习笔记的全部內容,希望文章能夠幫你解決所遇到的問題。
 
                            
                        - 上一篇: MATLAB滑动窗口(移动方差)
- 下一篇: startActivitystartAc
