Hide Table of Contents
RunCommand2 Method (IApplication)

Runs the specified command.

.NET Syntax

Visual Basic (Declaration) 
Function RunCommand2( _
   ByVal CommandString As System.String, _
   ByVal ParameterStrArray As System.Object, _
   ByVal ParameterTypeLongArray As System.Object, _
   ByVal HideCommandTitle As System.Boolean _
) As dsRunCommandError_e
dsRunCommandError_e RunCommand2( 
   System.string CommandString,
   System.object ParameterStrArray,
   System.object ParameterTypeLongArray,
   System.bool HideCommandTitle
function RunCommand2( 
   CommandString : System.String,
   ParameterStrArray : System.Object,
   ParameterTypeLongArray : System.Object,
   HideCommandTitle : System.boolean
) : dsRunCommandError_e;
Managed Extensions for C++ 
dsRunCommandError_e RunCommand2( 
   System.string* CommandString,
   System.Object* ParameterStrArray,
   System.Object* ParameterTypeLongArray,
   System.bool HideCommandTitle
dsRunCommandError_e RunCommand2( 
&   System.String^ CommandString,
&   System.Object^ ParameterStrArray,
&   System.Object^ ParameterTypeLongArray,
&   System.bool HideCommandTitle


Name of command to run (see Remarks)
Array of parameters to execute with the command
Array of ParameterStrArray types as defined by dsResType_e; the size of this array much match the size of ParameterStrArray
True to hide the command in the command window, false to show the command in the command window

Return Value

Status of running the command as defined in dsRunCommandError_e


Create a C++ program in Visual Studio using the C++ snippet below, substituting your_pdf with the full path to a PDF file on your computer.


C++ snippet attaches and detaches your_pdf


dsCommandMessage_ptr commandline;



dsRunCommandError_e error = dsRunCommand_InvalidCommand;

dsStringArray parameters;

dsLongArray parametersLong;

dsString strFile = L"your_pdf";

dsResType_e type = dsResType_String;

parameters.add( strFile );

parametersLong.add( type );


application->RunCommand2( L"_ATTACHPDF", parameters, parametersLong, true, &error );

commandline->PrintLine( error != dsRunCommand_Succeeded ? L"Run command failed" : L"Run command passed!" );


dsDocument_ptr document;

application->GetActiveDocument( &document );


dsLongArray ExternalDefinitionTypeLongArray;

dsObjectPtrArray ExternalDefinitionsArray;

document->GetImmediateChildReferences( &ExternalDefinitionTypeLongArray, &ExternalDefinitionsArray );


dsModel_ptr dsModel;

document->GetModel( &dsModel );


dsSketchManager_ptr sketchManager;

dsModel->GetSketchManager( &sketchManager );


dsPdfDefinition_c* pdfDefinition = ( dsPdfDefinition_c* )ExternalDefinitionsArray[ 0 ];


bool bRet;

sketchManager->DetachPdfDefinition( pdfDefinition, &bRet );

commandline->PrintLine( bRet ? L"Passed to detach Pdf" : L"Failed to detach PDF" );



Depending on the programming language that you use, either:

  • append \n to the command
    - or -
  • include & Chr(10) after the command

    These control strings emulate a user pressing the Enter key in DraftSight. The number of control strings should correspond to the number of times a user is required to press the Enter key for the command in DraftSight.

For example: 

To delete all entities in a drawing in this programming language... Call...

int state;

state = (int)dsApp.RunCommand("DELETE ALL\n\n", false);


Dim state as Integer;

state = dsApp.RunCommand("DELETE ALL" & Chr(10) & Chr(10), False)


Dim state as Long;

state = dsApp.RunCommand("DELETE ALL" & Chr(10) & Chr(10), False)



See Also


DraftSight 2024 SP02

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

Subject:   Feedback on Help Topics
Page:   RunCommand2 Method (IApplication)
*   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:


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

Web Help Content Version: API Help (English only) 2024 SP03

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.