Hide Table of Contents

Creating Polysolid Entities Example (C#)

This example shows how to create 3D polysolids.

//--------------------------------------------------------------
// Preconditions:
// 1. Create a C# Windows console project.
// 2. Copy and paste this example into the C# IDE.
// 3. Add a reference to:
//    install_dir\APISDK\tlb\DraftSight.Interop.dsAutomation.dll
// 4. Add references to System and System.Windows.Forms.
// 5. Start DraftSight.
// 6. Press F5 to debug the project.
//
// Postconditions: 
// 1. Inserts a 2D polyline.
// 2. Creates a 3D polysolid using the 2D polyline.
// 3. Creates an array of coordinates.
// 4. Creates a 3D polysolid using the coordinates. 

//----------------------------------------------------------------

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

using System.Runtime.InteropServices;

using DraftSight.Interop.dsAutomation;

using System.Windows.Forms;

 

namespace PolysolidConsoleApp1

{

    class Program

    {

        static void Main(string[] args)

        {

            //Connect to DraftSight application

            DraftSight.Interop.dsAutomation.Application application = ConnectToDraftSight();

            if (null == application)

            {

                return;

            }

 

            application.AbortRunningCommand(); // abort any command currently running in DraftSight to avoid nested commands

            Document dsDoc = application.GetActiveDocument();

            if (null == dsDoc)

            {

                return;

            }

 

            Model dsModel = dsDoc.GetModel();

            if (null == dsModel)

            {

                return;

            }

 

            SketchManager dsSketchManager = dsModel.GetSketchManager();

            if (null == dsSketchManager)

            {

                return;

            }

 

            PolyLine dsPolyline;

            {

                dsPolyline = dsSketchManager.InsertPolyline2D(

                 new double[] { 0.8839, 7.3348, 0.8839, 6.0943, 9.3647, 6.0943, 9.3647, 7.3348 },

                 true);

            }

 

            DispatchWrapper[] dsEntities = new DispatchWrapper[1];

            dsEntities[0] = new DispatchWrapper(dsPolyline);

 

            dsSketchManager.PolysolidByEntities(dsEntities, 4.0, 0.25, dsPolySolidJustification_e.dsPolySolidJustification_Left);

 

 

            double[] coordinatesArray = new double[] { 0.6339, 3.9955, 9.3647, 3.9955 };

 

            dsSketchManager.PolysolidByCoordinates(coordinatesArray, 4.0, 0.25, dsPolySolidJustification_e.dsPolySolidJustification_Left);

 

            ViewManager dsViewManager = dsDoc.GetViewManager();

            if (null != dsViewManager)

                dsViewManager.SetPredefinedView(dsPredefinedView_e.dsPredefinedView_SWIsometric);

            application.Zoom(dsZoomRange_e.dsZoomRange_Bounds, null, null);

        }

        public static DraftSight.Interop.dsAutomation.Application ConnectToDraftSight()

        {

            

            DraftSight.Interop.dsAutomation.Application dsApp = null;

 

            try

            {

                //Connect to DraftSight

                dsApp = (DraftSight.Interop.dsAutomation.Application)Marshal.GetActiveObject("DraftSight.Application");

            }

            catch (Exception ex)

            {

                MessageBox.Show("Failed to connect to DraftSight. Cause: " + ex.Message);

                dsApp = null;

            }

 

            return dsApp;

        }

    }

}

 



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:   Creating Polysolid Entities 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) 2020 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.