ISldWorks 的接口

Solidworks学习笔记-链接Solidworks

在此基础上试验

=========================================================================

属性

NameDescription备注
ActiveDocGets the currently active document.  获取当前活动的文档。返回类型object。
CommandInProgressImproves performance of out-of-process applications by informing SOLIDWORKS that a sequence of API calls will be made by the out-of-process application.  通过通知 SOLIDWORKS 进程外应用程序将进行一系列 API 调用来提高进程外应用程序的性能。
EnableBackgroundProcessingGets or sets whether to enable background processing.  获取或设置是否开启后台处理。
EnableFileMenuGets or sets whether to enable file-related menus and toolbars.  获取或设置是否启用与文件相关的菜单和工具栏。
FrameHeightGet or sets the height of the SOLIDWORKS window.  获取或设置 SOLIDWORKS 窗口的高度。
FrameLeftGets or sets the left position of the SOLIDWORKS window.  获取或设置 SOLIDWORKS 窗口的左侧位置。
FrameStateGets or sets the window state (minimum, maximum, or normal) for the SOLIDWORKS window.  获取或设置 SOLIDWORKS 窗口的窗口状态(最小、最大或正常)。可以把结果转化为swWindowState_e再显示。
FrameTopGets or sets the top position of the SOLIDWORKS window.  获取或设置 SOLIDWORKS 窗口的顶部位置。
FrameWidthGets or sets the width of the frame of the SOLIDWORKS window.  获取或设置 SOLIDWORKS 窗口的框架宽度。
IActiveDoc2Gets the currently active document.  获取当前活动的文档。返回类型ModelDoc2 。
StartupProcessCompletedGets whether the SOLIDWORKS startup process, including loading all startup add-ins, has completed.  获取 SOLIDWORKS 启动过程(包括加载所有启动插件)是否已完成。返回bool值。
TaskPaneIsPinnedGets or sets whether the SOLIDWORKS Task Pane is pinned.  获取或设置是否固定 SOLIDWORKS 任务窗格。
UserControlGets and sets whether the user has control over the application.  获取和设置用户是否可以控制应用程序。
UserControlBackgroundGets and sets whether the user has control over the application.  获取和设置用户是否可以控制应用程序。
UserTypeLibReferencesGets and sets the user-specified type library references.  获取和设置用户指定的类型库引用。
VisibleGets and sets the visibility property of the SOLIDWORKS application.  获取和设置 SOLIDWORKS 应用程序的可见性属性。UserControl = false,无文档打开时可以设置。

=========================================================================

方法

