IDrawingComponent Interface 学习

news/2024/11/28 23:31:21/

Solidworks学习笔记-链接Solidworks

在此基础上学习

属性

NameDescription备注
ComponentGets the referenced component for this drawing component.  获取此绘图组件的引用组件。
LayerGets or sets the name of the layer on which the component resides in the view.  获取或设置组件在视图中所在的层的名称。
LayerOverrideGets or sets whether the drawing component has properties that override the default properties of the layer.  获取或设置绘图组件是否具有覆盖图层默认属性的属性。
NameGets the name of the drawing component.  获取绘图组件的名称。
StyleGets or sets the style for the line for this component in this drawing view.  获取或设置此绘图视图中此组件的线条样式。
UseDocumentDefaultsGets or sets whether to use the document default settings for the component's line fonts.  获取或设置是否对组件的线条字体使用文档默认设置。
ViewGets the drawing view on which this component resides.  获取此组件所在的绘图视图。
VisibleGets or sets the visibility state for this component for this drawing view.  获取或设置此工程视图的此组件的可见性状态。
WidthGets or sets the width of the line for this component for this drawing view.  

获取或设置此绘图视图的此组件的线宽。

Component2 Component {get;}

//This example shows how to get the components in a drawing view and how to change their //line font styles.//------------------------------------------------------------------
// Preconditions:
// 1. Drawing document opened by the macro exists.
// 2. Drawing view is selected.
// 3. Open the Immediate window.
//
// Postconditions:
// 1. Specified drawing document is opened.
// 2. Drawing View1 is selected.
// 3. Gets the root and children components for Drawing
//    View1.
// 4. For each component:
//    a. Prints whether a drawing component is selected,
//       the name of the component, and the name of the 
//       configuration to the Immediate window.
//    b. Disables the use of the document defaults for the
//       the component's line font style.
//    c. Sets new line style and line thickness for the component's
//       visible edges and prints the new settings and values to
//       the Immediate window.
//    d. Prints the file name of the component to the Immediate window.
//------------------------------------------------------------------
using SolidWorks.Interop.sldworks;
using SolidWorks.Interop.swconst;
using System;
using System.Diagnostics;namespace LineFontsDrawingComponentCSharp.csproj
{partial class SolidWorksMacro{public void Main(){ModelDoc2 swModel = default(ModelDoc2);DrawingDoc swDraw = default(DrawingDoc);SelectionMgr swSelMgr = default(SelectionMgr);SelectData swSelData = default(SelectData);ModelDocExtension swModelDocExt = default(ModelDocExtension);View swView = default(View);DrawingComponent swRootDrawComp = default(DrawingComponent);object[] vDrawChildCompArr = null;DrawingComponent swDrawComp = default(DrawingComponent);Component2 swComp = default(Component2);ModelDoc2 swCompModel = default(ModelDoc2);string assemblyDrawing = null;bool status = false;int errors = 0;int warnings = 0;int lineWeight = 0;double lineThickness = 0;assemblyDrawing = "C:\\Users\\Public\\Documents\\SOLIDWORKS\\SOLIDWORKS 2018\\samples\\tutorial\\driveworksxpress\\mobile gantry.slddrw";swModel = (ModelDoc2)swApp.OpenDoc6(assemblyDrawing, (int)swDocumentTypes_e.swDocDRAWING, (int)swOpenDocOptions_e.swOpenDocOptions_Silent, "", ref errors, ref warnings);swDraw = (DrawingDoc)swModel;swModelDocExt = (ModelDocExtension)swModel.Extension;swSelMgr = (SelectionMgr)swModel.SelectionManager;swSelData = (SelectData)swSelMgr.CreateSelectData();status = swDraw.ActivateView("Drawing View4");status = swModelDocExt.SelectByID2("Drawing View1", "DRAWINGVIEW", 0.104008832128, 0.1163870710783, 0, false, 0, null, 0);swView = (View)swSelMgr.GetSelectedObject6(1, -1);swModel.ViewZoomtofit2();swRootDrawComp = (DrawingComponent)swView.RootDrawingComponent;Debug.Print("File = " + swModel.GetPathName());Debug.Print("  View = " + swView.Name);vDrawChildCompArr = (object[])swRootDrawComp.GetChildren();foreach (object vDrawChildComp in vDrawChildCompArr){swDrawComp = (DrawingComponent)vDrawChildComp;// Drawing component selected?Debug.Print(" Drawing component selected = " + swDrawComp.Select(true, null));// Returns NULL if underlying model is open in a different configurationswComp = (Component2)swDrawComp.Component;if ((null != swComp)){// Returns NULL if drawing is lightweightswCompModel = (ModelDoc2)swComp.GetModelDoc2();Debug.Print("      Component                            = " + swComp.Name2);Debug.Print("      Configuration                        = " + swComp.ReferencedConfiguration);// Turn off using document default settings for component's line font styleswDrawComp.UseDocumentDefaults = false;Debug.Print("      Default component line font in use   = " + swDrawComp.UseDocumentDefaults);// Set new line style for visible edgesswDrawComp.SetLineStyle((int)swDrawingComponentLineFontOption_e.swDrawingComponentLineFontVisible, (int)swLineStyles_e.swLineCHAIN);Debug.Print("        Line style for visible edges                      = " + swDrawComp.GetLineStyle((int)swDrawingComponentLineFontOption_e.swDrawingComponentLineFontVisible));// Set new line thickness for visible edgesswDrawComp.SetLineThickness((int)swDrawingComponentLineFontOption_e.swDrawingComponentLineFontVisible, (int)swLineWeights_e.swLW_CUSTOM, 0.0003);lineWeight = swDrawComp.GetLineThickness((int)swDrawingComponentLineFontOption_e.swDrawingComponentLineFontVisible, out lineThickness);Debug.Print("        Line weight style and thickness for visible edges = " + lineWeight + ", " + lineThickness * 1000 + " mm");if ((null != swCompModel)){Debug.Print("      File                                 = " + swCompModel.GetPathName());Debug.Print(" ");}}}}/// <summary>/// The SldWorks swApp variable is pre-assigned for you./// </summary>public SldWorks swApp;}
}
//This example shows how to select an assembly component in a drawing.//--------------------------------------------
// Preconditions:
// 1. Open a drawing of an assembly.
// 2. Select an assembly component in the drawing.
//
// Postconditions: Displays a message box
// containing the name of the selected assembly
// component.
//---------------------------------------------
using SolidWorks.Interop.sldworks;
using SolidWorks.Interop.swconst;
using System.Runtime.InteropServices;
using System;
using System.Windows.Forms;namespace GetSelectedDrawingComponent4CSharp.csproj
{public partial class SolidWorksMacro{public void Main(){ModelDoc2 swModelDoc;SelectionMgr swSelMgr;Component2 swComponent;DrawingComponent swDrawingComponent;swModelDoc = (ModelDoc2)swApp.ActiveDoc;if (swModelDoc == null){return;}swSelMgr = (SelectionMgr)swModelDoc.SelectionManager;if (swSelMgr.GetSelectedObjectCount2(0) == 0){MessageBox.Show("No selections detected.");return;}if (swSelMgr.GetSelectedObjectType3(1, 0) == (int)swSelectType_e.swSelCOMPONENTS){swDrawingComponent = (DrawingComponent)swSelMgr.GetSelectedObjectsComponent4(1, 0);if (swDrawingComponent == null){MessageBox.Show("The component is empty.");return;}else{swComponent = (Component2)swDrawingComponent.Component;MessageBox.Show(swComponent.Name2);}}else{MessageBox.Show("The selection is not an assembly component.");return;}}/// <summary>/// The SldWorks swApp variable is pre-assigned for you./// </summary>public SldWorks swApp;}
}

方法

NameDescription备注
DeSelectDeselects this drawing component.  取消选择此绘图组件。
GetChildrenGets the child components for this drawing component.  获取此绘图组件的子组件。
GetChildrenCountGets the number of child components for this drawing component.  获取此绘图组件的子组件数。
GetLineStyleGets the line style for the drawing component.  获取绘图组件的线条样式。
GetLineThicknessGets the line thickness for the drawing component.  获取绘图组件的线条粗细。
IGetChildrenGets the child components for this drawing component.  获取此绘图组件的子组件。
IsRootGets whether this is the root drawing component.  获取这是否是根绘图组件。
SelectSelects the specified drawing component.  选择指定的绘图组件。
SetLineStyleSets the line style for the drawing component.  设置绘图组件的线型。
SetLineThicknessSets the line thickness for the drawing component.  设置绘图组件的线条粗细。


http://www.ppmy.cn/news/500662.html

相关文章

C# SolidWorks二次开发-工程图-更换工程图图纸格式/模板

这两天有朋友提问&#xff0c;怎么更换工程图模板。 正好晚上还能挤点时间&#xff0c;就来写一篇文件解答一下。 首先&#xff0c;更换工程图模板&#xff0c;你需要知道手动怎么修改。 如下图&#xff0c;我这个没有模板&#xff0c;只有个纸张大小。 对着视图&#xff0c;右…

C# SolidWorks二次开发---工程图中心标记(Center Marks)

工程图的中心标记 作为一个不专业的制图人员&#xff0c;我就不解释中心标记是什么了。大家自己看Solidworks的官方帮助说明(好像不应该放英文的&#xff0c;大家都看不懂了 )。 就是这么个东东。 我自己画了一个非常复杂的图纸&#xff0c;创建主视图的时候好像就自动增加了…

PDM中的自定义属性映射

在PDM中需要在数据卡中反馈出文件的一些属性信息&#xff0c;使得用户在不打开文件的情况下可以快速了解此文件的属性信息&#xff0c;所以就需要实施的过程中在PDM后台做好属性映射&#xff0c;此文章主要讲述SOLIDWORKS文件、Excel文件、Word文档的属性映射。 SOLIDWORKS文件…

SOLIDWORKS 如何重用DWG格式图纸

经常有工程师咨询DWG图纸在SOLIDWORKS软件里如何使用&#xff0c;其实这涉及到DWG图纸在SOLIDWORKS软件里的重用问题&#xff0c;SOLIDWORKS支持对DWG图纸的重用&#xff0c;常用的有三种方法&#xff1a; 1、作为原始DWG图纸查看 作为原始DWG图纸查看是指使用SOLIDWORKS软件…

DATAKIT CrossManager 2022.4 Crack

CrossManager 是一款独立软件&#xff0c;可让您转换大多数 CAD 格式的文件。 使用 Cross Manager&#xff0c;您只需选择一个或多个 CAD 文件&#xff0c;即可将它们自动翻译成您想要的格式。 DATAKIT CrossManager是一款独立软件&#xff0c;可让您转换大多数 CAD 格式的文件…

数领科技|学会用低版本solidworks软件打开高版本sw文件

对各位使用solidworks进行设计的工程师而言,在工作中我们常常会遇到这样的情况,当我们将自己做好的SOLIDWORKS模型发给别人时,却因为对方的SOLIDWORKS版本较低,而打不开模型文件。在这种时候,我们通常需要先将SOLIDWORKS模型转换成中间格式(igs、stp等),然后对方就可以…

SOLIDWORKS批量转化PDF图纸的方法

在大家使用SOLIDWORKS过程中&#xff0c;常常需要将设计图纸转化成各种形式用来展示&#xff0c;而PDF作为日常工程需求中最常见的图纸样式。您可能面对采购或销售人员要求您发送PDF图纸&#xff0c;以期让供应商报价或供客户批准。常常会有大量图纸需要我们转化为PDF&#xff…

在 Winform 上显示 CAD 三维模型

0、基本概念 CAD CAD 是计算机辅助设计&#xff08;Computer-Aided Design&#xff09;的缩写&#xff0c;指的是使用计算机技术和软件工具来辅助进行设计和绘图的过程。 CAD 广泛应用于各种工程和设计领域&#xff0c;如建筑设计、机械工程、电子设计、航空航天、汽车设计等…