.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How do I Select Only One object Using a Window

5 REPLIES 5
SOLVED
Reply
Message 1 of 6
mgorecki
466 Views, 5 Replies

How do I Select Only One object Using a Window

 Hello,

In the code below, I am using a window to select a circle in the drawing.  I'm using a window because of the fudge factor in the placement of circles.  The problem is, when it gets to the line:

 

 

sourceBallObjIDs = New DatabaseServices.ObjectIdCollection(sourceBallSelectionSet.GetObjectIds)

 

The program hangs.  I'm new to working with selection sets, so if anyone can help me out with this one I'd really appreciate it. 

 

Dim sourceBallPSR As EditorInput.PromptSelectionResult

Dim sourceBallSelectionSet As EditorInput.SelectionSet

Dim sourceBallObjIDs As DatabaseServices.ObjectIdCollection

Dim sourceBallObjID As DatabaseServices.ObjectId

 

Dim bgaFilter(0) As DatabaseServices.TypedValue

bgaFilter(0) = New DatabaseServices.TypedValue(DatabaseServices.DxfCode.Start, "CIRCLE")

Dim bgaSSFilter As New EditorInput.SelectionFilter(bgaFilter)

' Select the first ballpad circle using a window

sourceBallPSR = myEd.SelectWindow(sourceWinPnt1, sourceWinPnt2, bgaSSFilter)

' If a cicle is selected

If Not IsNothing(sourceBallPSR.Value) Then 

   sourceBallSelectionSet = sourceBallPSR.Value

   sourceBallObjIDs = New DatabaseServices.ObjectIdCollection(sourceBallSelectionSet.GetObjectIds)

   For Each sourceBallObjID In sourceBallObjIDs

     Dim sourceBlockRef As DatabaseServices.BlockReference

       sourceBlockRef = sourceBallObjID.GetObject(DatabaseServices.OpenMode.ForRead)

       sourceBallCenter = sourceBlockRef.Position

    Next  

myBT = myDWG.Database.BlockTableId.GetObject(DatabaseServices.OpenMode.ForRead)

myBTR = myBT(DatabaseServices.BlockTableRecord.ModelSpace).GetObject(DatabaseServices.OpenMode.ForWrite)

 

'Draw the circle

Dim newCircle1 As New DatabaseServices.Circle(sourceBallCenter, New Geometry.Vector3d(0, 0, 1), (ballSize / 4))True)

myBTR.AppendEntity(newCircle1)

myTrans.AddNewlyCreatedDBObject(newCircle1,

sourceBallCount = 1

 :

:

:

 

Thanks,

Mark

5 REPLIES 5
Message 2 of 6
mgorecki
in reply to: mgorecki

Ok, my mistake.  It's actually locking up at the line:

 

sourceBlockRef = sourceBallObjID.GetObject(DatabaseServices.OpenMod​e.ForRead)

 

So any help would still be appreciated.

 

Thanks,
Mark

Message 3 of 6
norman.yuan
in reply to: mgorecki

So, you want the Editor select a set of entities with selecting filter being set to "CIRCLE", and after the selecting, you loop through the selected objectIds to try to get BlockReference from the SelectionSet. It does not make sense to me. That is, the selectionSet does not give you back a single BlockReference.

 

However, you still can write defensive code doing (such meaningless) thing without crashing AutoCAD:

 

For Each sourceBallObjID In sourceBallObjIDs

     Dim sourceBlockRef As DatabaseServices.BlockReference

       sourceBlockRef = TryCast(sourceBallObjID.GetObject(DatabaseServices.OpenMod​e.ForRead), BlockReference)

       If sourceBlockRef IsNot Nothing then

           sourceBallCenter = sourceBlockRef.Position

       End If

Next  

Norman Yuan

Drive CAD With Code

EESignature

Message 4 of 6
mgorecki
in reply to: norman.yuan

Hi Norman,

Actuallty the window is used to select only one circle at a time.  So maybe I'm going about it all worng. 

I have an array of circles (some circles may be missing from the array) and the window is only big enough to select one circle.  If a circle is not selected (it's just not there), then it will loop and move the window over to the left to select the next circle.  If a circle is selected, thenI just want to get the coordinate for the circle center.

 

Thanks,

Mark

Message 5 of 6
norman.yuan
in reply to: mgorecki

This was what I was wondering: why did you loop through the SelectioonSet for a BlockReference, if the selecctionset only selects Circle?

 

You can simply

 

For Each sourceBallObjID In sourceBallObjIDs

       Dim sourceCir As Circle = TryCast(sourceBallObjID.GetObject(DatabaseServices​.OpenMod​e.ForRead), Circle)

       If sourceCir IsNot Nothing then

           sourceBallCenter = sourceCir.Center

           Exit For ''Since you only need one circle to be selected

       End If

Next  

Norman Yuan

Drive CAD With Code

EESignature

Message 6 of 6
mgorecki
in reply to: norman.yuan

Hi Norman,

Thank you very much for your help.  Your suggestion works great.  Being new to VB.Net with AutoCad, I am learning through books and online (slowly, but surely) so your help is greatly appreciated.

 

Thanks again and have a great day.

Mark

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost