Author Topic: Program Locking Up Wrying to Get BlockRef  (Read 2221 times)

0 Members and 1 Guest are viewing this topic.

MGorecki

  • Guest
Program Locking Up Wrying to Get BlockRef
« 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.OpenMod​e.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.DxfCo​de.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.OpenMod​e.ForRead)
       sourceBallCenter = sourceBlockRef.Position
    Next 

myBT = myDWG.Database.BlockTableId.GetObject(DatabaseServ​ices.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

Glenn R

  • Guest
Re: Program Locking Up Wrying to Get BlockRef
« Reply #1 on: April 11, 2011, 05:26:13 PM »
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.

MGorecki

  • Guest
Re: Program Locking Up Wrying to Get BlockRef
« Reply #2 on: April 12, 2011, 11:40:48 AM »
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​.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 

Mark