Solidworks学习笔记-链接Solidworks
在此基础上
属性
Name | Description | 备注 |
IMaterialPropertyValues | Gets or sets a material's properties in the active configuration. | 获取或设置活动配置中的材料属性。 |
MaterialIdName | Gets or sets the material name. | 获取或设置材质名称。 |
MaterialPropertyValues | Gets or sets a material's properties in the active configuration. | 获取或设置活动配置中的材料属性。 |
MaterialUserName | Gets or sets the material name. This name is visible to the user. | 获取或设置材质名称。 该名称对用户可见。 |
方法
Name | Description | 备注 |
AddPropertyExtension | Adds a property extension to this part. | 向该部分添加属性扩展。 |
CreateFeatureFromBody3 | Creates a new imported feature from the specified temporary body. | 从指定的临时实体创建一个新的导入特征。 |
CreateNewBody | Creates a new body to use for import sewing operations and returns it to the caller. | 创建一个用于导入缝纫操作的新实体并将其返回给调用者。 |
CreateSurfaceFeatureFromBody | Creates a surface feature from a body. | 从实体创建曲面特征。 |
DeleteEntityName | Deletes the name associated with the specified entity. | 删除与指定实体关联的名称。 |
EditRollback | Rolls back the part's history to the feature just before the currently selected feature in the FeatureManager design tree. | 将零件的历史回滚到 FeatureManager 设计树中当前所选特征之前的特征。 |
EnumBodies3 | Enumerates the bodies in this part. | 枚举此部分中的实体。 |
EnumRelatedBodies2 | Creates an enumerated list of bodies. | 创建曲面的实体枚举列表。 |
EnumRelatedSectionedBodies2 | Gets an enumeration of the related sectioned bodies in a part. | 获取零件中相关分段实体的枚举。 |
ExportToDWG2 | Saves various aspects of a part (sheet metal, faces, loops, and annotation views) to one or more DXF/DWG files, preserving the specified file name. | 将零件的各个方面(钣金、面、循环和注释视图)保存到一个或多个 DXF/DWG 文件,同时保留指定的文件名。 |
FeatureById | Gets the feature with the specified ID in the part. | 获取零件中具有指定 ID 的特征。 |
FeatureByName | Gets the named feature in the part. | 获取零件中的命名特征。 |
FeatureXpert | Executes FeatureXpert, powered by SOLIDWORKS Intelligent Feature Technology ( SWIFT), in parts. | 部分执行 FeatureXpert,由 SOLIDWORKS 智能特征技术 (SWIFT) 提供支持。 |
FirstFeature | Gets the first feature in the part. | 获取零件中的第一个特征。 |
GetBodies2 | Gets the bodies in this part. | 获取此部分中的实体。 |
GetEntityByName | Gets an entity (face, edge, vertex) by name. | 按名称获取实体(面、边、顶点)。 |
GetEntityName | Gets the name of the specified entity. | 获取指定实体的名称。 |
GetMateReferenceEntity | Gets the mate reference entity. | 获取配合参考实体。 |
GetMaterialPropertyName2 | Gets the names of the material database and the material for the specified configuration. | 获取材料数据库的名称和指定配置的材料。 |
GetMaterialVisualProperties | Gets the material visual properties for this part. | 获取此零件的材料视觉属性。 |
GetNamedEntities | Gets an array of names of named entities (face, edge, vertex, and so on) in this part. | 获取此部分中命名实体(面、边、顶点等)的名称数组。 |
GetNamedEntitiesCount | Gets the number of named entities (face, edge, vertex, and so on) in this part. | 获取此零件中命名实体(面、边、顶点等)的数量。 |
GetPartBox | Gets the box enclosing the part. | 获取封闭零件的框。 |
GetPropertyExtension | Gets the specified property extension on this part document. | 获取此零件文档的指定属性扩展。 |
GetRelatedBodies | Creates a list of all the related bodies in a part. | 创建零件中所有相关实体的列表。 |
GetRelatedSectionedBodies | Gets all of the related sectioned bodies in a part. | 获取零件中所有相关的剖分实体。 |
GetSectionedBody | Gets the sectioned body seen in the specified drawing view. | 获取在指定工程视图中看到的剖切实体。 |
GetTessNorms | Gets the normal vector for each of the triangles, which make up the shaded picture tessellation. | 获取构成阴影图片细分的每个三角形的法线向量。 |
GetTessTriangleCount | Gets the number of triangles that make up the shaded picture tessellation for this part. | 获取构成此部件的阴影图片细分的三角形数。 |
GetTessTriangles | Gets the triangles that make up the shaded picture tessellation for this part. | 获取构成该部分阴影图片镶嵌的三角形。 |
GetTessTriStripEdges | Gets the edge ID for each of the edges in the triangles that make up the tessellation for this part. | 获取构成该零件镶嵌的三角形中每条边的边 ID。 |
GetTessTriStripNorms | Gets the normal vector for each of the triangles, which make up the shaded picture tessellation for this part. | 获取每个三角形的法向量,这些三角形构成了这部分的阴影图片细分。 |
GetTessTriStrips | Gets the vertices that make up the shaded picture tessellation for this part. | 获取构成该部分着色图片细分的顶点。 |
GetTessTriStripSize | Gets the size of the array floats required to contain the data returned when calling IPartDoc::GetTessTriStrips and IPartDoc::IGetTessTriStrips. | 获取包含调用 IPartDoc::GetTessTriStrips 和 IGetTessTriStrips 时返回的数据所需的数组浮点数的大小。 |
ICreateFeatureFromBody4 | Creates a new imported feature from the specified temporary body. | 从指定的临时实体创建一个新的导入特征。 |
ICreateNewBody2 | Creates a new body to use for import sewing operations and returns it to the caller. | 创建一个用于导入缝纫操作的新实体并将其返回给调用者。 |
ICreateSurfaceFeatureFromBody | Creates a surface feature from a body. | 从实体创建曲面特征。 |
ICreateSurfaceFeatureFromBodyCount2 | Gets the number of surface features to create from the body. | 获取要从主体创建的表面特征的数量。 |
IDeleteEntityName | Deletes the name associated with the specified entity. | 删除与指定实体关联的名称。 |
IExportToDWG2 | Saves various aspects of a part (sheet metal, faces, loops, and annotation views) to one or more DXF/DWG files, preserving the specified filename. | 将零件的各个方面(钣金、面、循环和注释视图)保存到一个或多个 DXF/DWG 文件,同时保留指定的文件名。 |
IFeatureById | Gets the feature with the specified ID in the part. | 获取零件中具有指定 ID 的特征。 |
IFeatureByName | Gets the named feature in the part. | 获取零件中的命名特征。 |
IFirstFeature | Gets the first feature in the part. | 获取零件中的第一个特征。 |
IGetEntityByName | Gets an entity (face, edge, vertex) by name. | 按名称获取实体(面、边、顶点)。 |
IGetEntityName | Gets the name of the specified entity. | 获取指定实体的名称。 |
IGetNamedEntities | Gets an array of names of named entities (face, edge, vertex, and so on) in this part. | 获取此部分中命名实体(面、边、顶点等)的名称数组。 |
IGetPartBox | Gets the box enclosing the part. | 获取封闭零件的框。 |
IGetProcessedBody2 | Pre-processes the geometry of a body so that: Closed periodic faces (for example, the lateral face of a cylinder) are split into two faces. Faces that straddle the seam, if any, of the underlying surface are split into two faces. | “预处理身体的几何形状,以便:闭合周期面(例如圆柱的侧面)被分成两个面。跨越接缝的面(如果有的话)被分成两个面。” |
IGetProcessedBodyWithSelFace2 | Gets a processed body. | 获取经过处理的主体。 |
IGetSectionedBody2 | Gets the sectioned body seen in the specified drawing view. | 获取在指定工程视图中看到的剖切实体。 |
IGetTessNorms | Gets the normal vector for each of the triangles, which make up the shaded picture tessellation. | 获取构成阴影图片细分的每个三角形的法线向量。 |
IGetTessTriangles | Gets the triangles that make up the shaded picture tessellation for this part. | 获取构成该部分阴影图片镶嵌的三角形。 |
IGetTessTriStripEdges | Gets the edge ID for each of the edges in the triangles that make up the tessellation for this part. | 获取构成该零件镶嵌的三角形中每条边的边 ID。 |
IGetTessTriStripEdgeSize | Gets the size of the array returned by IPartDoc::GetTessTriStripEdges and IPartDoc::IGetTessTriStripEdges. | 获取由 IPartDoc::GetTessTriStripEdges 和 IPartDoc::IGetTessTriStripEdges 返回的数组的大小。 |
IGetTessTriStripNorms | Gets the normal vector for each of the triangles, which make up the shaded picture tessellation for this part. | 获取每个三角形的法向量,这些三角形构成了这部分的阴影图片细分。 |
IGetTessTriStrips | Gets the vertices that make up the shaded picture tessellation for this part. | 获取构成该部分着色图片细分的顶点。 |
ImportDiagnosis | Diagnoses and repairs any gaps or bad faces on imported features. | 诊断和修复导入特征上的任何间隙或不良面。 |
ImportDiagnosisGapCloser | Allows you to repair a gap by moving the vertices on the edges surrounding the gap to new positions to close the gap on the imported model. | 允许您通过将间隙周围边缘上的顶点移动到新位置来修复间隙,以闭合导入模型上的间隙。 |
InsertBendNotes | Inserts bend notes for the specified flat-pattern feature of this sheet metal part. | 为该钣金零件的指定平面图案特征插入折弯注释。 |
InsertBends2 | Creates bends in a thin-feature part. | 在薄特征零件中创建折弯。 |
InsertBendTable | Creates a bend table annotation for the flat pattern of this sheet metal part. | 为该钣金零件的展开模式创建折弯表注释。 |
InsertMirrorAll | Mirrors the part about a selected planar face. | 围绕选定的平面镜像零件。 |
InsertPart3 | Inserts the specified part in the specified configuration into this part. | 将指定配置中的指定部件插入到该部件中。 |
ISetEntityName | Sets the name of the entity if the entity does not have a name. | 如果实体没有名称,则设置实体的名称。 |
IsMirrored | Gets whether this part is mirrored. | 获取这部分是否被镜像。 |
IsWeldment | Gets whether this part contains a weldment feature. | 获取此零件是否包含焊件特征。 |
MakeSection | Saves sketch profiles for use in the wizard. | 保存草图轮廓以在向导中使用。 |
MirrorFeature | Displays a dialog that allows the end-user to mirror a feature about a selected plane or planar face. | 显示一个对话框,允许最终用户围绕选定的平面或平面镜像特征。 |
MirrorPart2 | Creates a new part document that mirrors this part about a selected reference plane or planar face. | 创建一个新的零件文档,该文档围绕选定的参考平面或平面镜像该零件。 |
RemoveAllDisplayStates | Removes all display states and appearances from this part document. | 从此零件文档中删除所有显示状态和外观。 |
ReorderFeature | Reorders features and their operations. | 重新排序功能及其操作。 |
ResetPropertyExtension | Clears all values stored in the property extension. | 清除存储在属性扩展中的所有值。 |
SaveToFile3 | Saves the selected weldment member, surface body, or solid body to another part document. | 将选定的焊件成员、曲面体或实体保存到另一个零件文档中。 |
SetCosmosWorksMaterial | Assigns the material to use during analysis to this part. | 将分析期间要使用的材料分配给该部件。 |
SetDroppedFileName | Sets the filename for a recently dropped file. | 设置最近删除的文件的文件名。 |
SetEntityName | Sets the name of the entity if the entity does not have a name and the name is unique to the part. | 如果实体没有名称并且名称对于零件是唯一的,则设置实体的名称。 |
SetLineColor | Sets the color for the lines in the part document. | 设置零件文档中线条的颜色。 |
SetLineStyle | Sets the style or font for the lines in the part document. | 设置零件文档中线条的样式或字体。 |
SetLineWidth | Sets the thickness or weight for the lines in the part document. | 设置零件文档中线条的粗细或粗细。 |
SetMaterialPropertyName2 | Sets the name of the material property for the specified configuration. | 为指定的配置设置材料属性的名称。 |
SetMaterialVisualProperties | Sets the material visual properties for the active configuration and any specified configurations of this part. | 设置此零件的活动配置和任何指定配置的材料视觉属性。 |
System.int AddPropertyExtension( System.object PropertyExtension)
//---------------------------------------------
// Preconditions:
// 1. Open a part.
// 2. Open the Immediate window.
//
// Postconditions:
// 1. Adds three property extensions to the part.
// 2. Gets the three property extensions added to the part.
// 3. Examine the 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()
{
PartDoc swPart = default(PartDoc);
int retVal = 0;
string[] objAdded = new string[3];
string objRetrieved = null;
swPart = (PartDoc)swApp.ActiveDoc;
Debug.Print("Property extensions added:");
objAdded[0] = "12345PID";
retVal = swPart.AddPropertyExtension(objAdded[0]);
Debug.Print(" First property extension: " + objAdded[0]);
objAdded[1] = "6789PID";
retVal = swPart.AddPropertyExtension(objAdded[1]);
Debug.Print(" Second property extension: " + objAdded[1]);
objAdded[2] = "00000PID";
retVal = swPart.AddPropertyExtension(objAdded[2]);
Debug.Print(" Third property extension: " + objAdded[2]);
Debug.Print("Property extensions retrieved:");
objRetrieved = (string)swPart.GetPropertyExtension(retVal - 3);
Debug.Print(" First property extension: " + objRetrieved);
objRetrieved = (string)swPart.GetPropertyExtension(retVal - 2);
Debug.Print(" Second property extension: " + objRetrieved);
objRetrieved = (string)swPart.GetPropertyExtension(retVal - 1);
Debug.Print(" Third property extension: " + objRetrieved);
}
/// <summary>
/// The SldWorks swApp variable is pre-assigned for you.
/// </summary>
public SldWorks swApp;
}
}
void EditRollback()
This example shows how to move the rollback bar above and below a selected feature in a part document.
//---------------------------------------
// Preconditions: Verify that the part to open exists.
// 2. Run the macro.
//
// Postconditions:
// 1. Opens the part document.
// 2. Selects the Sweep1 feature.
// 3. Moves the rollback bar to feature above the
// Sweep1 feature; i.e., the Revolve1 feature.
// 4. Examine the graphics area to verify, then press
// F5
// 5. Moves the rollback bar to below the Sweep1 feature.
//------------------------------------------
using SolidWorks.Interop.sldworks;
using SolidWorks.Interop.swconst;
using System.Runtime.InteropServices;
using System;
namespace EditRollbackPartDocCSharp.csproj
{
public partial class SolidWorksMacro
{
public void Main()
{
ModelDoc2 swModel = default(ModelDoc2);
ModelDocExtension swModelDocExt = default(ModelDocExtension);
PartDoc swPart = default(PartDoc);
FeatureManager swFeatureMgr = default(FeatureManager);
string fileName = null;
bool status = false;
int errors = 0;
int warnings = 0;
fileName = "C:\\Users\\Public\\Documents\\SOLIDWORKS\\SOLIDWORKS 2018\\samples\\tutorial\\api\\cstick.sldprt";
swModel = (ModelDoc2)swApp.OpenDoc6(fileName, (int)swDocumentTypes_e.swDocPART, (int)swOpenDocOptions_e.swOpenDocOptions_Silent, "", ref errors, ref warnings);
swPart = (PartDoc)swModel;
swModelDocExt = (ModelDocExtension)swModel.Extension;
// Move rollback bar to above Sweep1
status = swModelDocExt.SelectByID2("Sweep1", "BODYFEATURE", 0, 0, 0, false, 0, null, 0);
swPart.EditRollback();
System.Diagnostics.Debugger.Break();
//Examine graphics area, then press F5
// Move rollback bar to below Sweep1
swFeatureMgr = (FeatureManager)swModel.FeatureManager;
status = swFeatureMgr.EditRollback((int)swMoveRollbackBarTo_e.swMoveRollbackBarToBeforeFeature, "");
}
/// <summary>
/// The SldWorks swApp variable is pre-assigned for you.
/// </summary>
public SldWorks swApp;
}
}
EnumBodies2 EnumBodies3( System.int BodyType,System.bool BVisibleOnly)
private void SW_Clear(object sender, RoutedEventArgs e)
{
System.Collections.Generic.List<string> list = new System.Collections.Generic.List<string>();
ModelDoc2 model = ((ModelDoc2)(sld4Handler.SwApp.ActiveDoc));
PartDoc partDoc = model as PartDoc;
EnumBodies2 bodies = null;
Body2 body2 = null;
if (partDoc != null) bodies = partDoc.EnumBodies3((int)swBodyType_e.swAllBodies, false);
int nFetched = -1;
bodies.Reset();
do
{
bodies.Next(1, out body2, ref nFetched);
if (body2 != null)
{
string str0 = body2.Name;
list.Add(str0);
}
} while (body2 != null);
//应用范例
foreach (var item in list)
{
MessageBox.Show(item.ToString());
}
}
EnumBodies2 EnumRelatedBodies2() 曲面的实体列表
private void SW_Clear(object sender, RoutedEventArgs e)
{
System.Collections.Generic.List<string> list = new System.Collections.Generic.List<string>();
ModelDoc2 model = ((ModelDoc2)(sld4Handler.SwApp.ActiveDoc));
PartDoc partDoc = model as PartDoc;
EnumBodies2 bodies = null;
Body2 body2 = null;
if (partDoc != null) bodies = partDoc.EnumRelatedBodies2();
int nFetched = -1;
bodies.Reset();
do
{
bodies.Next(1, out body2, ref nFetched);
if (body2 != null)
{
string str0 = body2.Name;
list.Add(str0);
}
} while (body2 != null);
//应用范例
foreach (var item in list)
{
MessageBox.Show(item.ToString());
}
}
System.object FirstFeature()
This example shows how to autodimension all under-constrained sketches in a part.
//------------------------------------------------------------
// Preconditions:
// 1. Verify that the specified part document template exists.
// 2. Open the Immediate window.
//
// Postconditions:
// 1. Opens a new part document.
// 2. Inserts two sketches.
// 3. Autodimensions the sketches.
// 4. Examine the Immediate window.
//-----------------------------------------------------------
using SolidWorks.Interop.sldworks;
using SolidWorks.Interop.swconst;
using System.Runtime.InteropServices;
using System;
using System.Diagnostics;
namespace AutoDimension2AllCSharp.csproj
{
public partial class SolidWorksMacro
{
const string swTnProfileFeature = "ProfileFeature";
const double nTolerance = 1E-08;
public void Main()
{
ModelDoc2 swModel = default(ModelDoc2);
ModelDocExtension swModelDocExt = default(ModelDocExtension);
PartDoc swPart = default(PartDoc);
object[] sketchLines = null;
string[] sSketchNameArr = null;
string sSketchName = null;
Feature swFeat = default(Feature);
Sketch swSketch = default(Sketch);
SketchSegment sketchSegment = default(SketchSegment);
SketchManager swSketchMgr = default(SketchManager);
int nRetVal = 0;
bool bRet = false;
// Create new part document and insert sketches
swModel = (ModelDoc2)swApp.NewDocument("C:\\ProgramData\\SolidWorks\\SolidWorks 2015\\templates\\Part.prtdot", 0, 0, 0);
swModelDocExt = (ModelDocExtension)swModel.Extension;
bRet = swModelDocExt.SetUserPreferenceToggle((int)swUserPreferenceToggle_e.swSketchAddConstToRectEntity, (int)swUserPreferenceOption_e.swDetailingNoOptionSpecified, false);
bRet = swModelDocExt.SetUserPreferenceToggle((int)swUserPreferenceToggle_e.swSketchAddConstLineDiagonalType, (int)swUserPreferenceOption_e.swDetailingNoOptionSpecified, true);
swSketchMgr = (SketchManager)swModel.SketchManager;
sketchLines = (object[])swSketchMgr.CreateCornerRectangle(0, 0, 0, 0.0711560575730914, -0.0480714437538268, 0);
swModel.ClearSelection2(true);
bRet = swModelDocExt.SetUserPreferenceToggle((int)swUserPreferenceToggle_e.swSketchAddConstToRectEntity, (int)swUserPreferenceOption_e.swDetailingNoOptionSpecified, false);
bRet = swModelDocExt.SetUserPreferenceToggle((int)swUserPreferenceToggle_e.swSketchAddConstLineDiagonalType, (int)swUserPreferenceOption_e.swDetailingNoOptionSpecified, true);
sketchLines = (object[])swSketchMgr.CreateCornerRectangle(-0.100496797175254, 0.0481170506199078, 0, -0.0506046179404507, 0.0100165849869995, 0);
swModel.ClearSelection2(true);
sketchSegment = (SketchSegment)swSketchMgr.CreateCircle(-0.06189, -0.041869, 0.0, -0.066641, -0.077213, 0.0);
swModel.ClearSelection2(true);
swSketchMgr.InsertSketch(true);
sketchSegment = (SketchSegment)swSketchMgr.CreateCircle(-0.032637, 0.106589, 0, -0.021539, 0.095387, 0);
swModel.ClearSelection2(true);
sketchSegment = (SketchSegment)swSketchMgr.CreateCircle(0, 0.083617, 0, 0.01255, 0.067729, 0);
swModel.ClearSelection2(true);
swSketchMgr.InsertSketch(true);
swModel.ClearSelection2(true);
// Find all under-constrained sketches
swPart = (PartDoc)swModel;
sSketchNameArr = new string[1];
swFeat = (Feature)swPart.FirstFeature();
while ((swFeat != null)) {
if (swTnProfileFeature == swFeat.GetTypeName2()) {
swSketch = (Sketch)swFeat.GetSpecificFeature2();
if ((int)swConstrainedStatus_e.swUnderConstrained == swSketch.GetConstrainedStatus()) {
sSketchNameArr[sSketchNameArr.GetUpperBound(0)] = (string)swFeat.Name;
Array.Resize(ref sSketchNameArr, sSketchNameArr.GetUpperBound(0) + 2);
}
}
swFeat = (Feature)swFeat.GetNextFeature();
}
// Autodimension all under-constrained sketches
Array.Resize(ref sSketchNameArr, sSketchNameArr.GetUpperBound(0));
foreach (string sSketchName_loopVariable in sSketchNameArr)
{
sSketchName = sSketchName_loopVariable;
swFeat = (Feature)swPart.FeatureByName(sSketchName);
swSketch = (Sketch)swFeat.GetSpecificFeature2();
nRetVal = AutoDimensionSketch(swApp, swModel, swSketch);
Debug.Print(sSketchName + " autodimensioned (0 = success): " + nRetVal);
}
}
public void FindAllUnderConstrainedSketches(SldWorks swApp, ModelDoc2 swModel, string[] sSketchNameArr)
{
PartDoc swPart = default(PartDoc);
Feature swFeat = default(Feature);
Sketch swSketch = default(Sketch);
swPart = (PartDoc)swModel;
swFeat = (Feature)swPart.FirstFeature();
while ((swFeat != null))
{
if (swTnProfileFeature == swFeat.GetTypeName2())
{
swSketch = (Sketch)swFeat.GetSpecificFeature2();
if ((int)swConstrainedStatus_e.swUnderConstrained == swSketch.GetConstrainedStatus())
{
sSketchNameArr[sSketchNameArr.GetUpperBound(0)] = (string)swFeat.Name;
Array.Resize(ref sSketchNameArr, sSketchNameArr.GetUpperBound(0) + 2);
}
}
swFeat = (Feature)swFeat.GetNextFeature();
}
// Remove last empty sketch name
Array.Resize(ref sSketchNameArr, sSketchNameArr.GetUpperBound(0));
}
public object GetAllSketchLines(SldWorks swApp, ModelDoc2 swModel, Sketch swSketch)
{
object functionReturnValue = null;
object[] vSketchSegArr = null;
SketchSegment vSketchSeg = null;
SketchSegment swSketchSeg = default(SketchSegment);
SketchLine swSketchCurrLine = default(SketchLine);
SketchLine[] swSketchLineArr = null;
swSketchLineArr = new SketchLine[1];
vSketchSegArr = (object[])swSketch.GetSketchSegments();
if ((vSketchSegArr != null))
{
foreach (SketchSegment vSketchSeg_loopVariable in vSketchSegArr)
{
vSketchSeg = (SketchSegment)vSketchSeg_loopVariable;
swSketchSeg = (SketchSegment)vSketchSeg;
if ((int)swSketchSegments_e.swSketchLINE == swSketchSeg.GetType())
{
swSketchCurrLine = (SketchLine)swSketchSeg;
swSketchLineArr[swSketchLineArr.GetUpperBound(0)] = (SketchLine)swSketchCurrLine;
Array.Resize(ref swSketchLineArr, swSketchLineArr.GetUpperBound(0) + 2);
}
}
}
if (0 == swSketchLineArr.GetUpperBound(0))
{
// No straight lines in this sketch
functionReturnValue = null;
return functionReturnValue;
}
// Remove last empty sketch line
Array.Resize(ref swSketchLineArr, swSketchLineArr.GetUpperBound(0));
functionReturnValue = (object[])swSketchLineArr;
return functionReturnValue;
}
public bool GetSketchPoint(SldWorks swApp, ModelDoc2 swModel, Sketch swSketch, SketchPoint swSketchPt)
{
bool functionReturnValue = false;
object[] vSketchPtArr = null;
vSketchPtArr = (object[])swSketch.GetSketchPoints2();
if ((vSketchPtArr != null))
{
// Use first point
swSketchPt = (SketchPoint)vSketchPtArr[0];
functionReturnValue = true;
return functionReturnValue;
}
functionReturnValue = false;
return functionReturnValue;
}
public bool FindVerticalOrigin(SldWorks swApp, ModelDoc2 swModel, Sketch swSketch, SketchSegment swSketchSegVert, SketchPoint swSketchPtVert)
{
bool functionReturnValue = false;
SketchLine[] vSketchLineArr = null;
SketchLine vSketchLine = null;
SketchLine swSketchCurrLine = default(SketchLine);
SketchPoint swStartPt = default(SketchPoint);
SketchPoint swEndPt = default(SketchPoint);
// Try to get first vertical line
vSketchLineArr = (SketchLine[])GetAllSketchLines(swApp, swModel, swSketch);
if ((vSketchLineArr != null))
{
foreach (SketchLine vSketchLine_loopVariable in vSketchLineArr)
{
vSketchLine = (SketchLine)vSketchLine_loopVariable;
swSketchCurrLine = (SketchLine)vSketchLine;
swStartPt = (SketchPoint)swSketchCurrLine.GetStartPoint2();
swEndPt = (SketchPoint)swSketchCurrLine.GetEndPoint2();
if (Math.Abs(swStartPt.X - swEndPt.X) < nTolerance)
{
swSketchSegVert = (SketchSegment)swSketchCurrLine;
functionReturnValue = true;
return functionReturnValue;
}
}
}
// Try to get the first point
functionReturnValue = GetSketchPoint(swApp, swModel, swSketch, swSketchPtVert);
return functionReturnValue;
}
public bool FindHorizontalOrigin(SldWorks swApp, ModelDoc2 swModel, Sketch swSketch, SketchSegment swSketchSegHoriz, SketchPoint swSketchPtHoriz)
{
bool functionReturnValue = false;
SketchLine[] vSketchLineArr = null;
SketchLine vSketchLine = null;
SketchLine swSketchCurrLine = default(SketchLine);
SketchPoint swStartPt = default(SketchPoint);
SketchPoint swEndPt = default(SketchPoint);
// Try to get first horizontal line
vSketchLineArr = (SketchLine[])GetAllSketchLines(swApp, swModel, swSketch);
if ((vSketchLineArr != null))
{
foreach (SketchLine vSketchLine_loopVariable in vSketchLineArr)
{
vSketchLine = (SketchLine)vSketchLine_loopVariable;
swSketchCurrLine = (SketchLine)vSketchLine;
swStartPt = (SketchPoint)swSketchCurrLine.GetStartPoint2();
swEndPt = (SketchPoint)swSketchCurrLine.GetEndPoint2();
if (Math.Abs(swStartPt.Y - swEndPt.Y) < nTolerance)
{
swSketchSegHoriz = (SketchSegment)swSketchCurrLine;
functionReturnValue = true;
return functionReturnValue;
}
}
}
// Try to get the first point
functionReturnValue = GetSketchPoint(swApp, swModel, swSketch, swSketchPtHoriz);
return functionReturnValue;
}
public int AutoDimensionSketch(SldWorks swApp, ModelDoc2 swModel, Sketch swSketch)
{
int functionReturnValue = 0;
Feature swFeat = default(Feature);
SketchSegment swSketchSegHoriz = null;
SketchPoint swSketchPtHoriz = null;
SketchSegment swSketchSegVert = null;
SketchPoint swSketchPtVert = null;
SketchManager swSketchMgr = null;
bool bRet = false;
if (false == FindHorizontalOrigin(swApp, swModel, swSketch, swSketchSegHoriz, swSketchPtHoriz))
{
functionReturnValue = (int)swAutodimStatus_e.swAutodimStatusDatumLineNotHorizontal;
return functionReturnValue;
}
if (false == FindVerticalOrigin(swApp, swModel, swSketch, swSketchSegVert, swSketchPtVert))
{
functionReturnValue = (int)swAutodimStatus_e.swAutodimStatusDatumLineNotVertical;
return functionReturnValue;
}
swFeat = (Feature)swSketch;
bRet = swFeat.Select2(false, 0);
// Editing sketch clears selections
swModel.EditSketch();
// Reselect sketch segments for autodimensioning
if ((swSketchSegVert != null))
{
// Vertical line is for horizontal datum
bRet = swSketchSegVert.Select4(true, null);
}
else if ((swSketchPtHoriz != null))
{
bRet = swSketchPtHoriz.Select4(true, null);
}
else if ((swSketchPtVert != null))
{
// Use any sketch point for horizontal datum
bRet = swSketchPtVert.Select4(true, null);
}
if ((swSketchSegHoriz != null))
{
// Horizontal line is for vertical datum
bRet = swSketchSegHoriz.Select4(true, null);
}
else if ((swSketchPtVert != null))
{
bRet = swSketchPtVert.Select4(true, null);
}
else if ((swSketchPtHoriz != null))
{
// Use any sketch point for vertical datum
bRet = swSketchPtHoriz.Select4(true, null);
}
// No straight lines, probably contains circles,
// so use sketch points for datums
if ((GetAllSketchLines(swApp, swModel, swSketch) == null))
{
if ((swSketchPtHoriz != null))
{
bRet = swSketchPtHoriz.Select4(false, null);
}
else if ((swSketchPtVert != null))
{
bRet = swSketchPtVert.Select4(false, null);
}
}
functionReturnValue = swSketch.AutoDimension2((int)swAutodimEntities_e.swAutodimEntitiesAll, (int)swAutodimScheme_e.swAutodimSchemeBaseline, (int)swAutodimHorizontalPlacement_e.swAutodimHorizontalPlacementBelow, (int)swAutodimScheme_e.swAutodimSchemeBaseline, (int)swAutodimVerticalPlacement_e.swAutodimVerticalPlacementLeft);
// Redraw so dimensions are displayed
swModel.GraphicsRedraw2();
// Exit sketch mode
swSketchMgr = swModel.SketchManager;
swSketchMgr.InsertSketch(false);
return functionReturnValue;
}
/// <summary>
/// The SldWorks swApp variable is pre-assigned for you.
/// </summary>
public SldWorks swApp;
}
}
System.object GetBodies2( System.int BodyType,System.bool BVisibleOnly)
This example shows how to show just one body of a multibody part in a drawing view.
//------------------------------------------------------------------
// Preconditions:
// 1. Open public_documents\samples\tutorial\multibody\multi_inter.sldprt.
// 2. Save the part document as a drawing document:
// a. Click File > Make Drawing from Part.
// b. Click OK on the Sheet Format/Size dialog.
// c. Drag the *Isometric view from the View Palette onto
// the drawing sheet.
// 3. Select the drawing view.
// 4. Open the Immediate window.
//
// Postconditions:
// 1. Shows one body of the multibody part
// in the drawing view.
// 2. Examine the drawing and the Immediate window.
//
// NOTE: Because the part document is used elsewhere, do not save
// changes.
//------------------------------------------------------------------
using SolidWorks.Interop.sldworks;
using SolidWorks.Interop.swconst;
using System;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Windows.Forms;
namespace BodiesViewCSharp.csproj
{
partial class SolidWorksMacro
{
public void Main()
{
ModelDoc2 swModel = default(ModelDoc2);
SelectionMgr swSelMgr = default(SelectionMgr);
SolidWorks.Interop.sldworks.View swView = default(SolidWorks.Interop.sldworks.View);
int nbrBodies = 0;
object[] arrBody = null;
Body2 swBody = default(Body2);
Face2 swFace = default(Face2);
Entity swEnt = default(Entity);
SelectData swSelData = default(SelectData);
PartDoc swPart = default(PartDoc);
bool status = false;
DispatchWrapper[] arrBodiesIn = new DispatchWrapper[1];
object[] Bodies = new object[1];
int i = 0;
int objType = 0;
swModel = (ModelDoc2)swApp.ActiveDoc;
swSelMgr = (SelectionMgr)swModel.SelectionManager;
swView = (SolidWorks.Interop.sldworks.View)swSelMgr.GetSelectedObject6(1, -1);
if ((swView == null))
{
MessageBox.Show("View not selected.");
return;
}
nbrBodies = swView.GetBodiesCount();
Debug.Print("Number of bodies: " + nbrBodies);
if ((nbrBodies < 1))
{
MessageBox.Show("No bodies in selected view.");
return;
}
arrBody = (object[])swView.Bodies;
for (i = 0; i < arrBody.Length; i++)
{
swBody = (Body2)arrBody[i];
swSelData = (SelectData)swSelMgr.CreateSelectData();
swSelData.View = swView;
status = swBody.Select2(false, swSelData);
// Object type 76 is a solid body
objType = swSelMgr.GetSelectedObjectType3(1, -1);
if ((objType == 76))
{
Debug.Print(" Object type: solid body");
}
if ((!((int)swSelectType_e.swSelSOLIDBODIES == swSelMgr.GetSelectedObjectType3(1, -1))))
{
MessageBox.Show("Solid body not found.");
}
swFace = (Face2)swBody.GetFirstFace();
while ((swFace != null))
{
swEnt = (Entity)swFace;
// Select using IEntity
status = swEnt.Select4(true, swSelData);
Debug.Assert(status);
swFace = (Face2)swFace.GetNextFace();
}
Debug.Print(" Name of body: " + swBody.GetSelectionId());
}
swModel.ClearSelection2(true);
// Get the bodies from referenced model
swModel = (ModelDoc2)swView.ReferencedDocument;
swPart = (PartDoc)swModel;
arrBody = (object[])swPart.GetBodies2((int)swBodyType_e.swSolidBody, true);
if ((nbrBodies == 1))
{
swView.Bodies = (arrBody);
}
else
{
// Set the body to include in the drawing view
Bodies[0] = arrBody[0];
arrBodiesIn[0] = new DispatchWrapper(Bodies[0]);
swView.Bodies = (arrBodiesIn);
}
swModel.ClearSelection2(true);
}
/// <summary>
/// The SldWorks swApp variable is pre-assigned for you.
/// </summary>
public SldWorks swApp;
}
}
System.string GetEntityName( System.object Entity)
This example shows how to get cross break feature data in a sheet metal part.
//----------------------------------------------------------------
// Preconditions:
// 1. Verify that the specified part document template exists.
// 2. Open the Immediate window.
//
// Postconditions:
// 1. Creates a sheet metal part with a cross break feature.
// 2. Iterates over all features in the part and gets the
// cross break feature.
// 3. Names the cross break feature's face.
// 4. Prints to the Immediate window this cross break
// feature data:
// * Name of the face
// * Whether its direction is reversed
// * Radius
// * Angle
// 5. Examine the 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()
{
PartDoc swPart = default(PartDoc);
ModelDoc2 swModel = default(ModelDoc2);
SketchManager swSketchManager = default(SketchManager);
ModelDocExtension swModelDocExt = default(ModelDocExtension);
FeatureManager swFeatureManager = default(FeatureManager);
CustomBendAllowance swCustomBendAllowance = default(CustomBendAllowance);
Feature swFeature = default(Feature);
CrossBreakFeatureData swCrossBreakFeatureData = default(CrossBreakFeatureData);
Face2 swFace = default(Face2);
Entity swEntity = default(Entity);
object[] sketchLines = null;
object[] features = null;
string faceName = null;
bool status = false;
int i = 0;
//Create sheet metal part with cross break feature
swPart = (PartDoc)swApp.NewDocument("C:\\ProgramData\\SOLIDWORKS\\SOLIDWORKS 2016\\templates\\part.prtdot", 0, 0, 0);
swModel = (ModelDoc2)swPart;
swSketchManager = (SketchManager)swModel.SketchManager;
swSketchManager.InsertSketch(true);
swModelDocExt = (ModelDocExtension)swModel.Extension;
status = swModelDocExt.SelectByID2("Front Plane", "PLANE", 0, 0, 0, false, 0, null, 0);
swModel.ClearSelection2(true);
status = swModelDocExt.SetUserPreferenceToggle((int)swUserPreferenceToggle_e.swSketchAddConstToRectEntity, (int)swUserPreferenceOption_e.swDetailingNoOptionSpecified, false);
status = swModelDocExt.SetUserPreferenceToggle((int)swUserPreferenceToggle_e.swSketchAddConstLineDiagonalType, (int)swUserPreferenceOption_e.swDetailingNoOptionSpecified, true);
sketchLines = (object[])swSketchManager.CreateCornerRectangle(0, 0, 0, 0.112582864792503, -0.0690084337349398, 0);
swModel.ClearSelection2(true);
swSketchManager.InsertSketch(true);
swModel.ShowNamedView2("*Trimetric", 8);
swFeatureManager = (FeatureManager)swModel.FeatureManager;
swCustomBendAllowance = (CustomBendAllowance)swFeatureManager.CreateCustomBendAllowance();
swCustomBendAllowance.KFactor = 0.5;
swFeature = (Feature)swFeatureManager.InsertSheetMetalBaseFlange2(0.0007366, false, 0.01905, 0.00508, 0.00254, false, 0, 0, 1, swCustomBendAllowance,
false, 0, 0.0001, 0.0001, 0.5, true, false, true, true);
status = swModelDocExt.SelectByID2("Base-Flange1", "BODYFEATURE", 0, 0, 0, false, 0, null, 0);
swModel.ClearSelection2(true);
status = swModelDocExt.SelectByID2("", "FACE", 0.0440948432654409, -0.0302769643316765, 0, true, 0, null, 0);
swFeature = (Feature)swFeatureManager.InsertCrossBreak(1.5707963267949, 0.000635);
swModel.ClearSelection2(true);
//Get the cross break feature
//by iterating over all features
features = (object[])swFeatureManager.GetFeatures(true);
for (i = 0; i < features.Length; i++)
{
swFeature = (Feature)features[i];
if (swFeature.GetTypeName2() == "CrossBreak")
{
swCrossBreakFeatureData = (CrossBreakFeatureData)swFeature.GetDefinition();
swCrossBreakFeatureData.AccessSelections(swModel, null);
swFace = (Face2)swCrossBreakFeatureData.Face;
swEntity = (Entity)swFace;
faceName = "CrossBreakFace";
status = swPart.SetEntityName(swEntity, faceName);
faceName = swModel.GetEntityName(swEntity);
Debug.Print("Cross break feature data:");
Debug.Print(" Name of face: " + faceName);
Debug.Print(" Reverse direction: " + swCrossBreakFeatureData.ReverseDirection);
Debug.Print(" Radius: " + swCrossBreakFeatureData.BreakRadius);
Debug.Print(" Angle: " + swCrossBreakFeatureData.BreakAngle);
swCrossBreakFeatureData.ReleaseSelectionAccess();
}
}
}
/// <summary>
/// The SldWorks swApp variable is pre-assigned for you.
/// </summary>
public SldWorks swApp;
}
}
System.object GetRelatedBodies()
private void SW_Clear(object sender, RoutedEventArgs e)
{
ModelDoc2 model = ((ModelDoc2)(sld4Handler.SwApp.ActiveDoc));
PartDoc partDoc = model as PartDoc;
object obj = null;
if (partDoc != null)
obj = partDoc.EnumRelatedBodies2();
System.Collections.Generic.List<string> list = new System.Collections.Generic.List<string>();
EnumBodies2 bodies = null;
Body2 body2 = null;
if (partDoc != null) bodies = (EnumBodies2)obj;
int nFetched = -1;
bodies.Reset();
do
{
bodies.Next(1, out body2, ref nFetched);
if (body2 != null)
{
string str0 = body2.Name;
list.Add(str0);
}
} while (body2 != null);
//应用范例
foreach (var item in list)
{
MessageBox.Show(item.ToString());
}
}
System.bool SaveToFile3( System.string Name,System.int Options,System.int CutListProps,System.bool OverrideTemplate,System.string TemplatePath,out System.int Errors,out System.int Warnings)
This example shows how to save a weldment member to another part document.
//----------------------------------------------------------------------------
// Preconditions: Open public_documents\samples\tutorial\api\weldment_box3.sldprt.
//
// Postconditions:
// 1. Updates the cut list in the weldment part.
// 2. Saves the first weldment member in the FeatureManager design tree to
// RefWeldment1.sldprt, and saves the cut list properties in the parent part
// to the cut list of the new part.
// 3. Opens RefWeldment1.sldprt and updates its cut list. (This step could
// take a few minutes to complete.)
// 4. At System.Diagnostics.Debugger.Break(), press F5.
// 5. Closes RefWeldment1.sldprt.
// 6. To verify steps 2 and 3, open and inspect RefWeldment1.sldprt, which resides
// in the same folder as this macro.
//
// NOTE: Because weldment_box3.sldprt is used elsewhere, do not save changes.
//---------------------------------------------------------------------------
using SolidWorks.Interop.sldworks;
using SolidWorks.Interop.swconst;
using System.Runtime.InteropServices;
using System;
namespace CreatePartForSolidBody_CSharp.csproj
{
partial class SolidWorksMacro
{
Feature swFeat;
BodyFolder swBodyFolder;
bool updateBoolstatus;
bool boolstatus;
int longstatus;
int longWarnings;
ModelDoc2 currentModel;
ModelDoc2 swModel;
int modelType;
string modelTitle;
public void Main()
{
currentModel = (ModelDoc2)swApp.ActiveDoc;
modelTitle = currentModel.GetTitle();
modelType = currentModel.GetType();
swFeat = (Feature)currentModel.FirstFeature();
if (swFeat == null)
ErrorMsg(swApp, "Failed to get first feature");
while ((swFeat != null))
{
if (swFeat.GetTypeName2() == "SolidBodyFolder")
{
swBodyFolder = (BodyFolder)swFeat.GetSpecificFeature2();
if (swBodyFolder == null)
ErrorMsg(swApp, "Failed to get body folder");
boolstatus = swBodyFolder.SetAutomaticCutList(true);
boolstatus = swBodyFolder.UpdateCutList();
break;
}
swFeat = (Feature)swFeat.GetNextFeature();
}
updateBoolstatus = false;
swFeat = (Feature)currentModel.FirstFeature();
if (swFeat == null)
ErrorMsg(swApp, "Failed to get first feature");
while ((swFeat != null))
{
if (swFeat.GetTypeName2() == "WeldMemberFeat")
{
boolstatus = swFeat.Select2(false, 0);
if (boolstatus == false)
ErrorMsg(swApp, "Failed to select feature");
// Save the selected solid body weldment member to another part,
// transferring the solid body's cut list properties to the new part's cut list;
// automatically creates a weldment and cut list folder
boolstatus = ((PartDoc)currentModel).SaveToFile3(swApp.GetCurrentMacroPathFolder() + "\\RefWeldment1" + ".sldprt", 1, swCutListTransferOptions_e.swCutListTransferOptions_CutListProperties, false, "", out longstatus, out longWarnings);
System.Diagnostics.Debugger.Break();
if (boolstatus == false)
ErrorMsg(swApp, "Failed to insert weldment member into new part");
swModel = (ModelDoc2)swApp.ActiveDoc;
if (swModel == null)
ErrorMsg(swApp, "Failed to set open model as active document");
updateBoolstatus = true;
break;
}
swFeat = (Feature)swFeat.GetNextFeature();
}
if (updateBoolstatus == true)
{
swFeat = (Feature)currentModel.FirstFeature();
if (swFeat == null)
ErrorMsg(swApp, "Failed to get first feature");
while ((swFeat != null))
{
if (swFeat.GetTypeName2() == "SolidBodyFolder")
{
swBodyFolder = (BodyFolder)swFeat.GetSpecificFeature2();
if (swBodyFolder == null)
ErrorMsg(swApp, "Failed to get body folder");
boolstatus = swBodyFolder.SetAutomaticCutList(true);
if (boolstatus == false)
ErrorMsg(swApp, "Failed to set cut list to automatic");
boolstatus = swBodyFolder.UpdateCutList();
if (boolstatus == false)
ErrorMsg(swApp, "Failed to update cut list");
swApp.CloseDoc(swModel.GetTitle());
break;
}
swFeat = (Feature)swFeat.GetNextFeature();
}
}
}
public void ErrorMsg(SldWorks Swapp, string Message)
{
Swapp.SendMsgToUser2(Message, 0, 0);
Swapp.RecordLine("'*** WARNING - General");
Swapp.RecordLine("'*** " + Message);
Swapp.RecordLine("");
}
public SldWorks swApp;
}
}
void SetMaterialPropertyName2( System.string ConfigName,System.string Database,System.string Name)
This method shows how to get and set the material properties of a part.
//-----------------------------------------------------
// Preconditions:
// 1. Open a part.
// 2. Open the Immediate window.
//
// Postconditions:
// 1. Gets and sets the part's material visual properties.
// 2. Inspect the Immediate window and graphics area.
//------------------------------------------------------
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 ApplyAppearance_CSharp.csproj
{
partial class SolidWorksMacro
{
public void Main()
{
ModelDoc2 myModel = default(ModelDoc2);
PartDoc myPart = default(PartDoc);
MaterialVisualPropertiesData myMatVisProps = default(MaterialVisualPropertiesData);
string configName = null;
string databaseName = null;
string newPropName = null;
bool orgBlend = false;
bool orgApply = false;
double orgAngle = 0;
double orgScale = 0;
long longstatus = 0;
myModel = (ModelDoc2)swApp.ActiveDoc;
myPart = (PartDoc)myModel;
myMatVisProps = myPart.GetMaterialVisualProperties();
Debug.Print("===== Material Visual Properties Example =====");
if ((myMatVisProps != null))
{
dump_material_visual_properties(myMatVisProps, myPart);
// Set the material to something else, so that the display changes
configName = "default";
databaseName = "SOLIDWORKS Materials";
newPropName = "Beech";
myPart.SetMaterialPropertyName2(configName, databaseName, newPropName);
dump_material_visual_properties(myMatVisProps, myPart);
}
// Set the material visual properties to be just color, no advanced graphics
myMatVisProps = myPart.GetMaterialVisualProperties();
if ((myMatVisProps != null))
{
longstatus = myPart.SetMaterialVisualProperties(myMatVisProps, (int)swInConfigurationOpts_e.swThisConfiguration, null);
dump_material_visual_properties(myMatVisProps, myPart);
// Set the material visual properties to be RealView
myMatVisProps.RealView = true;
longstatus = myPart.SetMaterialVisualProperties(myMatVisProps, (int)swInConfigurationOpts_e.swThisConfiguration, null);
dump_material_visual_properties(myMatVisProps, myPart);
// Set the material visual properties to be SOLIDWORKS standard textures
myMatVisProps.RealView = false;
longstatus = myPart.SetMaterialVisualProperties(myMatVisProps, (int)swInConfigurationOpts_e.swThisConfiguration, null);
dump_material_visual_properties(myMatVisProps, myPart);
}
myMatVisProps = myPart.GetMaterialVisualProperties();
if ((myMatVisProps != null))
{
orgAngle = myMatVisProps.Angle;
myMatVisProps.Angle = orgAngle + 1.0;
longstatus = myPart.SetMaterialVisualProperties(myMatVisProps, (int)swInConfigurationOpts_e.swThisConfiguration, null);
dump_material_visual_properties(myMatVisProps, myPart);
orgScale = myMatVisProps.Scale2;
myMatVisProps.Scale2 = orgScale * 1.25;
longstatus = myPart.SetMaterialVisualProperties(myMatVisProps, (int)swInConfigurationOpts_e.swThisConfiguration, null);
dump_material_visual_properties(myMatVisProps, myPart);
// Toggle the standard texture to blend with the part color
if (myMatVisProps.BlendColor == false)
{
orgBlend = false;
}
else
{
orgBlend = true;
}
myMatVisProps.BlendColor = !orgBlend;
longstatus = myPart.SetMaterialVisualProperties(myMatVisProps, (int)swInConfigurationOpts_e.swThisConfiguration, null);
dump_material_visual_properties(myMatVisProps, myPart);
myMatVisProps.BlendColor = orgBlend;
longstatus = myPart.SetMaterialVisualProperties(myMatVisProps, (int)swInConfigurationOpts_e.swThisConfiguration, null);
dump_material_visual_properties(myMatVisProps, myPart);
// Toggle the apply material color to part flag
if (myMatVisProps.ApplyMaterialColorToPart == false)
{
orgApply = false;
}
else
{
orgApply = true;
}
myMatVisProps.ApplyMaterialColorToPart = !orgApply;
longstatus = myPart.SetMaterialVisualProperties(myMatVisProps, (int)swInConfigurationOpts_e.swThisConfiguration, null);
dump_material_visual_properties(myMatVisProps, myPart);
myMatVisProps.ApplyMaterialColorToPart = orgApply;
longstatus = myPart.SetMaterialVisualProperties(myMatVisProps, (int)swInConfigurationOpts_e.swThisConfiguration, null);
dump_material_visual_properties(myMatVisProps, myPart);
// Toggle the apply material hatch to drawing section view flag
if (myMatVisProps.ApplyMaterialHatchToSection == false)
{
orgApply = false;
}
else
{
orgApply = true;
}
myMatVisProps.ApplyMaterialHatchToSection = !orgApply;
longstatus = myPart.SetMaterialVisualProperties(myMatVisProps, (int)swInConfigurationOpts_e.swThisConfiguration, null);
dump_material_visual_properties(myMatVisProps, myPart);
myMatVisProps.ApplyMaterialHatchToSection = orgApply;
longstatus = myPart.SetMaterialVisualProperties(myMatVisProps, (int)swInConfigurationOpts_e.swThisConfiguration, null);
dump_material_visual_properties(myMatVisProps, myPart);
// Toggle the apply appearance flag
if (myMatVisProps.ApplyAppearance == false)
{
orgApply = false;
}
else
{
orgApply = true;
}
myMatVisProps.ApplyAppearance = !orgApply;
longstatus = myPart.SetMaterialVisualProperties(myMatVisProps, (int)swInConfigurationOpts_e.swThisConfiguration, null);
dump_material_visual_properties(myMatVisProps, myPart);
myMatVisProps.ApplyAppearance = orgApply;
longstatus = myPart.SetMaterialVisualProperties(myMatVisProps, (int)swInConfigurationOpts_e.swThisConfiguration, null);
dump_material_visual_properties(myMatVisProps, myPart);
}
}
private void dump_material_visual_properties(MaterialVisualPropertiesData myMatVisProps, PartDoc myPart)
{
string configName = null;
string databaseName = null;
string propName = null;
bool bRealView = false;
double dScale = 0;
double dAngle = 0;
bool bBlendColor = false;
bool bApplyColor = false;
bool bApplyHatch = false;
bool bApplyAppearance = false;
configName = "default";
databaseName = null;
propName = myPart.GetMaterialPropertyName2(configName, out databaseName);
Debug.Print("");
Debug.Print("Config: \"" + configName + "\", Database: \"" + databaseName + "\", Material: \"" + propName + "\"");
if ((myMatVisProps != null))
{
bRealView = myMatVisProps.RealView;
dScale = myMatVisProps.Scale2;
dAngle = myMatVisProps.Angle;
bBlendColor = myMatVisProps.BlendColor;
bApplyColor = myMatVisProps.ApplyMaterialColorToPart;
bApplyHatch = myMatVisProps.ApplyMaterialHatchToSection;
bApplyAppearance = myMatVisProps.ApplyAppearance;
if (bRealView == false)
{
Debug.Print("Advanced graphics - SOLIDWORKS standard textures.");
}
else
{
Debug.Print("Advanced graphics - RealView textures.");
}
Debug.Print(" SOLIDWORKS standard texture scale = " + dScale + ", Angle = " + dAngle);
if (bBlendColor == false)
{
Debug.Print(" Do not blend part color with SOLIDWORKS standard texture.");
}
else
{
Debug.Print(" Blend part color with SOLIDWORKS standard texture.");
}
if (bApplyColor == false)
{
Debug.Print("Do not apply material color to part.");
}
else
{
Debug.Print("Apply material color to part.");
}
if (bApplyHatch == false)
{
Debug.Print("Do not apply material hatch to drawing section.");
}
else
{
Debug.Print("Apply material hatch to drawing section.");
}
if (bApplyAppearance == false)
{
Debug.Print("Do not apply appearance.");
}
else
{
Debug.Print("Apply appearance.");
}
}
}
public SldWorks swApp;
}
}
更多推荐
IPartDoc Interface 学习笔记
发布评论