VBA
Discuss AutoCAD ActiveX and VBA (Visual Basic for Applications) questions here.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Excel/Autocad Vba: switching between applications

0 REPLIES 0
Reply
Message 1 of 1
Umatonna
997 Views, 0 Replies

Excel/Autocad Vba: switching between applications

I am trying to write down a macro in excel with the following aim:

A. open a form with following options:

  1. choose the column where the data to be exported are present
  2. select the autocad file where to export (with browse button)

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

 

0 REPLIES 0

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost