Checking to see if a sketch is in edit mode?

Checking to see if a sketch is in edit mode?

keithjk
Advocate Advocate
493 Views
3 Replies
Message 1 of 4

Checking to see if a sketch is in edit mode?

keithjk
Advocate
Advocate

 

I need to be able to delete a sketch in my .idw file.  The snippet below works perfectly if the sketch is not in "edit mode" but it crashes if it is in edit mode. I can place "oSketch.exitedit" in the loop but that causes it to crash if it is not in edit mode. 

 

Any suggestions on how to check to see if a sketch is in edit mode?

 

Dim oSketch As DrawingSketch = Nothing

Dim oSketches As DrawingSketches = oDrawingView.Sketches

For Each oSketch In oSketches

 If oSketch.Name = "skSubPanelSketch" Then

   oSketch.Delete()

  Exit For

 End If

Next

0 Likes
494 Views
3 Replies
Replies (3)
Message 2 of 4

keithjk
Advocate
Advocate

I guess this works.  But I would like to know if there is a cleaner way of doing it.

 

Dim oSketch As DrawingSketch = Nothing

Dim oSketches As DrawingSketches = oDrawingView.Sketches

For Each oSketch In oSketches

If oSketch.Name = "skSubPanelSketch" Then

Try

oSketch.ExitEdit()

Catch

' do nothing

End Try

oSketch.Delete()

Exit For

Debug.Print("Exiting loop")

End If

Next

0 Likes
Message 3 of 4

chandra.shekar.g
Autodesk Support
Autodesk Support

Hi KeithJK,

 

If the sketch is in edit mode, sketch can not be deleted. So, sketch needs exit form edit mode.

 

Please try the following sample code to delete sketch.

 

        Dim oSketches As DrawingSketches
        oSketches = oDrawingView.Sketches

        For Each oSketch As DrawingSketch In oSketches
            If oSketch.Name = "skSubPanelSketch" Then
                Try
                    'sketch will be deleted if it is not edit mode.
oSketch.Delete() Catch
'If sketch is in edit mode. sketch needs exit from edit mode. oSketch.ExitEdit() oSketch.Delete() End Try Exit For End If Next

 

 


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



0 Likes
Message 4 of 4

frederic.vandenplas
Collaborator
Collaborator

Hi, this is what you need, for neat environment checking.

Sub Environment()

  Dim oEnvs As Environment
  Set oEnvs = ThisApplication.UserInterfaceManager.ActiveEnvironment
  Debug.Print oEnvs.InternalName
  'When editing sketches in drawings (on drawingview), it returns: DLxDrawingSketchEnvironment

End Sub

 

If you think this answer fullfilled your needs, improved your knowledge or leads to a solution,
please feel free to "kudos"