NameDescription备注
ActivateDoc3Activates a loaded document and rebuilds it as specified.  激活加载的文档并按指定重建它。
ActivateTaskPaneActivates the specified task pane.  激活指定的任务窗格。
AddCallbackRegisters a general purpose callback handler.  注册通用回调处理程序。
AddFileOpenItem3Adds file types to the File > Open dialog box.  将文件类型添加到“文件”>“打开”对话框。
AddFileSaveAsItem2Adds a file type to the SOLIDWORKS File > Save As dialog box.  将文件类型添加到 SOLIDWORKS 文件 > 另存为对话框。
AddItemToThirdPartyPopupMenuAdds menu items to a pop-up (shortcut) menu in a C++ SOLIDWORKS add-in.  将菜单项添加到 C++ SOLIDWORKS 插件中的弹出(快捷方式)菜单。
AddItemToThirdPartyPopupMenu2Adds menu items to a pop-up (shortcut) menu in a SOLIDWORKS add-in.  将菜单项添加到 SOLIDWORKS 插件中的弹出(快捷方式)菜单。
AddMenuAdds a menu item to a SOLIDWORKS menu for DLL applications.  将 DLL 应用程序的 菜单项添加到SOLIDWORKS 菜单。
AddMenuItem5Adds a menu item and image to the SOLIDWORKS user interface.  向 SOLIDWORKS 用户界面添加菜单项和图像。
AddMenuPopupItem3Adds a menu item with zero or more submenus to shortcut menus of entities of the specified type in documents of the specified type.  将具有零个或多个子菜单的菜单项添加到指定类型文档中指定类型实体的快捷菜单。
AddMenuPopupItem4Adds a menu item with zero or more submenus to shortcut menus of features of the specified type in documents of the specified type.  将具有零个或多个子菜单的菜单项添加到指定类型文档中指定类型功能的快捷菜单。
AddToolbar5Creates a Windows-style dockable toolbar.  创建一个 Windows 风格的可停靠工具栏。
AddToolbarCommand2Specifies the application functions to call when a toolbar button is clicked or sets a separator.  指定单击工具栏按钮或设置分隔符时要调用的应用程序函数。
AllowFailedFeatureCreationSets whether to allow the creation of a feature that has rebuild errors.  设置是否允许创建具有重建错误的特征。
ArrangeIconsArranges the icons in SOLIDWORKS.  在 SOLIDWORKS 中排列图标。
ArrangeWindowsArranges the open windows in SOLIDWORKS.  在 SOLIDWORKS 中排列打开的窗口。
BlockSkinningBlocks skinning a window, which prevents a window from looking like a SOLIDWORKS window.  阻止窗口蒙皮,防止窗口看起来像 SOLIDWORKS 窗口。
CallBackAllows an out-of-process executable or a SOLIDWORKS macro to call back a function in a SOLIDWORKS add-in DLL.  允许进程外可执行文件或 SOLIDWORKS 宏回调 SOLIDWORKS 插件 DLL 中的函数。
CheckpointConvertedDocumentSaves the specified open document if its version is older than the version of the SOLIDWORKS product being used.  如果指定的打开文档的版本早于正在使用的 SOLIDWORKS 产品的版本,则保存该文档。
CloseAllDocumentsCloses all open documents in the SOLIDWORKS session.  关闭 SOLIDWORKS 会话中所有打开的文档。
CloseAndReopenCloses and reopens the specified drawing document without unloading its references from memory.  关闭并重新打开指定的工程图文档,而不从内存中卸载其参考。
CloseDocCloses the specified document.  关闭指定的文档。
CommandOpens the specified dialog or file.  打开指定的对话框或文件。
CopyAppearanceCopies the appearance of the specified entity to the clipboard.  将指定实体的外观复制到剪贴板。
CopyDocumentCopies a document and optionally updates references to it.  复制文档并可选择更新对其的引用。
CreateNewWindowCreates a client window containing the active document.  创建包含活动文档的客户端窗口。
CreatePropertyManagerPageCreates a PropertyManager page.  创建 PropertyManager 页面。
CreateTaskpaneView3Creates an application-level Task Pane view.  创建应用程序级任务窗格视图。
DefineAttributeCreates an attribute definition, which is the first step in generating attributes.  创建属性定义,这是生成属性的第一步。
DisplayStatusBarSets whether to display the status bar.  设置是否显示状态栏。
DocumentVisibleAllows the application to control the display of a document in a window upon creation or retrieval.  允许应用程序在创建或检索时控制文档在窗口中的显示。
DragToolbarButtonCopies the specified toolbar button from the specified native SOLIDWORKS toolbar or ICommandGroup toolbar to the specified native SOLIDWORKS toolbar or ICommandGroup toolbar.  将指定的工具栏按钮从指定的原生 SOLIDWORKS 工具栏或 ICommandGroup 工具栏复制到指定的原生 SOLIDWORKS 工具栏或 ICommandGroup 工具栏。
DragToolbarButtonFromCommandIDCopies a button to a toolbar using a command ID.  使用命令 ID 将按钮复制到工具栏。
EnumDocuments2Gets a list of documents currently open in the application.  获取当前在应用程序中打开的文档列表。
ExitAppShuts down SOLIDWORKS.  关闭 SOLIDWORKS。
ExportHoleWizardItemExports data for the specified Hole Wizard standard.  为指定的异型孔向导标准导出数据。
ExportToolboxItemExports data for the specified Toolbox standard.  导出指定 Toolbox 标准的数据。
FrameGets the SOLIDWORKS main frame.  获取 SOLIDWORKS 主框架。
GetActiveConfigurationNameGets the name of the active configuration in the specified SOLIDWORKS document.  获取指定 SOLIDWORKS 文档中活动配置的名称。
GetAddInObjectGets an add-in object for the specified SOLIDWORKS add-in.  获取指定 SOLIDWORKS 插件的插件对象。
GetApplySelectionFilterGets the current state of the selection filter.  获取选择过滤器的当前状态。
GetBuildNumbers2Gets the build, major revision, and hot fix numbers of the SOLIDWORKS application.  获取 SOLIDWORKS 应用程序的内部版本、主要修订版本和修补程序编号。
GetButtonPositionGets the center coordinates of the specified SOLIDWORKS toolbar button.  获取指定 SOLIDWORKS 工具栏按钮的中心坐标。
GetCollisionDetectionManagerGets the collision detection manager.  获取碰撞检测管理器。
GetColorTableGets a color table from the SOLIDWORKS application.  从 SOLIDWORKS 应用程序获取颜色表。
GetCommandIDGets the SOLIDWORKS command ID for an instance of an add-in's control (e.g., an add-in's toolbar button).  获取插件控件实例(例如插件工具栏按钮)的 SOLIDWORKS 命令 ID。
GetCommandManagerGets the CommandManager for the specified add-in.  获取指定加载项的 CommandManager。
GetConfigurationCountGets the number of configurations in the SOLIDWORKS document, whether the document is opened or closed.  获取 SOLIDWORKS 文档中的配置数,无论文档是打开还是关闭。
GetConfigurationNamesGets the names of the configuration in this SOLIDWORKS document, whether the document is opened or closed.  获取此 SOLIDWORKS 文档中配置的名称,无论该文档是打开还是关闭。
GetCurrentFileUserGets the name of the user who has the the specified document open.  获取打开指定文档的用户的姓名。
GetCurrentLanguageGets the current language used by SOLIDWORKS.  获取 SOLIDWORKS 使用的当前语言。
GetCurrentLicenseTypeGets the type of license for the current SOLIDWORKS session.  获取当前 SOLIDWORKS 会话的许可类型。
GetCurrentMacroPathFolderGets the name of the folder where the macro resides.  获取宏所在文件夹的名称。
GetCurrentMacroPathNameGets the path name for the macro currently running.  获取当前运行的宏的路径名。
GetCurrentWorkingDirectoryGets the current working directory being used by the SOLIDWORKS application.  获取 SOLIDWORKS 应用程序正在使用的当前工作目录。
GetDataFolderGets the data directory name currently used by SOLIDWORKS.  获取 SOLIDWORKS 当前使用的数据目录名称。
GetDocumentCountGets the number of open documents in the current SOLIDWORKS session.  获取当前 SOLIDWORKS 会话中打开的文档数。
GetDocumentDependencies2Gets all of the model dependencies for a document.  获取文档的所有模型依赖项。
GetDocumentsGets the open documents in this SOLIDWORKS session.  获取此 SOLIDWORKS 会话中打开的文档。
GetDocumentTemplateGets the name of document template that can be used in ISldWorks::NewDocument or ISldWorks::INewDocument2.  获取可在 ISldWorks::NewDocument 或 ISldWorks::INewDocument2 中使用的文档模板的名称。
GetEnvironmentGets the IEnvironment object.  获取环境对象。
GetDocumentVisibleGets the visibility of the document to open.  获取打开的文档的可见性。
GetErrorMessagesGets the last 20 messages issued by SOLIDWORKS in the current SOLIDWORKS session.  获取 SOLIDWORKS 在当前 SOLIDWORKS 会话中发出的最后 20 条消息。
GetExecutablePathGets the path to the SOLIDWORKS executable, sldworks.exe.  获取 SOLIDWORKS 可执行文件 sldworks.exe 的路径。
GetExportFileDataGets the data interface for the specified file type to which to export one or more drawing sheets.  获取要导出一张或多张图纸的指定文件类型的数据接口。
GetFirstDocumentGets the document opened first in this SOLIDWORKS session.  获取在此 SOLIDWORKS 会话中首先打开的文档。
GetHoleStandardsDataGets the hole standards for the specified hole type.  获取指定孔类型的孔标准。
GetImageSizeGets:
small, medium, and large image sizes suitable for the current DPI setting of the display device.
default image size for the current DPI setting of the display device for images that are not based on the SOLIDWORKS icon size setting.
获取:
适合显示设备当前 DPI 设置的小、中和大图像尺寸。
对于不基于 SOLIDWORKS 图标大小设置的图像,显示设备当前 DPI 设置的默认图像大小。
GetImportFileDataGets the DXF/DWG, IGES, or STEP import data for the specified file.  获取指定文件的 DXF/DWG、IGES 或 STEP 导入数据。
GetInterfaceBrightnessThemeColorsGets the theme and colors of the SOLIDWORKS background.  获取 SOLIDWORKS 背景的主题和颜色。
GetLastSaveErrorGets the last save error issued by Microsoft in the current session.  获取 Microsoft 在当前会话中发出的最后一次保存错误。
GetLastToolbarIDGets the ID of the last toolbar added to the CommandManager.  获取添加到 CommandManager 的最后一个工具栏的 ID。
GetLatestSupportedFileVersionGets the version number that this instance of SOLIDWORKS reads and writes.  获取此 SOLIDWORKS 实例读取和写入的版本号。
GetLineStylesGets all of the line styles in the specified file.  获取指定文件中的所有线条样式。
GetLocalizedMenuNameGets a localized menu name for the specified menu ID.  获取指定菜单 ID 的本地化菜单名称。
GetMacroMethodsGets the names of the modules in the specified macro.  获取指定宏中模块的名称。
GetMassProperties2Gets the mass properties from the specified document for the specified configuration.  从指定文档中获取指定配置的质量属性。
GetMaterialDatabaseCountGets the number of material databases.  获取材料数据库的数量。
GetMaterialDatabasesGets the names of the material databases.  获取材料数据库的名称。
GetMaterialSchemaPathNameGets the path for the XML material schema file.  获取 XML 材料架构文件的路径。
GetMathUtilityGets IMathUtility.  获取 IMathUtility。
GetMenuStringsGets the name of the parent menu of the specified menu command.  获取指定菜单命令的父菜单的名称。
GetModelerGets the IModeler interface.  获取 IModeler 接口。
GetMouseDragModeGets whether the specified command-mouse mode is in effect.  获取指定的命令鼠标模式是否有效。
GetOpenDocSpecGets the specifications to use when opening a model document.  获取打开模型文档时要使用的规范。
GetOpenDocumentGets the open document with the specified name.  获取具有指定名称的打开文档。
GetOpenDocumentByNameGets the open document with the specified name.  获取具有指定名称的打开文档。
GetOpenedFileInfoGets the name of the last model successfully opened by SOLIDWORKS and the options that were in effect when it opened.  获取 SOLIDWORKS 成功打开的最后一个模型的名称以及打开时有效的选项。
GetOpenFileNamePrompts the user for the name of the file to open.  提示用户输入要打开的文件名。
GetPreviewBitmapGets the preview bitmap (.bmp) for the specified configuration, regardless if the SOLIDWORKS document is open or closed.  获取指定配置的预览位图 (.bmp),无论 SOLIDWORKS 文档是打开还是关闭。
GetPreviewBitmapFileGets the specified preview bitmap of a document and saves it as a Windows bitmap file (.bmp) using the specified filename.  获取文档的指定预览位图,并使用指定的文件名将其保存为 Windows 位图文件 (.bmp)。
GetProcessIDGets the process ID for the current SOLIDWORKS session.  获取当前 SOLIDWORKS 会话的进程 ID。
GetRayTraceRendererGet a ray-trace rendering engine, such as PhotoView 360.  获取光线跟踪渲染引擎,例如 PhotoView 360。
GetRecentFilesGets a list of the most recently used files.  获取最近使用的文件列表。
GetRoutingSettingsGets routing settings.  获取路由设置。
GetRunningCommandInfoGet a command's ID or PropertyManager page's command ID, title, and whether it is active in the user-interface.  获取命令的 ID 或 PropertyManager 页面的命令 ID、标题以及它是否在用户界面中处于活动状态。
GetSafeArrayUtilityGets the ISafeArrayUtility object.  获取 ISafeArrayUtility 对象。
GetSearchFoldersGets the current folder search path as shown in Tools > Options > System Options > File Locations > Show folders for > Referenced Documents.  获取当前文件夹搜索路径,如“工具”>“选项”>“系统选项”>“文件位置”>“显示文件夹”>“参考文档”所示。
GetSelectionFilterGets the current selection filter settings for the specified item type.  获取指定项目类型的当前选择过滤器设置。
GetSelectionFiltersGets all active selection filters.  获取所有活动的选择过滤器。
GetSSOFormattedURLFormats the specified URL for single sign-on.  为单点登录格式化指定的 URL。
GetTemplateSizesGets the sheet properties from a template document.  从模板文档中获取工作表属性。
GetToolbarDock2Gets the docking state of the toolbar.  获取工具栏的停靠状态。
GetToolbarState2Gets the state of the toolbar.  获取工具栏的状态。
GetToolbarVisibilityGets whether this toolbar is visible.  获取此工具栏是否可见。
GetUserPreferenceDoubleValueGets system default user preference values.  获取系统默认用户首选项值。
GetUserPreferenceIntegerValueGets system default user preference values.  获取系统默认用户首选项值。
GetUserPreferenceStringListValueGets the name of the DXF mapping file.  获取 DXF 映射文件的名称。
GetUserPreferenceStringValueGets system default user preference values.  获取系统默认用户首选项值。
GetUserPreferenceToggleGets document default user preference values.  获取文档默认用户首选项值。
GetUserProgressBarGets a progress indicator.  获取进度指示器。
GetUserTypeLibReferenceCountGets the number of user-specified type library references.  获取用户指定的类型库引用的数量。
GetUserUnitGets an empty IUserUnit object of the specified type.  获取指定类型的空 IUserUnit 对象。
HideBubbleTooltipHides the bubble ToolTip displayed by ISldWorks::ShowBubbleTooltipAt2.  隐藏由 ISldWorks::ShowBubbleTooltipAt2 显示的气泡工具提示。
HideToolbar2Hides a toolbar created with ISldWorks::AddToolbar5.  隐藏使用 ISldWorks::AddToolbar5 创建的工具栏。
IActivateDoc3Activates a document that has already been loaded. This file becomes the active document, and this method returns a pointer to that document object.  激活已加载的文档。此文件成为活动文档,此方法返回指向该文档对象的指针。
ICopyDocumentCopies a document and optionally updates references to it.  复制文档并可选择更新对其的引用。
ICreatePropertyManagerPageCreates a PropertyManager page.  创建 PropertyManager 页面。
IDefineAttributeCreates an attribute definition, which is the first step in generating attributes.  创建属性定义,这是生成属性的第一步。
IGetColorTableGets a color table from the SOLIDWORKS application.  从 SOLIDWORKS 应用程序获取颜色表。
IGetConfigurationNamesGets the names of the configuration in this SOLIDWORKS document, whether the document is opened or closed.  获取此 SOLIDWORKS 文档中配置的名称,无论该文档是打开还是关闭。
IGetDocumentDependencies2Gets all of the model dependencies for a document.  获取文档的所有模型依赖项。
IGetDocumentDependenciesCount2Gets the size of the array needed for a call to ISldWorks::IGetDocumetnDependencies2.  获取调用 ISldWorks::IGetDocumetnDependencies2 所需的数组大小。
IGetDocumentsGets the open documents is this SOLIDWORKS session.  获取SOLIDWORKS 会话中打开的文档。
IGetEnvironmentGets the IEnvironment object.  获取 IEnvironment 对象。
IGetFirstDocument2Gets the document opened first in this SOLIDWORKS session.  获取在此 SOLIDWORKS 会话中首先打开的文档。
IGetMassProperties2Gets the mass properties from the specified document for the specified configuration.  从指定文档中获取指定配置的质量属性。
IGetMaterialDatabasesGets the names of the material databases.  获取材料数据库的名称。
IGetMathUtilityGets the IMathUtility interface.  获取 IMathUtility 接口。
IGetModelerGets the IModeler interface.  获取 IModeler 接口。
IGetOpenDocumentByName2Gets the open document with the specified name.  获取具有指定名称的打开文档。
IGetRayTraceRendererGet a ray-trace rendering engine.  获取光线跟踪渲染引擎。
IGetSelectionFiltersGets all active selection filters.  获取所有活动的选择过滤器。
IGetSelectionFiltersCountGets the number of active selection filters.  获取活动选择过滤器的数量。
IGetTemplateSizesGets the sheet properties from a template document.  从模板文档中获取工作表属性。
IGetUserTypeLibReferencesGets the specified user-specified type library references.  获取指定的用户指定类型库引用。
IGetUserUnitGets an empty IUserUnit object of the specified type.  获取指定类型的空 IUserUnit 对象。
IGetVersionHistoryCountGets the size of the array required to hold data returned by ISldWorks::IVersionHistory.  获取保存 ISldWorks::IVersionHistory 返回的数据所需的数组大小。
IMoveDocumentMoves a document and optionally updates references to it.  移动文档并可选择更新对其的引用。
ImportHoleWizardItemImports data for the specified Hole Wizard standard.  为指定的异型孔向导标准导入数据。
ImportToolboxItemImports data for the specified Toolbox standard.  为指定的 Toolbox 标准导入数据。
INewDocument2Creates a new document based on the specified template.  基于指定的模板创建一个新文档。
InstallQuickTipGuideImplements your add-in's copy of the Quick Tips.  实施您的加载项的快速提示副本。
IRemoveUserTypeLibReferencesRemoves the user-specified type library references.  删除用户指定的类型库引用。
IsBackgroundProcessingCompletedGets whether SOLIDWORKS has finished background processing a drawing document that requires a lot of CPU time to open.  获取 SOLIDWORKS 是否已完成后台处理需要大量 CPU 时间才能打开的工程图文档。
IsCommandEnabledGets whether the specified command is enabled.  获取是否启用指定的命令。
ISetSelectionFiltersSets the status for multiple selection filters.  设置多选过滤器的状态。
ISetUserTypeLibReferencesSets the user-specified type library references.  设置用户指定的类型库引用。
IsRapidDraftGets whether the specified drawing file is in SOLIDWORKS Detached format.  获取指定的工程图文件是否为 SOLIDWORKS 分离格式。
IsSameGets whether the two specified objects are the same object.  获取指定的两个对象是否为同一个对象。
IVersionHistoryGets a list of strings indicating the versions in which a model was saved.  获取指示保存模型的版本的字符串列表。
LoadAddInLoads the specified add-in in SOLIDWORKS.  在 SOLIDWORKS 中加载指定的插件。
LoadFile4Loads a non-native file (for example, *.igs, *.dxf*.prt*.sat*.ipt*.step) into a new model document in SOLIDWORKS.  将非本地文件(例如,*.igs、*.dxf、*.prt、*.sat、*.ipt、*.step)加载到 SOLIDWORKS 中的新模型文档中。
MoveDocumentMoves a document and optionally updates references to it.  移动文档并可选择更新对其的引用。
NewDocumentCreates a new document based on the specified template.  基于指定的模板创建一个新文档。
OpenDoc6Opens an existing document and returns a pointer to the document object.  打开现有文档并返回指向文档对象的指针。
OpenDoc7Opens an existing document and returns a pointer to the document object.  打开现有文档并返回指向文档对象的指针。
PasteAppearanceApplies to the specified entity an appearance that has been copied to the clipboard.   将已复制到剪贴板的外观应用于指定实体。
PostMessageToApplicationPosts a message to the application that invoked this method.  向调用此方法的应用程序发布消息。
PostMessageToApplicationx64Posts a message to the application that invoked this method in 64-bit applications.  向在 64 位应用程序中调用此方法的应用程序发布消息。
PreSelectDwgTemplateSizeEstablishes which template to use when creating a drawing.  确定创建图纸时要使用的模板。
PresetNewDrawingParametersPresets the drawing template and sheet size parameters to avoid showing the Sheet Format/Size dialog when creating a new drawing document in the user-interface.  预设绘图模板和图纸尺寸参数,以避免在用户界面中创建新图纸文档时显示图纸格式/尺寸对话框。
PreviewDocDisplays a preview of a document to the specified window.  在指定窗口中显示文档预览。
PreviewDocx64Displays a preview of a document to the specified window in 64-bit applications.  在 64 位应用程序中的指定窗口中显示文档预览。
QuitDocCloses the specified document without saving changes.  关闭指定的文档而不保存更改。
RecordLineAdds a line of code to a VBA macro and the SOLIDWORKS journal file.  向 VBA 宏和 SOLIDWORKS 日志文件添加一行代码。
RecordLineCSharpAdds a line of code to a C# macro and the SOLIDWORKS journal file.  向 C# 宏和 SOLIDWORKS 日志文件添加一行代码。
RecordLineVBnetAdds a line of code to a VB.NET macro and the SOLIDWORKS journal file.  向 VB.NET 宏和 SOLIDWORKS 日志文件添加一行代码。
RefreshQuickTipWindowTells the SOLIDWORKS application that your add-in's state has changed and triggers a query for the current URL page.  告诉 SOLIDWORKS 应用程序您的插件状态已更改并触发对当前 URL 页面的查询。
RefreshTaskpaneContentRefreshes the view of the Design Library tab in the Task Pane.  刷新任务窗格中设计库选项卡的视图。
RegisterThirdPartyPopupMenuRegisters a third-party pop-up (shortcut) menu.  注册第三方弹出(快捷方式)菜单。
RegisterTrackingDefinitionRegisters a tracking definition.  注册跟踪定义。
RemoveCallbackUnregisters a general purpose callback handler.  取消注册通用回调处理程序。
RemoveFileOpenItem2Removes a file type from the File > Open dialog box that was added using ISldWorks::AddFileOpenItem3.  从使用 ISldWorks::AddFileOpenItem3 添加的文件 > 打开对话框中删除文件类型。
RemoveFileSaveAsItem2Removes a file type from the File > Save As dialog box that was added using ISldWorks::AddFileSaveAsItem2.  从使用 ISldWorks::AddFileSaveAsItem2 添加的文件 > 另存为对话框中删除文件类型。
RemoveFromMenuRemoves: 
the specified command from all main frame menus or a toolbar or both
the specified command's parent menus
删除:
来自所有主框架菜单或工具栏或两者的指定命令
指定命令的父菜单
RemoveFromPopupMenuRemoves the specified menu item from one or all specified context-sensitive menus (also called shortcut menus and pop-up menus) for the specified document types.  从指定文档类型的一个或所有指定上下文相关菜单(也称为快捷菜单和弹出菜单)中删除指定菜单项。
RemoveItemFromThirdPartyPopupMenuRemoves a menu item and icon from a third-party pop-up (shortcut) menu.  从第三方弹出(快捷方式)菜单中删除菜单项和图标。
RemoveMenuRemoves a menu item from the specified document frame.  从指定的文档框架中删除菜单项。
RemoveMenuPopupItem2Removes an item on a pop-up (shortcut) menu.  删除弹出(快捷方式)菜单上的项目。
RemoveToolbar2Removes a toolbar created with ISldWorks::AddToolbar5.  删除使用 ISldWorks::AddToolbar5 创建的工具栏。
RemoveUserTypeLibReferencesRemoves the user-specified type library references.  删除用户指定的类型库引用。
ReplaceReferencedDocumentReplaces a referenced document.  替换引用的文档。
ResetPresetDrawingParametersResets SOLIDWORKS back to its default behavior after calling ISldWorks::PresetNewDrawingParameters (i.e., display Sheet Format/Size dialog when opening a new drawing document).  在调用 ISldWorks::PresetNewDrawingParameters 后将 SOLIDWORKS 重置为其默认行为(即,在打开新工程图文档时显示图纸格式/尺寸对话框)。
ResetUntitledCountResets the index of untitled documents.  重置无标题文档的索引。
RestoreSettingsRestores the specified SOLIDWORKS settings from the specified *.sldreg file.  从指定的 *.sldreg 文件恢复指定的 SOLIDWORKS 设置。
ResumeSkinningResumes skinning windows.  恢复蒙皮窗口。
RevisionNumberGets the version number of this SOLIDWORKS installation.  获取此 SOLIDWORKS 安装的版本号。
RunAttachedMacroRuns the specified attached macro, module, and procedure.  运行指定的附加宏、模块和过程。
RunCommandRuns the specified SOLIDWORKS command.  运行指定的 SOLIDWORKS 命令。
RunJournalCmdDo not use.  不使用。
RunMacro2Runs a macro from a project file.  从项目文件运行宏。
SaveSettingsSaves the specified SOLIDWORKS settings to the specified *.sldreg file.  将指定的 SOLIDWORKS 设置保存到指定的 *.sldreg 文件。
SendMsgToUser2Displays a message box containing a message to the user, who is required to interact with it before continuing.  向用户显示一个包含消息的消息框,用户需要在继续之前与其进行交互。
SetAddinCallbackInfo2Sets add-in callback commands.  设置加载项回调命令。
SetApplySelectionFilterSets the current state of the selection filter.  设置选择过滤器的当前状态。
SetCurrentWorkingDirectorySets the current working directory to be used by SOLIDWORKS.  设置 SOLIDWORKS 使用的当前工作目录。
SetMissingReferencePathNameSets the missing reference file name. Use with the SOLIDWORKS event ReferenceNotFoundNotify.  设置缺少的参考文件名。与 SOLIDWORKS 事件 ReferenceNotFoundNotify 一起使用。
SetMouseDragModeSets the command-mouse mode.  设置命令鼠标模式。
SetMultipleFilenamesPromptSets the new filenames to open in response to the ISldWorks PromptForMultipleFileNamesNotify event.  设置新文件名以响应 ISldWorks PromptForMultipleFileNamesNotify 事件而打开。
SetNewFilenameSets the name of the new SOLIDWORKS file.  设置新 SOLIDWORKS 文件的名称。
SetPromptFilename2Sets the file to open in response to a SOLIDWORKS event.  设置文件以响应 SOLIDWORKS 事件而打开。
SetSearchFoldersSets the current folder search path as shown in Tools > Options > System Options > File Locations > Show folders for  > Referenced Documents.  设置当前文件夹搜索路径,如工具 > 选项 > 系统选项 > 文件位置 > 显示文件夹 > 参考文档所示。
SetSelectionFilterSets the current selection filter values for the specified item type.  设置指定项目类型的当前选择过滤器值。
SetSelectionFiltersSets the status for multiple selection filters.  设置多选过滤器的状态。
SetThirdPartyPopupMenuStateSets whether to show or hide a third-party popup (shortcut) menu.  设置是显示还是隐藏第三方弹出(快捷方式)菜单。
SetToolbarDock2Sets the docking state of the toolbar.  设置工具栏的停靠状态。
SetToolbarVisibilitySets whether the specified toolbar is visible.  设置指定的工具栏是否可见。
SetUserPreferenceDoubleValueSets system default user preference values.  设置系统默认用户首选项值。
SetUserPreferenceIntegerValueSets system default user preference values.  设置系统默认用户首选项值。
SetUserPreferenceStringListValueSets the name of the DXF mapping files.  设置 DXF 映射文件的名称。
SetUserPreferenceStringValueSets system default user preference values.  设置系统默认用户首选项值。
SetUserPreferenceToggleSets system default user preference values.  设置系统默认用户首选项值。
ShowBubbleTooltipDisplays a bubble ToolTip and flashes the specified toolbar button.  显示气泡工具提示并闪烁指定的工具栏按钮。
ShowBubbleTooltipAt2Displays a bubble ToolTip at the specified location.  在指定位置显示气泡工具提示。
ShowHelpDisplays the specified Help topic.  显示指定的帮助主题。
ShowThirdPartyPopupMenuSets where to show a third-party pop-up (shortcut) menu.  设置在何处显示第三方弹出(快捷方式)菜单。
SolidWorksExplorerStarts SOLIDWORKS Explorer.  启动 SOLIDWORKS Explorer。
UnInstallQuickTipGuideUninstalls your add-in's Quick Tips  卸载加载项的快速提示
UnloadAddInUnloads the specified add-in from SOLIDWORKS.  从 SOLIDWORKS 卸载指定的插件。
VersionHistoryGets a list of strings indicating the versions in which a model was saved.  获取指示保存模型的版本的字符串列表。

