Community
I am trying to write down a macro in excel with the following aim:
A. open a form with following options:
B. switch to autocad file, maximize Autocad window, zoom extent
C. let the user pick 2 points in order to identify the window where to place the data
D. Place a MText containing the exported data.
Here is the code that runs when you decide to export notes (I arranged it from different web sources, since I am not a programmer). The problem is that: -maximization of windows seems not to work; -when I have several open drawing it fails to make the selected drawing active.
Public Sub DrawNotes(Nome_File As String, Psz As Integer) Dim acadDoc As AcadDocumentDim line As AcadLineDim StartPt(2) As Double Dim EndPt(2) As Double Dim InsertPnt1 As Variant, InsertPnt2 As Variant Dim Note_Testo As AcadMTextDim Note_Stringa As String Dim i As Integer, fl As Integer Dim Num_Note As Integer Dim Larg_Note As Double Dim Alt_Note As Double Dim Hgt As Integer Dim NFile As String On Error Resume Next Set Graphics = GetObject(, "AutoCAD.Application")AppActivate "AutoCAD"AcadApplication.WindowState = acMax NFile = Right(Nome_File, Len(Nome_File) - InStrRev(Nome_File,"\")) AcadApplication.Documents.Item(NFile).ActivateSet acadDoc = Graphics.ActiveDocument Graphics.ZoomExtents Note_Stringa = "Notes:"Num_Note = 1 For i = 1 To 50 If Not Note(i, Psz) = "" Then Num_Note = Num_Note + 1 Note_Stringa = Note_Stringa + vbCrLf + Note(i, Psz) End If NextInsertPnt1 = acadDoc.Utility.GetPoint(, "Seleziona Punto in Alto Sx")InsertPnt2 = acadDoc.Utility.GetPoint(InsertPnt1, "Seleziona Punto in Basso Dx")Larg_Note = Abs(InsertPnt2(0) - InsertPnt1(0))Alt_Note = Abs(InsertPnt1(1) - InsertPnt2(1))Hgt = Application.WorksheetFunction.Round(Alt_Note / Num_Note, 0) If acadDoc.ActiveSpace = acModelSpace Then Set Note_Testo = acadDoc.ModelSpace.AddMText(InsertPnt1, Larg_Note, Note_Stringa) Else Set Note_Testo = acadDoc.PaperSpace.AddMText(InsertPnt1, Larg_Note, Note_Stringa) End IfNote_Testo.LineSpacingDistance = Hgt Note_Testo.Height = Application.WorksheetFunction.Round(Hgt / 3, 0) On Error GoTo 0 End Sub
Any help will be appreciated! Thank you in advance