Results 1 to 3 of 3

Thread: AutoCAD Text Window disabled by Windows Forms

  1. #1
    Login to Give a bone
    0

    Default AutoCAD Text Window disabled by Windows Forms

    Hi,

    After I run a VB.NET DLL that uses Windows Forms, my AutoCAD Text Window is disabled, including the close button. It doesn't happen for a commandline function, just those with a form. If I cancel the form before I do anything, I don't get the problem.

    The only way to get the functionality of the Text Window back is to restart AutoCAD.

    I suspect it's a bug, but I'll include some code below:

    This doesn't disable the AutoCAD Text Window

    Code:
        <Autodesk.AutoCAD.Runtime.CommandMethod("BT")> Public Sub BracketText()
            clsAutoCADText.txtBracketText()
        End Sub
    
    
     Public Shared Sub txtBracketText()
    
    
            '///// Adds or remved brackets to a selection of text
            '' Get the current document and database  
            Dim acDoc As Document = Application.DocumentManager.MdiActiveDocument
            Dim acCurDb As Database = acDoc.Database
            Using acTrans As Transaction = acCurDb.TransactionManager.StartTransaction()
                '' Request for objects to be selected in the drawing area      
                Dim acSSPrompt As PromptSelectionResult = acDoc.Editor.GetSelection()
                '' If the prompt status is OK, objects were selected      
                If acSSPrompt.Status = PromptStatus.OK Then
                    Dim acSSet As SelectionSet = acSSPrompt.Value
                    For Each acSSObj As SelectedObject In acSSet
                        '' Check to make sure a valid SelectedObject object was returned         
                        If Not IsDBNull(acSSObj) Then
                            '' Open the selected object for write             
                            Dim acEnt As Entity = acTrans.GetObject(acSSObj.ObjectId, Autodesk.AutoCAD.DatabaseServices.OpenMode.ForWrite)
                            If Not IsDBNull(acEnt) Then
                                If TypeOf (acEnt) Is DBText Then
                                    Dim oText As DBText = DirectCast(acEnt, DBText)
                                    Dim sText As String = oText.TextString.Trim
                                    If sText.StartsWith("(") And sText.EndsWith(")") Then
    
    
                                        If sText.Length <= 2 Then
                                            MsgBox("I refuse to make a zero length string.")
                                            Exit Sub
                                        End If
                                        sText = sText.Substring(1, sText.Length - 2)
                                    Else
                                        sText = "(" & sText & ")"
                                    End If
                                    oText.TextString = sText
                                End If
                            End If
                        End If
                    Next
                    '' Save the new object to the database         
                    acTrans.Commit()
                End If
                '' Dispose of the transaction
            End Using
        End Sub
    This does disable the Text Window...

    Code:
        <Autodesk.AutoCAD.Runtime.CommandMethod("QA")> Public Sub QA()
            Dim f As New frmPolygonsArea
            f.ShowDialog()
            f = Nothing ' 
        End Sub
    
       Private Sub frmPolygonsArea_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    
    
    
    
            arM2.Add("m%%2012")
            arM2.Add("m²")
            Me.cmbm2.DataSource = arM2
    
    
            arAreaUnits.Add("Auto")
            arAreaUnits.Add("Metres")
            arAreaUnits.Add("Hectares")
            Me.cmbAreaUnits.DataSource = arAreaUnits
    
    
            arDecimals.Add("Round down to nearest 10m²")
            arDecimals.Add("Round down to nearest 5m²")
            arDecimals.Add("0")
            arDecimals.Add("0.0")
            arDecimals.Add("0.00")
            arDecimals.Add("0.000")
            arDecimals.Add("0.0000")
            arDecimals.Add("0.00000")
            Me.cmbDecimals.DataSource = arDecimals
            Me.cmbDecimals.SelectedIndex = 2
    
    
            Me.cmbLayer.DataSource = clsConicsAcadLayerManager.GetLayerList(False)
            Me.cmbLayer.Text = Application.GetSystemVariable("CLAYER")
            Me.cmbTextStyle.DataSource = clsConicsAcadLayerManager.GetTextStyleList()
            Me.cmbTextStyle.Text = Application.GetSystemVariable("TEXTSTYLE")
            Dim n As Double = Application.GetSystemVariable("USERR4") * 4
            If n <= 0 Then
                n = 2
            End If
            Me.txtHeight.Text = n.ToString
        End Sub
    
    
        Private Sub cmdCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdCancel.Click
            Me.Hide()
        End Sub
    
    
     Private Sub cmdLabel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdLabel.Click
            Dim oPLs As New ObjectIdCollection
    
    
            'validate
            If Not IsNumeric(Me.txtHeight.Text) Then
                MsgBox("Text height not a number", vbExclamation, "Shinput")
                Exit Sub
            End If
            Dim nHeight As Double = CDbl(Me.txtHeight.Text)
            Dim sLay As String = Me.cmbLayer.Text
            Dim sStyle As String = Me.cmbTextStyle.Text
            Dim sText As String
    
    
            'Select Polylines
            Me.Hide()
    
    
    
    
            'Loop throughthem
            Dim acDwg As Autodesk.AutoCAD.ApplicationServices.Document
            acDwg = Application.DocumentManager.MdiActiveDocument
            Using tr As Transaction = acDwg.TransactionManager.StartTransaction()
                oPLs = clsRPSUtilities.PickObjects
                If oPLs IsNot Nothing Then
                    For Each OID As ObjectId In oPLs
                        Dim obj As DBObject = tr.GetObject(OID, Autodesk.AutoCAD.DatabaseServices.OpenMode.ForWrite)
                        Dim ent As Entity = DirectCast(obj, Entity)
                        If TypeOf ent Is Polyline Then
                            Dim pl As New Polyline
                            pl = DirectCast(obj, Polyline)
                            sText = FormatArea(pl.Area, Me.cmbAreaUnits.Text, Me.cmbDecimals.Text)
                            clsAutoCADText.CreateText(sText, clsRPSUtilities.Get2DCentroid(pl), sStyle, nHeight, 90)
                        ElseIf TypeOf ent Is Polyline2d Then
                            Dim pl As New Polyline2d
                            pl = DirectCast(obj, Polyline2d)
                            sText = FormatArea(pl.Area, Me.cmbAreaUnits.Text, Me.cmbDecimals.Text)
                            clsAutoCADText.CreateText(sText, clsRPSUtilities.Get2DCentroid(pl), sStyle, nHeight, 90)
                        ElseIf TypeOf ent Is Polyline3d Then
                            Dim pl As New Polyline3d
                            pl = DirectCast(obj, Polyline3d)
                            sText = FormatArea(pl.Area, Me.cmbAreaUnits.Text, Me.cmbDecimals.Text)
                            clsAutoCADText.CreateText(sText, clsRPSUtilities.Get2DCentroid(pl), sStyle, nHeight, 90)
                        End If
                    Next OID
                End If
                tr.Commit()
            End Using
    
    
        End Sub
    I've obviously not supplied all the code for the form, let me know if you want to see more.

    Has anyone else encountered this?

  2. #2
    I could stop if I wanted to
    Join Date
    2007-08
    Posts
    201
    Login to Give a bone
    0

    Default Re: AutoCAD Text Window disabled by Windows Forms

    Hi,

    Try using:
    Autodesk.AutoCAD.ApplicationServices.Application.ShowModalDialog(f)
    instead of:
    f.ShowDialog().

  3. #3
    Login to Give a bone
    0

    Default Re: AutoCAD Text Window disabled by Windows Forms

    Brilliant! Thank you.

Similar Threads

  1. Additional windows functionality in the text window.
    By IanR in forum AutoCAD Wish List
    Replies: 6
    Last Post: 2014-08-18, 01:07 PM
  2. Using Windows Forms vb
    By drewj in forum Revit - API
    Replies: 1
    Last Post: 2012-07-19, 08:43 PM
  3. how to make a window family with a sill that can be disabled
    By jameswest77 in forum Revit Architecture - Families
    Replies: 1
    Last Post: 2010-09-21, 06:23 PM
  4. Door and windows disabled?
    By Dave Lewis in forum Revit Architecture - General
    Replies: 1
    Last Post: 2006-10-04, 10:00 PM
  5. VB.Net Netload DLL and Windows forms (EXE)
    By KevinBarnett in forum Dot Net API
    Replies: 2
    Last Post: 2005-12-15, 08:17 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •