Jump to content

Select Text Entity from Xref using .net


giskumar

Recommended Posts

Hi,

 

Thanks for the reply, This working fine.

 

I want to select this Text from a Modeless form. When i try to pass the Editor.GetNestedEntity() in button click, it is not activating the model space. please let me know how can i change the focus to drawing model with out clicking on drawing.

 

Regards,

Kumar.

Link to comment
Share on other sites

Hi,

 

Thanks for the reply, This working fine.

 

I want to select this Text from a Modeless form. When i try to pass the Editor.GetNestedEntity() in button click, it is not activating the model space. please let me know how can i change the focus to drawing model with out clicking on drawing.

 

Regards,

Kumar.

 

Try this way

 
''---   Form1   ---''
Imports System.Windows.Forms
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.ApplicationServices
Public Class Form1
   Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
       Me.TextBox1.Text = "Select a Text: "
   End Sub
   Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
       Me.Hide()
       Try
           GetXrefTextValue()
           Me.TextBox1.Text = TextSelected(0)
           Me.Show()
       Catch ex As System.Exception
           MsgBox(ex.Message & vbLf & ex.StackTrace)
       End Try
   End Sub
   Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles Button2.Click
       Me.Close()
   End Sub
   Public Sub GetXrefTextValue()
       Try
           Dim doc As Document = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument
           Dim docloc As DocumentLock = doc.LockDocument()
           Using docloc
               Dim tr As Transaction = doc.TransactionManager.StartTransaction()
               Using tr
                   Dim nid As ObjectId = doc.Editor.GetNestedEntity(vbLf & "Select a Text: ").ObjectId
                   Dim obj As DBObject = tr.GetObject(nid, OpenMode.ForRead)
                   If TypeOf obj Is DBText Then
                       Dim txt As DBText = TryCast(obj, DBText)
                       If txt IsNot Nothing Then
                           TextSelected.Clear()
                           TextSelected.Add(txt.TextString)
                       Else
                           TextSelected.Clear()
                           TextSelected.Add("Looser")
                       End If
                   Else
                       TextSelected.Clear()
                       TextSelected.Add("Not a type of the text.")
                   End If
                   tr.Commit()
               End Using
           End Using
       Catch ex As System.Exception
           MsgBox(ex.Message & vbLf & ex.StackTrace)
       End Try
   End Sub
End Class

 

 
''---   Commands.vb   ---''
Imports System
Imports System.Windows.Forms
Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.Geometry
Imports Autodesk.AutoCAD.EditorInput
<Assembly: CommandClass(GetType(ModelessFormVB.Commands))> 
Namespace ModelessFormVB
   Public Class Commands
       <CommandMethod("vb", CommandFlags.Modal)> _
       Public Sub testForm()
           Dim ed As Editor = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor
           Dim frm As New Form1
           Autodesk.AutoCAD.ApplicationServices.Application.ShowModelessDialog(frm)
           Dim usi As EditorUserInteraction = ed.StartUserInteraction(frm)
       End Sub
   End Class
End Namespace

 

 
''---   Module1.vb   ---''
End Namespace
Module Module1
   Public TextSelected As New List(Of String)
End Module

 

~'J'~

Link to comment
Share on other sites

Hi Thanks for great help,

 

I would also like to know how to perform a windowselection on Xref data from .net API.

 

 

Regards,

Kumar.

Link to comment
Share on other sites

See docs about using SelectionFilter

http://docs.autodesk.com/ACD/2010/ENU/AutoCAD%20.NET%20Developer%27s%20Guide/files/WS1a9193826455f5ff2566ffd511ff6f8c7ca-4067.htm

Use "Insert" for dxfcode value, then check if selected BlockReference belong to Xref

Here is very quick sample to get you started with:

 

 
<CommandMethod("selxref")> _
Public Sub testXrefWindowSelection()
Dim ed As Editor = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor
ed.WriteMessage(vbLf & "Select objects on screen using window selection:")
Dim ppo As New PromptPointOptions(vbLf & "Pick a first point : ")
ppo.AllowNone = True
Dim ppr As PromptPointResult
ppr = ed.GetPoint(ppo)
If ppr.Status <> PromptStatus.OK Then
Return
End If
Dim p1 As Point3d = ppr.Value
Dim pco As New PromptCornerOptions(vbLf & "Pick opposite point : ", p1)
ppr = ed.GetCorner(pco)
If ppr.Status <> PromptStatus.OK Then
Return
End If
Dim p2 As Point3d = ppr.Value
Dim xrids As New ObjectIdCollection()
Dim tvs As TypedValue() = {New TypedValue(0, "INSERT")}

Dim result As PromptSelectionResult = ed.SelectWindow(p1, p2, New SelectionFilter(tvs))
If result.Status <> PromptStatus.OK Then
Return
End If
Dim sset As SelectionSet = result.Value
Dim db As Database = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Database
Using tr As Transaction = db.TransactionManager.StartTransaction()
Dim blockIds As New ObjectIdCollection()
For Each sobj As SelectedObject In sset
Dim blockRef As BlockReference = DirectCast(tr.GetObject(sobj.ObjectId, OpenMode.ForRead, False, True), BlockReference)
Dim blkDef As BlockTableRecord = DirectCast(tr.GetObject(blockRef.BlockTableRecord, OpenMode.ForRead, False), BlockTableRecord)
If blkDef.IsFromExternalReference OrElse blkDef.IsFromOverlayReference Then
ed.WriteMessage(vbLf & "XRef name: {0}", blkDef.Name)
xrids.Add(blkDef.ObjectId)
End If
Next
If xrids.Count = 0 Then
ed.WriteMessage(vbLf & "No XRefs found")
Else
' do your rest work with xref here
ed.WriteMessage(vbLf & "Number of XRefs found: {0}", xrids.Count)
End If
tr.Commit()
End Using
End Sub

Edited by fixo
Link to comment
Share on other sites

  • 6 years later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...