Draw in View selected principal view (VB)

Hi guys. Writing my first program as a tool for 2D drawing (VB).

Already got a button which saves the drawing to PDF in a specified path.


Now i want to add a button which saves the selected view as .dxf. 

1. Firsly the user selects the desired principal view

2. Check if only one view is selected and that it is an principal view.

3. Change Environment (only for selected view) to "DrawingViewEdit"

4. Save the file with extension ".dxf"

5. Change Environment back to "Detail"

6. Fit screen to active view


Seems pretty straightforward, but I seem to miss something.

Below the code which now changes the view of the complete sheet to draw in view.

Also need to build in check if the selected item is an drawing view.



Dim SEApplication As SolidEdgeFramework.Application
Dim SEDraftDocument As SolidEdgeDraft.DraftDocument = SEApplication.ActiveDocument
Dim SESelectSet As SolidEdgeFramework.SelectSet = SEDraftDocument.SelectSet
Dim SeSheetWindow As SolidEdgeDraft.SheetWindow = SEApplication.ActiveWindow If SESelectSet.Count = 0 Or SESelectSet.Count > 1 Then MsgBox("Selecteer één enkel aanzicht. Dit aanzicht wordt als DXF opgeslagen.", MsgBoxStyle.Information, Title:="Info") Else SeSheetWindow.Environment = "DrawingViewEdit" End If


So far steps 2,3 and 6 give me problems.

Can't find in SolidEdgeSpy where i can change to the "DrawingViewEdit" Environment.


Re: Draw in View selected principal view (VB)

Hi RickNL,

the .Environement Property only retrurns an object of the current active environement.

The only way I know is to start the appropriate command:

application.StartCommand(40037) ' Draw in View
application.StartCommand(10231) ' Exit Draw in view

 You can find the command IDs with Syp for Solid Edge (thanx to Jason), look at the Event Monitor tab and change environment manually.


Regards from Germany, Jürgen


VS2015, SE ST10

Re: Draw in View selected principal view (VB)

If you want to do it like you described, You will have to write an addin with a locator command to select the drawing view, then start the command to enter "Draw in View" and to listen to the application event to wait for the environment being changed. Then, you will need to export to DXF and start another command to return to the previous environment.

All this can make it complex, especially as environment changes are involved in the command and this typically terminates any running command.

BUT: If you can live with a simple solution you can either let the user select the drawing view or simply iterate through all principal drawing views on your active sheet and export them one by one to a separate DXF file.

The trick is here to activate the sheet of each drawing view before exporting to DXF, as long as your SEACAD.ini file defines the option to export only the active sheet.

Here is my code:

' DFT: Export all principal drawing views on the active sheet to DXF
Dim objDoc As DraftDocument = objApp.ActiveDocument
Dim strDocName As String = objDoc.FullName
strDocName = strDocName.Substring(0, strDocName.Length - 4) ' Remove the file extension ".dft"
Dim objSheet As Sheet = objDoc.ActiveSheet
Dim nView As Integer = 1
For Each objView As DrawingView In objSheet.DrawingViews
  If objView.DrawingViewType = DrawingViewTypeConstants.igPrincipleView Then
    Dim objViewSheet As Sheet = objView.Sheet
    objDoc.SaveAs(strDocName & "_" & nView & ".dxf")
    nView += 1
  End If

Re: Draw in View selected principal view (VB)

[ Edited ]

Thanks for the reactions! That's a very helpful piece of code, works like a charm as you described it would.

Iterates through all views and then saves them one by one as .dxf 

I can live with the simple solution.


One small deviation, if I understand you correctly; You mentioned that i could let the user select the drawing view which needs to be saved as .dxf. That would be the workable solution, and exactly what i want to accomplish.

So not 'For' Each objView' but only for the objView which is selected by the user.

Or is that the the complex way you described, with the addin?


On side note (just occured to me): the selected view (to be converted to .dxf) can either be an pricipal view or the flat pattern.

Re: Draw in View selected principal view (VB)

Hallo Jürgen! Danke für dein Tipp! Die Event Monitor tab hätte ich eigentlich noch nicht so gebraucht. Gute Arbeitsweise um ein Code hinter ein Kommando heraus zu finden.

Re: Draw in View selected principal view (VB)


if you need to select the view, please check the MouseEvents and EventHandling samples from Jason Newell (Samples on GitHub). They show you how to handle mouse events and react on selection...

Re: Draw in View selected principal view (VB)

Ok Martin, thanks. I will check them out. Combine them with the code you provided to get it working!