其他分享
首页 > 其他分享> > IDrawingComponent Interface 学习

IDrawingComponent Interface 学习

作者:互联网

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 configuration
                swComp = (Component2)swDrawComp.Component;

                if ((null != swComp))
                {
                    // Returns NULL if drawing is lightweight
                    swCompModel = (ModelDoc2)swComp.GetModelDoc2();

                    Debug.Print("      Component                            = " + swComp.Name2);
                    Debug.Print("      Configuration                        = " + swComp.ReferencedConfiguration);

                    // Turn off using document default settings for component's line font style
                    swDrawComp.UseDocumentDefaults = false;
                    Debug.Print("      Default component line font in use   = " + swDrawComp.UseDocumentDefaults);
                    // Set new line style for visible edges
                    swDrawComp.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 edges
                    swDrawComp.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.  设置绘图组件的线条粗细。

标签:IDrawingComponent,default,component,学习,组件,绘图,Interface,line,drawing
来源: https://blog.csdn.net/hd51cc/article/details/121706928