Hide Table of Contents

Add Decal Example (VB.NET)

This example shows how to add a decal to a selected face on a part.

'----------------------------------------------------------------------------
' Preconditions:
' 1. Verify that the specified part document to open exists.
' 2. Verify that the specified decal files exist.
' 3. Select Tools > Add-ins > PhotoView 360.
' 4. Open the Immediate window.
'
' Postconditions:
' 1. Opens the specified part document.
' 2. Selects the face where to apply a decal.
' 3. Applies a decal to the selected face.
' 4. Gets the properties of the decal and prints them
'    to the Immediate window.
' 5. Examine the graphics area and the Immediate window.
'
' NOTE: Because the part is used elsewhere, do not save changes.
'----------------------------------------------------------------------------
Imports SolidWorks.Interop.sldworks
Imports SolidWorks.Interop.swconst
Imports System.Runtime.InteropServices
Imports System
Imports System.Diagnostics
 
Partial Class SolidWorksMacro
 
    Public Sub main()
 
        Dim swModel As ModelDoc2
        Dim swSelMgr As SelectionMgr
        Dim swModelDocExt As ModelDocExtension
        Dim swFace As Face2
        Dim swDecal As Decal
        Dim swMaterial As RenderMaterial
        Dim swFaceDecalPropertiesArray() As Object
        Dim swFaceDecalProperties As FaceDecalProperties
        Dim status As Boolean
        Dim strname As String
        Dim nDecalID As Integer
        Dim i As Integer
        Dim errors As Integer
        Dim warnings As Integer
        Dim fileName As String
        Dim nbrDecals As Integer
 
        'Open part document and select face where to 
        'apply a decal
        fileName = "C:\Program Files\SolidWorks Corp\SolidWorks\samples\tutorial\tolanalyst\minimum_clearance\top_plate.sldprt"
        swModel = swApp.OpenDoc6(fileName, swDocumentTypes_e.swDocPART, swOpenDocOptions_e.swOpenDocOptions_Silent, "", errors, warnings)
        swSelMgr = swModel.SelectionManager
        swModelDocExt = swModel.Extension
        status = swModelDocExt.SelectByID2("""FACE", -0.00374778769440809, 0.0609129688728558, 0.0160000000000196, False, 0, Nothing, 0)
        swFace = swSelMgr.GetSelectedObject6(1, -1)
        swModel.ClearSelection2(True)
 
        'Create the decal
        swDecal = swModelDocExt.CreateDecal
        swMaterial = swDecal
        status = 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
        status = swModelDocExt.AddDecal(swDecal, nDecalID)
 
        'Rebuild the model
        Call swModelDocExt.Rebuild(swRebuildOptions_e.swRebuildAll)
 
        'Get decal properties
        status = swModelDocExt.SelectByID2("""FACE", -0.00374778769440809, 0.0609129688728558, 0.0160000000000196, False, 0, Nothing, 0)
        swFace = swSelMgr.GetSelectedObject6(1, -1)
        nbrDecals = swFace.GetDecalsCount
        Debug.Print("Number of decals applied to this face: " & nbrDecals)
        If nbrDecals > 0 Then
            swFaceDecalPropertiesArray = swFace.GetAllDecalProperties
            For i = 0 To UBound(swFaceDecalPropertiesArray)
                swFaceDecalProperties = swFaceDecalPropertiesArray(i)
                Debug.Print("Decal " & i + 1 & "'s texture:")
                Debug.Print("  Angle: " & swFaceDecalProperties.TextureAngle)
                Debug.Print("  Angle UV: " & swFaceDecalProperties.TextureAngleUV)
                Debug.Print("  File: ")
                Debug.Print("     Name: " & swFaceDecalProperties.TextureFilename)
                Debug.Print("     ID: " & swFaceDecalProperties.TextureFilenameID)
                Debug.Print("  ID: " & swFaceDecalProperties.TextureID)
                Debug.Print("  Map ID: " & swFaceDecalProperties.TextureMapID)
                Debug.Print("  Mirrored? " & swFaceDecalProperties.TextureMirrored)
                Debug.Print("  Render mode (0 = Image; 1 = Luminance):  " & swFaceDecalProperties.TextureRenderMode)
                Debug.Print("  Translation: ")
                Debug.Print("      U: " & swFaceDecalProperties.TextureTranslationU)
                Debug.Print("      V: " & swFaceDecalProperties.TextureTranslationV)
                Debug.Print("      X: " & swFaceDecalProperties.TextureTranslationX)
                Debug.Print("      Y: " & swFaceDecalProperties.TextureTranslationY)
                Debug.Print("  UV scale: ")
                Debug.Print("      U: " & swFaceDecalProperties.TextureUScale)
                Debug.Print("      V: " & swFaceDecalProperties.TextureVScale)
            Next i
        End If
 
    End Sub
 
    ''' <summary>
    ''' The SldWorks swApp variable is pre-assigned for you.
    ''' </summary>
    Public swApp As SldWorks
 
 
End Class

 



Provide feedback on this topic

SOLIDWORKS welcomes your feedback concerning the presentation, accuracy, and thoroughness of the documentation. Use the form below to send your comments and suggestions about this topic directly to our documentation team. The documentation team cannot answer technical support questions. Click here for information about technical support.

* Required

 
*Email:  
Subject:   Feedback on Help Topics
Page:   Add Decal Example (VB.NET)
*Comment:  
*   I acknowledge I have read and I hereby accept the privacy policy under which my Personal Data will be used by Dassault Systèmes

Print Topic

Select the scope of content to print:



x

We have detected you are using a browser version older than Internet Explorer 7. For optimized display, we suggest upgrading your browser to Internet Explorer 7 or newer.

 Never show this message again
x

Web Help Content Version: API Help (English only) 2015 SP05

To disable Web help from within SOLIDWORKS and use local help instead, click Help > Use SOLIDWORKS Web Help.

To report problems encountered with the Web help interface and search, contact your local support representative. To provide feedback on individual help topics, use the “Feedback on this topic” link on the individual topic page.