TheSwamp
Code Red => .NET => Topic started by: MGorecki on April 11, 2011, 05:09:27 PM
-
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:
sourceBlockRef = sourceBallObjID.GetObject(DatabaseServices.OpenMode.ForRead)
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 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
-
Well, I don't do VB, but it looks like you're trying to stuff a circle into a block reference - not going to happen.
-
Yes (wearing the big red "NEWBIE" stamp on my forehead) :-)
The fix for this came from Norman Yuan (a very helpful person) at the Autodesk forum.
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
Mark