giskumar Posted October 12, 2012 Posted October 12, 2012 Hi, I want to select a Text from Xref using c#.Net. Please let me know how can i do this? Regards, Kumar. Quote
BlackBox Posted October 12, 2012 Posted October 12, 2012 FWIW - I do not claim to speak for others, but in my limited experience 'the community' tends to frown upon posting duplicate threads. As for your question, consider the Editor.GetNestedEntity() Method. Quote
giskumar Posted October 13, 2012 Author Posted October 13, 2012 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. Quote
fixo Posted October 14, 2012 Posted October 14, 2012 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'~ Quote
giskumar Posted October 14, 2012 Author Posted October 14, 2012 Thanks for the reply. I will try this. Quote
giskumar Posted October 15, 2012 Author Posted October 15, 2012 Hi Thanks for great help, I would also like to know how to perform a windowselection on Xref data from .net API. Regards, Kumar. Quote
fixo Posted October 15, 2012 Posted October 15, 2012 (edited) 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 October 15, 2012 by fixo Quote
giskumar Posted October 15, 2012 Author Posted October 15, 2012 Thanks fixo, This really works for me. Quote
Recommended Posts
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.