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
Solved! Go to Solution.
Solved by norman.yuan. Go to Solution.
Ok, my mistake. It's actually locking up at the line:
sourceBlockRef = sourceBallObjID.GetObject(DatabaseServices.OpenMode.ForRead)
So any help would still be appreciated.
Thanks,
Mark
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.OpenMode.ForRead), BlockReference)
If sourceBlockRef IsNot Nothing then
sourceBallCenter = sourceBlockRef.Position
End If
Next
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
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.OpenMode.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
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