Jump to content

Recommended Posts

Posted

Hi

 

I want to know how to erase a part of a drawing (by VBA).

 

The zone to erase will be alway the same on each drawing

I want to do by a windows selection (point1: 0,0,0 point2: 10,15,0)

 

I try by using acSelectionSetWindows but that does'nt work

 

Thanks

 

ps : Here what I tested. I know there are several lines to put at the garbage, but I keep all the lines of codes who were tested

 

Private Sub test()

   Dim ObjSelection As AcadSelectionSet
   Dim ObjetOut As AcadEntity

   Dim Point1(0 To 2) As Double
   Dim Point2(0 To 2) As Double
   Dim Point3(0 To 5) As Double
   'Data
   Point1(0) = 0#
   Point1(1) = 0#
   Point1(2) = 0#
   Point2(0) = 10#
   Point2(1) = 15#
   Point2(2) = 0#

   Point3(0) = 0#
   Point3(1) = 0#
   Point3(2) = 0#
   Point3(3) = 10#
   Point3(4) = 15#
   Point3(5) = 0#

    On Error Resume Next
    'set ObjSelection = ThisDrawing.PaperSpace.Item
   '. SelectionSets.Item.SelectByPolygon(acSelectionSetWindowPolygon, Point3)

   ObjSelection.Clear
   Set ObjetOut = ObjSelection.Select acSelectionSetWindow, Point1, Point2

   'ByPolygon acSelectionSetWindow, Point3

   'ObjSelection.Select acSelectionSetWindow, Point1, Point2
    'Set ObjSelection = SelectionSets.Item

 '  objSelection.Clear
 '   Set objObjet = objSelection
 '   objSelection.AddItems objObjets
 '  objSelection.Erase

   'objSelection.SelectByPolygon(acSelectionSetWindowPolygon, 0,0,0 10,15,0)
   'Set objselectionset = selectionsetscollection.Add(strCartouche)

End Sub

Posted

Give this a try.

 

Private Sub test()

   Dim ObjSelection As AcadSelectionSet
   Dim ObjetOut As AcadEntity

   Dim Point1(0 To 2) As Double
   Dim Point2(0 To 2) As Double
   Dim Point3(0 To 5) As Double
   'Data
   Point1(0) = 0#
   Point1(1) = 0#
   Point1(2) = 0#
   Point2(0) = 10#
   Point2(1) = 15#
   Point2(2) = 0#

     On Error Resume Next
     ThisDrawing.SelectionSets.Item("TempSSet").Delete
     On Error GoTo 0
     
     Set ObjSelection = ThisDrawing.SelectionSets.Add("TempSSet")
   ObjSelection.Select acSelectionSetWindow, Point1, Point2
   
   For Each ObjetOut In ObjSelection
     ObjetOut.Delete
   Next

  ThisDrawing.Regen acAllViewports
End Sub

Posted

Thanks

That works perfectly.

 

I have a another question, what is ("TempSSet")?

Posted

When implemented from VBA, selection sets are required to have a name. If a VBA routine tries to create a named selection set that already exist and/or tries to delete a named selection set that does not exist, the routine will crash. There are a couple of ways to deal with those issues; the method I used (the statement between the two “On Error”s) is the most basic.

Posted

Thanks for the hints. Moreover, thanks for taking your time to answer our question

  • 3 weeks later...
Posted

Hi me again!

 

I forgot, I have to kept a few information. This information is not on the same layer on each drawing.

So it's possible to erase part of the drawing but only on one layer, to do a "filter" before erasing the entity?:?

 

Thanks

Posted

Yes, all of the Selection methods (though, not Thisdrawing.Utility.GetEntity) support filtering.

 

This thread has and example of using selection filtered by Layer. The example employs the acSelectionSetAll mode, but would work equally well with acSelectionSetWindow.

 

http://www.cadtutor.net/forum/showthread.php?t=38124

Posted

Your fast!

Thanks for the links, I didn't saw this tread

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...