Add Decal Example (C#)
This example shows how to add a decal to a selected face on a part.
//----------------------------------------------------------------------------
// Preconditions:
// 1. Open a part document that contains a model.
// 2. Ensure that the specified decal files exist.
// 3. Select a face on the model.
// 4. Select Tools > Add-ins > PhotoView 360.
//
// Postconditions: A decal is applied to the selected face.
//----------------------------------------------------------------------------
using
SolidWorks.Interop.sldworks;
using
SolidWorks.Interop.swconst;
using
System.Runtime.InteropServices;
using
System;
namespace
AddDecal_CSharp.csproj
{
public
partial
class
SolidWorksMacro
{
public
void Main()
{
ModelDoc2
swModel;
SelectionMgr
swSelMgr;
ModelDocExtension
swModelDocExt;
Face2
swFace;
Decal
swDecal;
RenderMaterial
swMaterial;
Boolean
boolstatus;
String
strName;
int
nDecalID = 0;
swModel = (ModelDoc2)swApp.ActiveDoc;
swSelMgr = (SelectionMgr)swModel.SelectionManager;
swModelDocExt = (ModelDocExtension)swModel.Extension;
swFace = (Face2)swSelMgr.GetSelectedObject6(1,
-1);
swModel.ClearSelection2(true);
swDecal = swModelDocExt.CreateDecal();
swMaterial = (RenderMaterial)swDecal;
boolstatus = swMaterial.AddEntity(swFace);
strName = "C:\\Program
Files\\SolidWorks Corp\\SolidWorks\\data\\graphics\\Decals\\Logos\\sw.p2d";
swMaterial.FileName = strName;
strName = "C:\\Program
Files\\SolidWorks Corp\\SolidWorks\\data\\graphics\\Decals\\Logos\\sw.bmp";
swMaterial.TextureFilename = strName;
swMaterial.MappingType = 0;
swMaterial.FixedAspectRatio =
false;
swMaterial.FitHeight =
true;
swMaterial.FitWidth =
true;
boolstatus = swModelDocExt.AddDecal(swDecal,
out nDecalID);
swModel.Rebuild((int)swRebuildOptions_e.swRebuildAll);
}
public
SldWorks
swApp;
}
}