Hide Table of Contents

Flip Sketch Picture Example (C#)

This example shows how to flip a sketch picture.

//----------------------------------------------------------------------------
// Preconditions:
// 1. Verify that the specified document template exists.

// 2. Copy an image file (i.e., .bmp.gif.jpg.jpeg.tif.wmf) to
//    c:\temp.
// 3. Replace image_file in the ISketchManager::InsertSketchPicture parameter
//    with the name of the copied file.
// 4. Open an Immediate window.
//
// Postconditions:
// 1. Creates a new model document.
// 2. Creates Sketch1 and Sketch Picture1 in the graphics area and the
//    FeatureManager design tree.
// 3. Selects Sketch Picture1 and flips it top to bottom.
// 4. Inspect the Immediate window.
//----------------------------------------------------------------------------
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 FlipSketchPicture_CSharp.csproj
{
    partial class SolidWorksMacro
    {
 
        ModelDoc2 swModel;
        Feature swFeat;
        SketchPicture swSketchPicture;
        SelectionMgr swSelMgr;
        bool boolstatus;
        double width;
        double height;
        double angle;
 
        public void Main()
        {
            swModel = (ModelDoc2)swApp.NewDocument("C:\\ProgramData\\SolidWorks\\SOLIDWORKS 2015\\templates\\Part.prtdot", 0, 0, 0);
            swModel = (ModelDoc2)swApp.ActiveDoc;
 
            swSelMgr = (SelectionMgr)swModel.SelectionManager;
            swModel.SketchManager.InsertSketch(true);
            swSketchPicture = swModel.SketchManager.InsertSketchPicture2("c:\\temp\\image_file", false);
            swModel.SketchManager.InsertSketch(true);
 
            boolstatus = swModel.Extension.SelectByID2("Sketch Picture1""SKETCHBITMAP", 0, 0, 0, false, 0, null, 0);
            swFeat = (Feature)swSelMgr.GetSelectedObject6(1, -1);
 
            Debug.Print("Feature name = " + swFeat.Name);
 
            boolstatus = swSketchPicture.Flip(false);
            Debug.Print("  Sketch picture flipped? " + swSketchPicture.Flipped);
 
            swSketchPicture.GetSize(ref width, ref height);
            Debug.Print("  Width: " + width * 1000 + " mm");
            Debug.Print("  Height: " + height * 1000 + " mm");
 
            angle = swSketchPicture.Angle;
            //1 radian = 180º/p = 57.295779513º or approximately 57.3º
            Debug.Print("  Angle: " + angle * 57.3 + " degrees");
 
        }
 
        /// <summary>
        /// The SldWorks swApp variable is pre-assigned for you.
        /// </summary>
 
        public SldWorks swApp;
 
    }
 
}
 

 



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:   Flip Sketch Picture Example (C#)
*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) 2019 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.