Hide Table of Contents

Get Virtual Sharp Witness Line Data Example (C#)

This example shows how to get the geometry data of all of the virtual sharp witness lines in a drawing.

//----------------------------------------------------------------------------
// Preconditions: Open the drawing of a part that contains one or more
// virtual sharps with witness lines.
//
// Postconditions: Inspect the Immediate Window for virtual sharp witness line
// geometry data.
// ---------------------------------------------------------------------------
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 GetWitnessGeomInfo_CSharp.csproj
{
    
partial class SolidWorksMacro
    {
        
ModelDoc2 swModel;
        
DrawingDoc pDrawing;
        
View swView;
        
int Count;
        
int size;
        
Double[] entitiesData;
        
int index;
        
int entityCounts;
        
int entType;
        
int linesCount;
        
int arcsCount;
        
int VirtualSharpNum;
        
int j;

        
public void Main()
        {
            swModel = (
ModelDoc2)swApp.ActiveDoc;
            pDrawing = (
DrawingDoc)swModel;

            swView = (
View)pDrawing.GetFirstView();

            
while ((swView != null))
            {
                
Debug.Print("Drawing view: " + swView.Name);

                Count = swView.GetWitnessEntitiesCount(
out size);

                
Debug.Print("  Number of virtual sharp witness lines: " + Count);
                
Debug.Print("  Size of virtual sharp witness line geometry data array: " + size);

                
if ((Count > 0))
                {
                    entitiesData = (
double[])swView.GetWitnessGeomInfo();

                    
if ((entitiesData != null))
                    {
                        VirtualSharpNum = 0;
                        index = 0;
                        entityCounts = 0;
                        
while (entityCounts < Count - 1)
                        {
                            
Debug.Print("    Virtual sharp " + VirtualSharpNum);
                            
Debug.Print("      Color: " + entitiesData[index]);
                            index = index + 1;
                            
Debug.Print("      Line style (swLineStyles_e): " + entitiesData[index]);
                            index = index + 1;
                            
Debug.Print("      Line weight: (swLineWeights_e): " + entitiesData[index]);
                            index = index + 1;
                            
Debug.Print("      Layer ID: " + entitiesData[index]);
                            index = index + 1;
                            
Debug.Print("      Layer override (swLayerOverride_e):" + entitiesData[index]);
                            index = index + 1;

                            entType = (
int)entitiesData[index];
                            
Debug.Print("      Entity type: " + entType);
                            
if ((entType == 0))
                            {
                                index = index + 1;
                                linesCount = (
int)entitiesData[index];
                                
Debug.Print("      Line count: " + linesCount);
                                index = index + 1;

                                
for (j = 0; j <= linesCount - 1; j++)
                                {
                                    
Debug.Print("        Start: x =" + entitiesData[index] + " y =" + entitiesData[index + 1] + " z =" + entitiesData[index + 2]);
                                    index = index + 3;
                                    
Debug.Print("        End:   x =" + entitiesData[index] + " y =" + entitiesData[index + 1] + " z =" + entitiesData[index + 2]);
                                    index = index + 3;
                                }
                                entityCounts = entityCounts + linesCount;
                            }

                            entType = (
int)entitiesData[index];
                            
Debug.Print("      Entity type: " + entType);
                            
if ((entType == 1))
                            {
                                index = index + 1;
                                arcsCount = (
int)entitiesData[index];
                                
Debug.Print("      Arc count: " + arcsCount);
                                index = index + 1;

                                
for (j = 0; j <= arcsCount - 1; j++)
                                {
                                    
Debug.Print("        Start:  x =" + entitiesData[index] + " y =" + entitiesData[index + 1] + " z =" + entitiesData[index + 2]);
                                    index = index + 3;
                                    
Debug.Print("        End:    x =" + entitiesData[index] + " y =" + entitiesData[index + 1] + " z =" + entitiesData[index + 2]);
                                    index = index + 3;
                                    
Debug.Print("        Center: x =" + entitiesData[index] + " y =" + entitiesData[index + 1] + " z =" + entitiesData[index + 2]);
                                    index = index + 3;
                                    
Debug.Print("        Normal: x =" + entitiesData[index] + " y =" + entitiesData[index + 1] + " z =" + entitiesData[index + 2]);
                                    index = index + 3;
                                }

                                entityCounts = entityCounts + arcsCount;

                            }

                            VirtualSharpNum = VirtualSharpNum + 1;

                        }

                    }
                }

                swView = (
View)swView.GetNextView();

            }

        }

        
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:   Get Virtual Sharp Witness Line Data 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) 2018 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.