=========================================================================

object ActivateDoc3

        private void SW_Clear(object sender, RoutedEventArgs e)
        {
            //首先要打开Solidworks软件,加载Solidworks文档
            string name = "Part1.sldprt";  //当前打开文档中的其中一个文档的名称
            bool useUserPreferences = true;
            int option = (int)swRebuildOnActivation_e.swUserDecision;
            int error = 0;
            Object oblect= sld4Handler.SwApp.ActivateDoc3(name, useUserPreferences, option, error);
            if(oblect!=null)
            {
                ModelDoc2 model = (ModelDoc2)oblect;
                MessageBox.Show(model.GetPathName());
            }           
        }

此方法要求文档当前在您的 SOLIDWORKS 会话中打开。 它专门检查文档是否已在此会话中升级到 SOLIDWORKS 产品的当前版本。 如果没有,则此方法无效。

     private void SW_Read(object sender, RoutedEventArgs e)
        {
            //应用范例
            List<string> list = Sld4File.GetModleName(sld4Handler,false);
            int error = 0;
            foreach (var item in list)
            {
                sld4Handler.SwApp.ActivateDoc3(item.ToString(),false, (int)swRebuildOnActivation_e.swDontRebuildActiveDoc,ref error);
                MessageBox.Show(item.ToString());
            }
        } 
   

