Starting in December, we will archive content from the community that is 10 years and older. This FAQ provides more information.
I am embarrassed to ask this, but I need help...
I insert a block using .Net. That's ok, but after the block is inserted I am unable to select anything on the screen and I mean anything! I need to hit the escape button and then regen in order to be able to select the block.
I have tried:
Dim brefIds As ObjectIdCollection = btr.GetBlockReferenceIds(False, True)
For Each id As ObjectId In brefIds
Dim bref As BlockReference = tr.GetObject(id, OpenMode.ForWrite, False, True)
bref.RecordGraphicsModified(True)
Next
Also:
tr.TransactionManager.QueueForGraphicsFlush()
But to no avail! Why am I not able to access anything until escaping and regen? It is driving me crazy. Basically, I have a floating Pallette that calls up this command:
<CommandMethod("UDC_TPInsert")> Public Shared Sub InsertBlocks()
Dim doc As Document = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument
Dim db As Database = HostApplicationServices.WorkingDatabase
Dim ed As Editor = doc.Editor
Dim blkName As String = My.Settings.BlockName
Dim blkLay As String = My.Settings.BlockScale
Dim bSc As Double = My.Settings.BlockLayer
Dim cLay As String = Nothing
Dim ObjId As ObjectId
Dim pr As PromptResult
Dim dRot As Double
Dim attrot As Double = 0
Dim info As DatabaseSummaryInfo = db.SummaryInfo
Dim blkRecId As ObjectId = ObjectId.Null
Dim iPt1(0 To 2) As Double
Dim ipt3d As Point3d
Dim tp As Integer = 0
Dim iSNewBlk As Boolean = False
Dim newblk As ObjectId = Nothing
Using doc.LockDocument
Autodesk.AutoCAD.Internal.Utils.SetFocusToDwgView()
Try
Dim sScale As Double = bSc
Dim cs As Double = CDbl(My.Computer.Registry.GetValue("HKEY_CURRENT_USER\Software\Autodesk\UserVars", "BCScale", Nothing))
If String.IsNullOrEmpty(bSc) Or bSc = 0 Then sScale = cs
Dim sOrient As String = My.Computer.Registry.GetValue("HKEY_CURRENT_USER\Software\Autodesk\UserVars", "BCOrient", Nothing)
Dim sfile As String = My.Computer.Registry.GetValue("HKEY_CURRENT_USER\Software\Autodesk\UserVars", "BCDATA", Nothing)
sfile = Path.GetFileName(sfile)
Dim xmlList As New List(Of String)
Dim bSL As Boolean = False
Using tr As Transaction = db.TransactionManager.StartTransaction
' CHECK IF THE BLOCK EXISTS IIN THE DRAWING ELSE INSERT IT
Dim bt As BlockTable = DirectCast(tr.GetObject(db.BlockTableId, OpenMode.ForRead), BlockTable)
CheckorMakelayer(blkLay, 7)
If Not bt.Has(blkName) Then
iSNewBlk = True
If ImportBlocks(blkName) = False Then
Try
Dim BlkFullPath = funcFFile(blkName)
Using dbInsert As New Database(False, True)
dbInsert.ReadDwgFile(BlkFullPath, IO.FileShare.Read, True, "")
ObjId = db.Insert(Path.GetFileNameWithoutExtension(BlkFullPath), dbInsert, True)
End Using
Catch ex As System.Exception
ed.WriteMessage(vbLf & "Block '{0}' not found.", blkName)
Return
End Try
End If
ObjId = bt(blkName)
Else
ObjId = bt(blkName)
End If
' NOW INSERT THE BLOCK
Using br As New BlockReference(Point3d.Origin, ObjId)
br.Layer = blkLay
br.TransformBy(ed.CurrentUserCoordinateSystem)
If Not bSc = 0 Then sScale = bSc
Dim insertJig As New UDC_Common.InsertBlockJig.InsertBlockJig(br, bSc)
pr = ed.Drag(insertJig)
' Using RotateBlockJig class to rotate the block
Dim rotateJig As New UDC_Common.InsertBlockJig.RotateBlockJig(br)
pr = ed.Drag(rotateJig)
rotateJig.UpdateRotation()
dRot = br.Rotation
' Check if it is a streetlight and move it back
For Each it In xmlList
If UCase(it).Equals(UCase(br.Name)) Then
bSL = True
Exit For
Else
bSL = False
End If
Next
'ed.WriteMessage(vbLf & bSL)
Select Case bSL
Case True
Dim sla As String = My.Computer.Registry.GetValue("HKEY_CURRENT_USER\Software\Autodesk\UserVars", "BCSLA", Nothing)
Dim slo As Single = CSng(My.Computer.Registry.GetValue("HKEY_CURRENT_USER\Software\Autodesk\UserVars", "BCOffset", Nothing))
dRot = Format(dRot - funcGetRads(90), "0.000000")
If sla = "T" Then
iPt1(0) = insertJig.iPt.X + (Math.Sin(dRot) * slo) : iPt1(1) = insertJig.iPt.Y - (Math.Cos(dRot) * slo)
ipt3d = New Point3d(iPt1(0), iPt1(1), 0)
br.Position = ipt3d
Else
ipt3d = New Point3d(insertJig.iPt.X, insertJig.iPt.Y, 0)
End If
'ObjId = funcInsBlkAtts(db, "LV_POLE", ipt3d, "", dRot)
dRot = 0
End Select
Dim btr As BlockTableRecord = DirectCast(tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite), BlockTableRecord)
btr.AppendEntity(br)
tr.AddNewlyCreatedDBObject(br, True)
Select Case sOrient
Case "A" : attrot = dRot
Case Else : attrot = funcGetRads(sOrient)
End Select
'blkRecId = bt(sspl(UBound(sspl)))
blkRecId = bt(blkName)
If blkRecId <> ObjectId.Null Then
Dim BlkTblRec As BlockTableRecord = TryCast(tr.GetObject(blkRecId, OpenMode.ForRead), BlockTableRecord)
If BlkTblRec.HasAttributeDefinitions Then
For Each objId2 As ObjectId In BlkTblRec
Dim AttDef As AttributeDefinition = TryCast(tr.GetObject(objId2, OpenMode.ForRead), AttributeDefinition)
If AttDef IsNot Nothing Then
Dim AttRef As New AttributeReference()
AttRef.SetAttributeFromBlock(AttDef, br.BlockTransform)
AttRef.Rotation = attrot
br.AttributeCollection.AppendAttribute(AttRef)
tr.AddNewlyCreatedDBObject(AttRef, True)
End If
Next
End If
End If
'MsgBoxWithLineNumber("TP")
Dim brefIds As ObjectIdCollection = btr.GetBlockReferenceIds(False, True)
For Each id As ObjectId In brefIds
Dim bref As BlockReference = tr.GetObject(id, OpenMode.ForWrite, False, True)
bref.RecordGraphicsModified(True)
Next
newblk = br.ObjectId
End Using
If iSNewBlk = True Then
'' Example of grabbing a single block object id from the database
'Dim btrId As ObjectId = db.Insert(blkName, db, True)
Dim brcsdxgfdgf = CType(tr.GetObject(newblk, OpenMode.ForRead), BlockReference)
WipeoutsToBottom(brcsdxgfdgf)
End If
tr.TransactionManager.QueueForGraphicsFlush()
tr.Commit()
End Using
doc.SendStringToExecute("UDC_TPInsert", True, False, False)
Catch ex As System.Exception
ed.WriteMessage(ex.Message)
End Try
End Using
End Sub
Is there anyone who might be able to explain what I am doing wrong?
Solved! Go to Solution.
Solved by _gile. Go to Solution.
Ok, I have nailed it down to this command!
doc.SendStringToExecute("UDC_TPInsert", True, False, False)
Why is this taking the focus off of the drawing and how the hell do I get back? I have tried using :
Autodesk.AutoCAD.Internal.Utils.SetFocusToDwgView()
But to no avail...
@BlackBox_ helped me find this command, but I am unable to determine why it takes the focus away from the Active drawing and how to get it back. I have changed the values to True, but all I get is an error.
So frustrating!
Hi,
what do you expect when doing this:
<CommandMethod("UDC_TPInsert")> Public Shared Sub InsertBlocks()
Dim doc As Document = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument
'...
doc.SendStringToExecute("UDC_TPInsert", True, False, False)
'...
End Sub
You define a Command which calls itself...
_gile,
At first I was going to go on the defence, but I know your intentions are good, so, mate thank you.
My intention was to be able to repeat the command, so when I was advised to use that method, I was not helped to understand, which I am hoping you might do.
The command doesn't actually run, but stores it, so may I ask why you can't have it within the command itself? To the best of my understanding it merely logs it so when I hit return it repeats, but I do not understand why it can't. Obviously it is doing something, but it eludes me.
Thank you by the way, it now works.
Can't find what you're looking for? Ask the community or share your knowledge.