Dak22 Dak22 - 5 months ago 14
Vb.net Question

DraftSight API - MoveEntities via VB.Net

I have a VB.Net program that will open a .dwg and then give the user the ability to add “part blocks” to the drawing.

However, I need to be able to shift all the components in the drawing at one time.

How do I “Select All” from the API in DraftSight? The code below is what I have got started.

'Connect to DraftSight
dsApp = GetObject(, "DraftSight.Application")

'Get active document
dsDoc = dsApp.GetActiveDocument()
If Not dsDoc Is Nothing Then

'Get model space
dsModel = dsDoc.GetModel()

'Get Sketch Manager
dsSketchManager = dsModel.GetSketchManager()


'Basic Command I want to use to Move Selection
' - MOVE
' - Specify Entities = SelectALL
' - Specify Entities = "Enter"
' - Specify from Point = insertX, insertY
' - Specify destination = 0,0

'Move instance parameters
Dim Move_Instance As ISketchManager

Dim insertX As Double
insertX = 5.0
Dim insertY As Double
insertY = 10.0
Dim insertZ As Double
insertZ = 0.0

Dim SelectALL As Object

'Move Selection
Move_Instance = dsApp.GetActiveDocument().GetModel().GetSketchManager.MoveEntities(insertX, insertY, insertZ, SelectALL)

Else
MsgBox("There are no open documents in DraftSight")
End If

Answer

After some trial and error, I decide a way to do what I am looking for is to just use the “RunCommand” feature. Below is what I did…

        Dim dsApp As DraftSight.Application
    Dim dsDoc As DraftSight.Document
    Dim dsModel As DraftSight.Model
    Dim dsSketchManager As DraftSight.SketchManager
    Dim dsViewManager As DraftSight.ViewManager

    'Connect to DraftSight
    dsApp = GetObject(, "DraftSight.Application")
    'Abort any command currently running in DraftSight
    'to avoid nested commands
    dsApp.AbortRunningCommand()

    'Get active document
    dsDoc = dsApp.GetActiveDocument()
    If Not dsDoc Is Nothing Then

        'Get model space
        dsModel = dsDoc.GetModel()

        'Get Sketch Manager
        dsSketchManager = dsModel.GetSketchManager()

        Dim dsSheet As DraftSight.Sheet
        Dim dsVarSheets As Object
        dsVarSheets = dsDoc.GetSheets
        dsSheet = dsVarSheets(1)
        If dsSheet Is Nothing Then
            Return
        End If

        'Get View Manager
        dsViewManager = dsDoc.GetViewManager()

        'Select All and Move to location 0,0
        Dim Move As Integer
        Move = dsApp.RunCommand("MOVE ALL  -5.0,-10.0  0.0,0.0", False)
    Else
        MsgBox("There are no open documents in DraftSight")
    End If
Comments