//获取当前打开文档的名称列表
        public static System.Collections.Generic.List<string> GetModleName(Sld4Handler sld4Handler, bool isPath = true)
        {
            System.Collections.Generic.List<string> list = new System.Collections.Generic.List<string>();
            EnumDocuments2 enumDocuments2 = sld4Handler.SwApp.EnumDocuments2();
            ModelDoc2 modelDoc2 = null;
            int nFetched = -1;
            enumDocuments2.Reset();
            do
            {
                enumDocuments2.Next(1, out modelDoc2, ref nFetched);
                if (modelDoc2 != null)
                {
                    string str0 = modelDoc2.GetPathName();
                    if (isPath == true && str0.Contains(@"\"))//名称存在路径的时候,截取获得最终所需的模型名
                    {
                        str0 = str0.Substring(str0.LastIndexOf(@"\") + 1, str0.Length - str0.LastIndexOf(@"\") - 1 - (str0.Length - str0.LastIndexOf(".")));
                    }
                    list.Add(str0);
                }
            } while (modelDoc2 != null);
            return list;
        }

 

 

=========================================================================

ActivateTaskPane

        private void SW_Clear(object sender, RoutedEventArgs e)
        {
            //首先要打开软件
            if(sld4Handler.SwApp.ActivateTaskPane((int)swTaskPaneTab_e.swFileExplorer))
            {
                MessageBox.Show("task pane is activated");
            }           
        }

=========================================================================

ArrangeWindows

        private void SW_Clear(object sender, RoutedEventArgs e)
        {
            //首先要打开软件,加载2个以上的文档
            sld4Handler.SwApp.ArrangeWindows(0);
            MessageBox.Show("Cascade");
            sld4Handler.SwApp.ArrangeWindows(1);
            MessageBox.Show("Tile horizontally");
            sld4Handler.SwApp.ArrangeWindows(2);
            MessageBox.Show("Tile vertically");

        }

=========================================================================

CheckpointConvertedDocument

VersionHistory

OpenDoc6

CloseAllDocuments(IncludeUnsaved=true,关闭所有文件     IncludeUnsaved=false,关闭有更改外的所有文件

        private void SW_Clear(object sender, RoutedEventArgs e)
        {
            //首先要打开软件,前后显示保存前后的软件版本
            {
                string[] version = (string[])sld4Handler.SwApp.VersionHistory((@"G:\SW\ADD DRAFT.sldprt"));
                MessageBox.Show(version[version.Length-1].ToString());
            }
            int errors = 0, warnings = 0;
            sld4Handler.ModelDoc = sld4Handler.SwApp.OpenDoc6(@"G:\SW\ADD DRAFT.sldprt", (int)swDocumentTypes_e.swDocPART, (int)swOpenDocOptions_e.swOpenDocOptions_ReadOnly, "", ref errors, ref warnings);
            if (sld4Handler.ModelDoc == null) return;
                int error = sld4Handler.SwApp.CheckpointConvertedDocument(@"G:\SW\ADD DRAFT.sldprt");
            if (error == 0)
            {
                string[] newversion = (string[])sld4Handler.SwApp.VersionHistory((@"G:\SW\ADD DRAFT.sldprt"));
                MessageBox.Show(newversion[newversion.Length - 1].ToString());
            }
            else
                MessageBox.Show(((swFileSaveError_e)error).ToString());
     sld4Handler.SwApp.CloseAllDocuments(true);
        }

=========================================================================

CloseDoc

        private void SW_Clear(object sender, RoutedEventArgs e)
        {
            sld4Handler.ModelDoc = sld4Handler.SwApp.ActiveDoc;
            string name = sld4Handler.ModelDoc.GetPathName();
            sld4Handler.SwApp.CloseDoc(name);

        }

=======================================================================

CopyDocument

复制的源文件不能打开。


            int result= sld4Handler.SwApp.CopyDocument(@"G:\标准件(20210908)\标准件\其余\水滴指针 26.SLDPRT", @"G:\标准件(20210908)\标准件\复制文件.SLDPRT", null, null, (int)swMoveCopyOptions_e.swMoveCopyOptionsCreateNewFolder);
            MessageBox.Show(((swMoveCopyError_e)result).ToString());

==============================================================================================

DisplayStatusBar

 OnOff:True if you want the status bar displayed, false if not

bool flag = false;

        private void SW_Clear(object sender, RoutedEventArgs e)
        {
            flag = !flag;
            sld4Handler.SwApp.DisplayStatusBar(flag);
        }

=========================================================================

DocumentVisible

此方法是一个标志,允许您在加载文档时显示或隐藏文档。

=========================================================================

 EnumDocuments2

     private void SW_Read(object sender, RoutedEventArgs e)
        {
            //应用范例
            List<string> list = Sld4File.GetModleName(sld4Handler, false);
            foreach (var item in list)
            {
                  MessageBox.Show(item.ToString());
            }
        } 
   

//获取当前打开文档的名称列表
        public static System.Collections.Generic.List<string> GetModleName(Sld4Handler sld4Handler, bool isPath = true)
        {
            System.Collections.Generic.List<string> list = new System.Collections.Generic.List<string>();
            EnumDocuments2 enumDocuments2 = sld4Handler.SwApp.EnumDocuments2();
            ModelDoc2 modelDoc2 = null;
            int nFetched = -1;
            enumDocuments2.Reset();
            do
            {
                enumDocuments2.Next(1, out modelDoc2, ref nFetched);
                if (modelDoc2 != null)
                {
                    string str0 = modelDoc2.GetPathName();
                    if (isPath == true && str0.Contains(@"\"))//名称存在路径的时候,截取获得最终所需的模型名
                    {
                        str0 = str0.Substring(str0.LastIndexOf(@"\") + 1, str0.Length - str0.LastIndexOf(@"\") - 1 - (str0.Length - str0.LastIndexOf(".")));
                    }
                    list.Add(str0);
                }
            } while (modelDoc2 != null);
            return list;
        }

=========================================================================

ExitApp

=========================================================================

GetActiveConfigurationName

        private void SW_Clear(object sender, RoutedEventArgs e)
        {
            ModelDoc2 modelDoc = sld4Handler.SwApp.ActiveDoc;
            string path = modelDoc.GetPathName();
           
            string s=sld4Handler.SwApp.GetActiveConfigurationName(path);
            MessageBox.Show(s);
        }

=========================================================================

GetBuildNumbers2

        private void SW_Clear(object sender, RoutedEventArgs e)
        {
            string BaseVersion = null;
            string CurrentVersion = null;
            string HotFixes = null;

            sld4Handler.SwApp.GetBuildNumbers2(out BaseVersion, out CurrentVersion, out HotFixes);
            MessageBox.Show("BaseVersion:"+ BaseVersion+"\n"+ "CurrentVersion:" + CurrentVersion + "\n" + "HotFixes:" + HotFixes + "\n");
        }

=========================================================================

GetConfigurationCount

        private void SW_Clear(object sender, RoutedEventArgs e)
        {
            int i=sld4Handler.SwApp.GetConfigurationCount(((ModelDoc2)(sld4Handler.SwApp.ActiveDoc)).GetPathName())           ;
            MessageBox.Show(i.ToString());
        }

=========================================================================

GetConfigurationNames

        private void SW_Clear(object sender, RoutedEventArgs e)
        {
            string[] s=(string[])sld4Handler.SwApp.GetConfigurationNames(((ModelDoc2)(sld4Handler.SwApp.ActiveDoc)).GetPathName());
            for (int i = 0; i < s.Length; i++)
            {
                MessageBox.Show(s[i]);
            }            
        }

=========================================================================

GetCurrentFileUser

        private void SW_Clear(object sender, RoutedEventArgs e)
        {
            string s=sld4Handler.SwApp.GetCurrentFileUser(((ModelDoc2)(sld4Handler.SwApp.ActiveDoc)).GetPathName());
            MessageBox.Show(s);           
        }

=========================================================================

GetCurrentLanguage

        private void SW_Clear(object sender, RoutedEventArgs e)
        {
            string s = sld4Handler.SwApp.GetCurrentLanguage();
            MessageBox.Show(s);           
        }

=========================================================================

GetCurrentLicenseType

        private void SW_Clear(object sender, RoutedEventArgs e)
        {
            int i = sld4Handler.SwApp.GetCurrentLicenseType();
            MessageBox.Show(((swLicenseType_e)i).ToString());           
        }

=========================================================================

GetCurrentWorkingDirectory

        private void SW_Clear(object sender, RoutedEventArgs e)
        {
            string s = sld4Handler.SwApp.GetCurrentWorkingDirectory();
            MessageBox.Show(s);           
        }

=========================================================================

GetDataFolder

        private void SW_Clear(object sender, RoutedEventArgs e)
        {
            string s = sld4Handler.SwApp.GetDataFolder(true);
            MessageBox.Show(s);           
        }

=========================================================================

GetDocumentCount

        private void SW_Clear(object sender, RoutedEventArgs e)
        {
           int i = sld4Handler.SwApp.GetDocumentCount();(sld4Handler.SwApp.ActiveDoc)).GetPathName());
            MessageBox.Show(i.ToString());           
        }

=========================================================================

GetDocumentDependencies2

//This example shows how to copy a document and its dependencies to this macro's folder.

//---------------------------------------------------------------------------
// Preconditions: Open an assembly document.
//
// Postconditions:
// 1. Closes the assembly document.
// 2. Copies the assembly document and its dependencies to the macro folder.
// 3. Examine the macro folder.
//---------------------------------------------------------------------------
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 GetCurrentMacroPathName_CSharp.csproj
{
    partial class SolidWorksMacro
    {

        public void Main()
        {
            string source = null;
            string target = null;
            string sourcefile = null;
            string tempfile = null;
            bool traverse = false;
            bool search = false;
            bool addreadonlyinfo = false;
            object[] depends = null;
            string[] sourcefiles = null;
            string[] targetfiles = null;
            int idx = 0;
            int sourcecount = 0;
            int copyopt = 0;
            int errors = 0;
            int lind = 0;
            ModelDoc2 doc = default(ModelDoc2);

            doc = (ModelDoc2)swApp.ActiveDoc;

            source = swApp.GetCurrentWorkingDirectory();    //工作目录
            sourcefile = doc.GetPathName();    //完整路径和文件名

            tempfile = swApp.GetCurrentMacroPathName();
            lind = tempfile.LastIndexOf("\\");
            target = tempfile.Substring(0, lind);

            traverse = true;
            search = true;
            addreadonlyinfo = false;

             //完整路径和文件名,遍历标志,搜索标志,添加只读信息标志
            //返回文档名称和带有完整路径名的文件名
            depends = (object[])swApp.GetDocumentDependencies2(sourcefile, traverse, search, addreadonlyinfo);

            if ((depends == null))
                return;

            idx = 1;

            while (idx <= depends.GetUpperBound(0))
            {
                Array.Resize(ref sourcefiles, sourcecount + 1);
                Array.Resize(ref targetfiles, sourcecount + 1);

                sourcefiles[sourcecount] = (string)depends[idx];
                lind = sourcefiles[sourcecount].LastIndexOf("\\");
                targetfiles[sourcecount] = target + sourcefiles[sourcecount].Substring(lind, sourcefiles[sourcecount].Length - lind);

                sourcecount = sourcecount + 1;
                idx = idx + 2;
            }

            swApp.CloseAllDocuments(true);

            copyopt = (int)swMoveCopyOptions_e.swMoveCopyOptionsOverwriteExistingDocs;
            errors = swApp.CopyDocument(source + sourcefile, target + sourcefile, (sourcefiles), (targetfiles), (int)copyopt);

        }

        public SldWorks swApp;

    }
} 

=========================================================================

GetDocuments

        private void SW_Clear(object sender, RoutedEventArgs e)
        {
           object[] files=(object[])sld4Handler.SwApp.GetDocuments();
            int count = sld4Handler.SwApp.GetDocumentCount();
            for (int i = 0; i < count; i++)
            {
                MessageBox.Show(((ModelDoc2)files[i]).GetPathName().ToString());
            }                  
        }

=========================================================================

GetDocumentVisible

        private void SW_Clear(object sender, RoutedEventArgs e)
        {
           if(sld4Handler.SwApp.GetDocumentVisible((int)swDocumentTypes_e.swDocPART))
            MessageBox.Show("the document will be visible when opened");                
        }

=========================================================================

GetErrorMessages

=========================================================================

GetExecutablePath

        private void SW_Clear(object sender, RoutedEventArgs e)
        {
            MessageBox.Show(sld4Handler.SwApp.GetExecutablePath());
        }

=========================================================================

GetFirstDocument

        private void SW_Clear(object sender, RoutedEventArgs e)
        {
            MessageBox.Show(((ModelDoc2)sld4Handler.SwApp.GetFirstDocument()).GetPathName());
        }

=========================================================================

GetLatestSupportedFileVersion

        private void SW_Clear(object sender, RoutedEventArgs e)
        {
            int vision = sld4Handler.SwApp.GetLatestSupportedFileVersion();
            string s = "";
            switch (vision)
            {
                case 44: s= "SLIDWORKS 95"; break;
                case 243: s = "SOLIDWORKS 96 "; break;
                case 483: s = "SLIDWORKS 97"; break;
                case 629: s = "SOLIDWORKS 97Plus"; break;
                case 822: s = "SOLIDWORKS 98"; break;
                case 1008: s = "SOLIDWORKS 98Plus"; break;
                case 1137: s = "SOLIDWORKS 99"; break;
                case 1500: s = "SOLIDWORKS 2000"; break;
                case 1750: s = "SOLIDWORKS 2001"; break;
                case 1950: s = "SOLIDWORKS 2001Plus"; break;
                case 2200: s = "SOLIDWORKS 2003"; break;
                case 2500: s = "SOLIDWORKS 2004"; break;
                case 2800: s = "SOLIDWORKS 2005"; break;
                case 3100: s = "SOLIDWORKS 2006 "; break;
                case 3400: s = "SOLIDWORKS 2007"; break;
                case 3800: s = "SOLIDWORKS 2008 "; break;
                case 4100: s = "SOLIDWORKS 2009"; break;
                case 4400: s = " SOLIDWORKS 2010"; break;
                case 4700: s = " SOLIDWORKS 2011"; break;
                case 5000: s = "SOLIDWORKS 2012"; break;
                case 6000: s = " SOLIDWORKS 2013"; break;
                case 7000: s = " SOLIDWORKS 2014"; break;
                case 8000: s = "SOLIDWORKS 2015"; break;
                case 9000: s = "SOLIDWORKS 2016"; break;
                case 10000: s = "SOLIDWORKS 2017"; break;
                case 11000: s = "SOLIDWORKS 2018"; break;
                case 12000: s = "SOLIDWORKS 2019"; break;
                default: s = "";                    break;
            }
            MessageBox.Show(s);
        }

=========================================================================

GetMassProperties2

        private void SW_Clear(object sender, RoutedEventArgs e)
        {
            string s = "";
            string path = sld4Handler.ModelDoc.GetPathName();
            double[] reslut = (double[])sld4Handler.SwApp.GetMassProperties2(path, "默认", 1);
            for (int i = 0; i < reslut.Length; i++)
            {
                s += reslut[i].ToString() + "\n";
            }
            MessageBox.Show("结果数组:质心坐标 x,y,z +体积+表面积+质量+XX+YY+ZZ+XY+ZX+YZ"+"\n");
            MessageBox.Show(s.ToString());
        }

=========================================================================

GetOpenDocument

        private void SW_Clear(object sender, RoutedEventArgs e)
        {            
            MessageBox.Show(sld4Handler.SwApp.GetOpenDocument(@"G:\标准件(20210908)\标准件\其余\水滴指针 26.Sldprt").GetPathName());
        }

=========================================================================

GetOpenDocumentByName

        private void SW_Clear(object sender, RoutedEventArgs e)
        {            
            MessageBox.Show(((ModelDoc2)sld4Handler.SwApp.GetOpenDocumentByName(@"G:\标准件(20210908)\标准件\其余\水滴指针 26.Sldprt")).GetPathName());
        }

=========================================================================

GetOpenedFileInfo

        private void SW_Clear(object sender, RoutedEventArgs e)
        {
            string file = null;
            int options = 0;
            sld4Handler.SwApp.GetOpenedFileInfo(out file, out options);
            MessageBox.Show(file+" "+((swOpenDocOptions_e)options).ToString());
        }

=========================================================================

GetOpenFileName

This example shows how to prompt the user for the name of the file to open. This example also shows how to set up filters by file types.

'---------------------------------------------------------
' Preconditions: Open the Immediate window.
'
' Postconditions:
' 1. Displays the File to Attach dialog and lists the file
'    types specified in the filter.
' 2. Examine the Immediate window.
'----------------------------------------------------------
Option Explicit
Public swApp As SldWorks.SldWorks
Public swModel As SldWorks.ModelDoc2
Sub main()
    Dim Filter As String
    Dim fileName As String
    Dim fileConfig As String
    Dim fileDispName As String
    Dim fileOptions As Long    
    Set swApp = Application.SldWorks
    ' The Filter string has three filters
    ' associated with it; note the use of
    ' the | character between filters
    Filter = "SOLIDWORKS Files (*.sldprt; *.sldasm; *.slddrw)|*.sldprt;*.sldasm;*.slddrw|Filter name (*.fil)|*.fil|All Files (*.*)|*.*|"
    fileName = swApp.GetOpenFileName("File to Attach", "", Filter, fileOptions, fileConfig, fileDispName)
    Debug.Print fileName
End Sub

=========================================================================

GetProcessID

        private void SW_Clear(object sender, RoutedEventArgs e)
        {
            MessageBox.Show(sld4Handler.SwApp.GetProcessID().ToString());
        }

========================================================================

GetRecentFiles

        private void SW_Clear(object sender, RoutedEventArgs e)
        {
           object file= sld4Handler.SwApp.GetRecentFiles();
            string[] files = (string[])file;
            string s = "";
            for (int i = 0; i < files.Length; i++)
            {
                s += files[i] + "\n";
            }
            MessageBox.Show(s);
        }

=========================================================================

GetSearchFolders

        private void SW_Clear(object sender, RoutedEventArgs e)
        {
            MessageBox.Show(
            sld4Handler.SwApp.GetSearchFolders((int)swSearchFolderTypes_e.swDocumentType));
        }

=========================================================================

IActivateDoc3

        private void SW_Clear(object sender, RoutedEventArgs e)
        {
            string path = ((ModelDoc2)(sld4Handler.SwApp.ActiveDoc)).GetPathName();
            if (path == null) return;
            int Errors = 0;
            ModelDoc2 modelDoc = sld4Handler.SwApp.IActivateDoc3(path, false, out Errors);
            MessageBox.Show(modelDoc.GetPathName());
        }

=========================================================================

IGetOpenDocumentByName2

        private void SW_Clear(object sender, RoutedEventArgs e)
        {
            string path = ((ModelDoc2)(sld4Handler.SwApp.ActiveDoc)).GetPathName();
            if (path == null) return;
            ModelDoc2 modelDoc = sld4Handler.SwApp.IGetOpenDocumentByName2(path);
            MessageBox.Show(modelDoc.GetPathName());
        }

=========================================================================

IMoveDocument

        private void SW_Clear(object sender, RoutedEventArgs e)
        {
            string FromChildren = null, ToChildren = null;
            int returnValve= sld4Handler.SwApp.IMoveDocument(@"G:\标准件(20210908)\标准件\其余\三角刻度指针.sldprt", @"G:\标准件(20210908)\标准件\IMoveDocument复制.sldprt",0,ref FromChildren,ref ToChildren,(int)swMoveCopyOptions_e.swMoveCopyOptionsCreateNewFolder);
            MessageBox.Show(((swMoveCopyError_e)returnValve).ToString());
        }

=========================================================================

INewDocument2

        private void SW_Clear(object sender, RoutedEventArgs e)
        {
            ModelDoc2  modelDoc= sld4Handler.SwApp.INewDocument2(@"G:\标准件(20210908)\设计库\Expert模板\Expert_A4p.drwdot", (int)swDwgPaperSizes_e.swDwgPaperA4size,297.0,210.0);
            MessageBox.Show(modelDoc.GetPathName());
        }

=========================================================================

IsRapidDraft

        private void SW_Clear(object sender, RoutedEventArgs e)
        {
            if(sld4Handler.SwApp.IsRapidDraft(@"G:\标准件(20210908)\RapidDraft.slddrw"))
            MessageBox.Show(" the file is in RapidDraft format");
        }

=========================================================================

IsSame

//This example shows how to determine if two selected entities are the same entities and //if those entities have the same persistent IDs. 

//NOTE: Using IModelDocExtension::IsSamePersistentID and ISldWorks::IsSame might be //helpful when your application is passed two entities that it didn't select, and your //application needs to know if they're the same entity.

//----------------------------------------------------------------------------
// Preconditions: 
// 1. Open a part document is open and select two
//    different entities (e.g., face, edge, vertex, etc.).
// 2. Open the Immediate window.
//
// Postconditions:
// 1. Compares the selected entities.
// 2. Examine the code and Immediate window.
//------------------------------------
using SolidWorks.Interop.sldworks;
using SolidWorks.Interop.swconst;
using System;
using System.Diagnostics;
 
namespace Macro1CSharp.csproj
{
    partial class SolidWorksMacro
    {
        public void Main()
        {
 
            ModelDoc2 swModel = default(ModelDoc2);
            SelectionMgr swSelMgr = default(SelectionMgr);
            ModelDocExtension swModelDocExt = default(ModelDocExtension);
            object selObj1 = null;
            object selObj2 = null;
            object selObjPID1 = null;
            object selObjPID2 = null;
 
            swModel = (ModelDoc2)swApp.ActiveDoc;
            swSelMgr = (SelectionMgr)swModel.SelectionManager;
            swModelDocExt = swModel.Extension;
 
            // Get the selected objects 
            selObj1 = swSelMgr.GetSelectedObject6(1, -1);
            selObj2 = swSelMgr.GetSelectedObject6(2, -1);
            Debug.Print("Compare the selected objects:");
            switch (swApp.IsSame(selObj1, selObj2))
            {
                case 0:
                    Debug.Print(" Selected objects are not the same.");
                    break;
                case 1:
                    Debug.Print(" Selected objects are the same.");
                    break;
                case -1:
                    Debug.Print(" Unable to determine if selected objects are the same.");
                    break;
            }
 
            Debug.Print("");
 
            Debug.Print("Compare the same objects:");
            switch (swApp.IsSame(selObj1, selObj1))
            {
                case 0:
                    Debug.Print(" Selected objects are not the same.");
                    break;
                case 1:
                    Debug.Print(" Selected objects are the same.");
                    break;
                case -1:
                    Debug.Print(" Unable to determine if selected objects are the same.");
                    break;
            }
 
            Debug.Print("");
 
            // Get the persistent reference IDs of the 
            // selected objects 
            selObjPID1 = swModelDocExt.GetPersistReference3(selObj1);
            selObjPID2 = swModelDocExt.GetPersistReference3(selObj2);
            Debug.Print("Compare the persistent reference IDs of the selected objects:");
            switch (swModelDocExt.IsSamePersistentID(selObjPID1, selObjPID2))
            {
                case 0:
                    Debug.Print(" Selected objects do not have the same persistent reference ID.");
                    break;
                case 1:
                    Debug.Print(" Selected objects do have the same persistent reference ID.");
                    break;
                case -1:
                    Debug.Print(" Unable to determine if the selected objects have the same persistent reference ID.");
                    break;
            }
 
            Debug.Print("");
 
            Debug.Print("Compare the persistent reference IDs of the same objects:");
            switch (swModelDocExt.IsSamePersistentID(selObjPID1, selObjPID1))
            {
                case 0:
                    Debug.Print(" Selected objects do not have the same persistent reference ID.");
                    break;
                case 1:
                    Debug.Print(" Selected objects do have the same persistent reference ID.");
                    break;
                case -1:
                    Debug.Print(" Unable to determine if the selected objects have the same persistent reference ID.");
                    break;
            }
        }
        public SldWorks swApp;
    }
}

=========================================================================

OpenDoc6

        private void SW_Clear(object sender, RoutedEventArgs e)
        {
            int error = 0, warnings = 0;
            ModelDoc2 modelDoc1 = sld4Handler.SwApp.OpenDoc6(@"G:\标准件(20210908)\标准件\其余\三角指针.sldprt", (int)swDocumentTypes_e.swDocPART, (int)swOpenDocOptions_e.swOpenDocOptions_ReadOnly, "", error, warnings);
            ModelDoc2 modelDoc2 = sld4Handler.SwApp.OpenDoc6(@"G:\标准件(20210908)\标准件\其余\水滴指针 26.sldprt", (int)swDocumentTypes_e.swDocPART, (int)swOpenDocOptions_e.swOpenDocOptions_ReadOnly, "", error, warnings);
            int result = sld4Handler.SwApp.IsSame(modelDoc1, modelDoc2);
            MessageBox.Show(((swObjectEquality)result).ToString());
        }

=========================================================================

OpenDoc7

//This example shows how to specify how to open an assembly document.

//------------------------------------------------------
// Preconditions: Verify that the specified assembly document
// to open exists.
//
// Postconditions:
// 1. If the Large Design Review dialog is displayed, click OK
//    to close it.
// 2. Opens the specified assembly document and loads
//    and displays the specified component.
// 3. Examine the graphics area.
//
// NOTE: Because the model 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);
            DocumentSpecification swDocSpecification = default(DocumentSpecification);
            string[] componentsArray = new string[1];
            object[] components = null;
            string name = null;
            int errors = 0;
            int warnings = 0; 
 
            //Set the specifications
            swDocSpecification = (DocumentSpecification)swApp.GetOpenDocSpec("C:\\Users\\Public\\Documents\\SOLIDWORKS\\SOLIDWORKS 2018\\samples\\tutorial\\advdrawings\\bowl and chute.sldasm");
            componentsArray[0] = "food bowl-1@bowl and chute";
            components = (object[])componentsArray;
            swDocSpecification.ComponentList = components;
            swDocSpecification.Selective = true;
            name = swDocSpecification.FileName;
            swDocSpecification.DocumentType = (int)swDocumentTypes_e.swDocASSEMBLY;
            swDocSpecification.DisplayState = "Default_Display State-1";
            swDocSpecification.UseLightWeightDefault = false;
            swDocSpecification.LightWeight = true;
            swDocSpecification.Silent = true;
            swDocSpecification.IgnoreHiddenComponents = true;
 
            //Open the assembly document as per the specifications
            swModel = (ModelDoc2)swApp.OpenDoc7(swDocSpecification);
            errors = swDocSpecification.Error;
            warnings = swDocSpecification.Warning; 
 
        }
 
        /// <summary>
        ///  The SldWorks swApp variable is pre-assigned for you.
        /// </summary>
        public SldWorks swApp;
    }
}

=========================================================================

MoveDocument

        private void SW_Clear(object sender, RoutedEventArgs e)
        {
            sld4Handler.SwApp.MoveDocument(@"G:\标准件(20210908)\标准件\其余\三角指针.sldprt", @"G:\标准件(20210908)\标准件\其余\MoveDocument三角指针.sldprt",null,null,(int)swMoveCopyOptions_e.swMoveCopyOptionsCreateNewFolder);
        }

=========================================================================

NewDocument

This example shows how create to a new part with an imported body from the processed body of the original part.

//------------------------------------------------
// Preconditions:
// 1. Verify that the specified part document template
//    exists.
// 2. Open a part containing only one solid body.
// 3. Open the Immediate window.
// 4. Run the macro.
//
// Postconditions:
// 1. Creates a new part with an imported body
//    from the processed body of the original part.
// 2. Examine the Immediate window.
//
// NOTE: Differences are best seen in wireframe and with parts
// that contain curved, circular, or both types of faces.
//--------------------------------------------------
 
using SolidWorks.Interop.sldworks;
using SolidWorks.Interop.swconst;
using System.Runtime.InteropServices;
using System;
using System.Diagnostics;
 
namespace ProcessbodyCSharp.csproj
{
    public partial class SolidWorksMacro
    {
        public void Main()
        {
            // 1 radian = 180º/p = 57.295779513º or approximately 57.3º 
            const double RadPerDeg = 1.0 / 57.3;
            const double MaxUAngle = 1.0 * RadPerDeg;
            const double MaxVAngle = 1.0 * RadPerDeg;
 
            ModelDoc2 swModel = default(ModelDoc2);
            Body2 swBody = default(Body2);
            Body2 swProcBody = default(Body2);
            PartDoc swPart = default(PartDoc);
            PartDoc swNewPart = default(PartDoc);
            Feature swFeat = default(Feature);
            object[] vBodies = null;
 
            swModel = (ModelDoc2)swApp.ActiveDoc;
            swPart = (PartDoc)swModel;
            vBodies = (object[])swPart.GetBodies2((int)swBodyType_e.swSolidBody, false);
            swBody = (Body2)vBodies[0];
            swProcBody = (Body2)swBody.GetProcessedBody2(MaxUAngle, MaxVAngle);
            swNewPart = (PartDoc)swApp.NewDocument("C:\\ProgramData\\SOLIDWORKS\\SOLIDWORKS 2013\\templates\\part.prtdot", 0, 0, 0);
            swFeat = (Feature)swNewPart.CreateFeatureFromBody3(swProcBody, false, (int)swCreateFeatureBodyOpts_e.swCreateFeatureBodyCheck);
            Debug.Print("File = " + swModel.GetPathName());
            Debug.Print("  Body faces            = " + swBody.GetFaceCount());
            Debug.Print("  Processed body faces  = " + swProcBody.GetFaceCount());
 
 
 
        }
 
        /// <summary>
        ///  The SldWorks swApp variable is pre-assigned for you.
        /// </summary>
        public SldWorks swApp;
    }
}

=========================================================================

QuitDoc

        private void SW_Clear(object sender, RoutedEventArgs e)
        {
           string path=((ModelDoc2)sld4Handler.SwApp.ActiveDoc).GetPathName();
            sld4Handler.SwApp.QuitDoc(path);
        }

=========================================================================

ReplaceReferencedDocument

This example shows how to replace a referenced document with a different document in an assembly.

'---------------------------------------------------------------------------------------------------
' Preconditions:
' 1. Create C:\temp\blade shaft.
' 2. Copy these files from C:\Users\Public\Documents\SOLIDWORKS\SOLIDWORKS 2018\samples\tutorial\advdrawings
'    to C:\temp\blade shaft:
'    * blade shaft.sldasm
'    * drive shaft.sldprt
'    * drive shaft pin.sldprt
'    * drive shaft plate.sldprt
' 3. Open C:\temp\blade shaft\drive shaft.sldprt and save the file as drive shaft2.sldprt.
' 4. Close drive shaft2.sldprt.
' 5. Open the Immediate window.
'
' Postconditions:
' 1. Replaces C:\temp\blade shaft\drive shaft.sldprt with C:\temp\blade shaft\drive shaft2.sldprt.
' 2. Examine the Immediate window and open C:\temp\blade shaft\blade shaft.sldasm, click Rebuild,
'    click File > Find References and examine the files listed under Name.
'------------------------------------------------------------------------------------------------------
Option Explicit
Const sReferencingDoc As String = "C:\temp\blade shaft\blade shaft.sldasm"
Const sOldDoc As String = "C:\temp\blade shaft\drive shaft.sldprt"
Const sNewDoc As String = "C:\temp\blade shaft\drive shaft2.sldprt"
Sub main()
    Dim swApp As SldWorks.SldWorks
    Dim bRet As Boolean
    Set swApp = CreateObject("SldWorks.Application")
    bRet = swApp.ReplaceReferencedDocument(sReferencingDoc, sOldDoc, sNewDoc)
    Debug.Print ("Reference to drive shaft.sldprt replaced with reference to drive shaft2.sldprt? " & bRet)
    
End Sub

=========================================================================

RevisionNumber

        private void SW_Clear(object sender, RoutedEventArgs e)
        {
            MessageBox.Show(sld4Handler.SwApp.RevisionNumber());
        }

=========================================================================

SendMsgToUser2

        private void SW_Clear(object sender, RoutedEventArgs e)
        {
            sld4Handler.SwApp.SendMsgToUser2("I am sending msg",(int)swMessageBoxIcon_e.swMbWarning,(int)swMessageBoxBtn_e.swMbOk);
        }

=========================================================================

SetCurrentWorkingDirectory

This example shows how to programmatically open a document and set the SOLIDWORKS working directory.

//---------------------------------------------------------------------------
// Preconditions: 
// 1. Verify that the specified document to open exists.
// 2. Open the Immediate window.
//
// Postconditions:
// 1. Opens the specified document.
// 2. Sets the SOLIDWORKS working directory to the document directory.
// 3. Examine the 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 SetWorkingDirectory_CSharp.csproj
{
    partial class SolidWorksMacro
    {

        ModelDoc2 doc;
        int fileerror;
        int filewarning;

        public void Main()
        {
            swApp.Visible = true;

            // Get the current working directory before opening the document
            Debug.Print("Current working directory is " + swApp.GetCurrentWorkingDirectory());

            doc = swApp.OpenDoc6("C:\\Users\\Public\\Documents\\SOLIDWORKS\\SOLIDWORKS 2018\\samples\\tutorial\\api\\chair.sldprt", (int)swDocumentTypes_e.swDocPART, (int)swOpenDocOptions_e.swOpenDocOptions_Silent, "", ref fileerror, ref filewarning);

            // Opening a document with SldWorks::OpenDoc6 does not set the working directory
            Debug.Print("Current working directory is still " + swApp.GetCurrentWorkingDirectory());

            // Set the working directory to the document directory
            swApp.SetCurrentWorkingDirectory(doc.GetPathName().Substring(0, doc.GetPathName().LastIndexOf("\\")));

            Debug.Print("Current working directory is now " + swApp.GetCurrentWorkingDirectory());

        }

        public SldWorks swApp;

    }
} 

=========================================================================

SetNewFilename

        private void SW_Clear(object sender, RoutedEventArgs e)
        {
            if (sld4Handler.SwApp.SetNewFilename(@"G:\标准件(20210908)\标准件\其余\SetNewFilename.sldprt") ==true)
                MessageBox.Show("true");
        }

不大明白什么用,貌似判断文件名的有效性。

=========================================================================

SetSearchFolders

//This example shows how to get and set the file locations in which SOLIDWORKS searches for reference documents.

//----------------------------------------------------------------------------
// Preconditions: Open the Immediate window.
//
// Postconditions:
// 1. Adds c:\; to the beginning of the search folder path for reference
//    documents.
// 2. Examine the Immediate window.
//
// NOTE: This macro changes your SOLIDWORKS search folders system settings.
// ---------------------------------------------------------------------------
using SolidWorks.Interop.sldworks;
using SolidWorks.Interop.swconst;
using System.Runtime.InteropServices;
using System;
using System.Diagnostics;
namespace Macro1CSharp.csproj
{
    partial class SolidWorksMacro
    {
 
        ModelDoc2 Part;
        string searchFolders;
 
        bool boolstatus;
 
        public void Main()
        {
            Part = (ModelDoc2)swApp.ActiveDoc;
 
            swApp.SetUserPreferenceToggle((int)swUserPreferenceToggle_e.swUseFolderSearchRules, false);
 
            searchFolders = swApp.GetSearchFolders((int)swSearchFolderTypes_e.swDocumentType);
            Debug.Print("Current search path: " + searchFolders);
            searchFolders = "c:\\;" + searchFolders;
            boolstatus = swApp.SetSearchFolders((int)swSearchFolderTypes_e.swDocumentType, searchFolders);
            searchFolders = swApp.GetSearchFolders((int)swSearchFolderTypes_e.swDocumentType);
            Debug.Print("New search path: " + searchFolders);
        }
 
 
        public SldWorks swApp;
 
    }
}

=========================================================================

SolidWorksExplorer
=========================================================================

  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值