Running MASSPROP command through VBA

Running MASSPROP command through VBA

Anonymous
Not applicable
2,198 Views
6 Replies
Message 1 of 7

Running MASSPROP command through VBA

Anonymous
Not applicable

Hi,

 

I'd like to use VBA to automatically run MASSPROP and save the results as a file. I'd do this manually by typing:

 

massprop enter

all enter enter enter

y enter enter

 

so to do this in VBA I tried the command

 

SendCommand ("_massprop" & vbCr & "_all" & vbCr & vbCr & vbCr & "_y" & vbCr & vbCr)

 

but it only gets to the "Write analysis to file?" stage and then stops

 

I'm very new to VBA in AutoCAD and AutoCAD generally so I'd appreciate any help.

 

Thanks!

0 Likes
Accepted solutions (1)
2,199 Views
6 Replies
Replies (6)
Message 2 of 7

Ed__Jobe
Mentor
Mentor
Accepted solution

This happens because vba can't switch focus to the file dialog. Before you run SendCommand, use the SetVariable method to set FILEDIA to 0, then set it back to 1 when you are done.

Ed


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
How to post your code.

EESignature

Message 3 of 7

Anonymous
Not applicable

Hi,

 

Thanks for your reply, I've googled what you suggested and tried a few things but they haven't worked. How would you recommend coding that?

 

Thanks!

0 Likes
Message 4 of 7

Ed__Jobe
Mentor
Mentor

ThisDrawing.SetVariable "FILEDIA", 0

ThisDrawing.SendCommand "massprop"

ThisDrawing.SetVariable "FILEDIA", 1

Ed


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
How to post your code.

EESignature

Message 5 of 7

Anonymous
Not applicable

Hi, thanks again for the quick response, I implemented that and I can see the changes it has made but my code still doesn't run to completion.

 

My full code (running from VBA in Excel) is:

 

Sub Main()
    Dim ACAD As AcadApplication 'Create ACAD variable of type AcadApplication
    Set ACAD = GetObject(, "AutoCAD.Application") 'Get a running instance of the class AutoCAD.Application
    ACAD.ActiveDocument.SetVariable "FILEDIA", 0
    ACAD.ActiveDocument.SendCommand ("massprop" & vbCr & "all" & vbCr & vbCr & vbCr & "y" & vbCr & vbCr) 'Print a message to the AutoCAD® command line
    ACAD.ActiveDocument.SetVariable "FILEDIA", 1
End Sub

When I run this then go into AutoCAD the command line looks like:

 

ACAD_1.PNG

 

but if I then click on the command line it switches to this:

 

ACAD_2.PNG

 

Thanks for all the help!

Tom

 

 

 

0 Likes
Message 6 of 7

Ed__Jobe
Mentor
Mentor

There's something about that command that it won't respond to scripting. I tried a plain old scr and it does the same thing.

Ed


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
How to post your code.

EESignature

0 Likes
Message 7 of 7

Anonymous
Not applicable

Hi,

 

I was looking at something else and by chance stumbled across a reference to QAFLAGS. It turned out that changing this to 2 made the script work.

 

My working code is:

 

Sub Main()
    Dim ACAD As AcadApplication 'Create ACAD variable of type AcadApplication
    Set ACAD = GetObject(, "AutoCAD.Application") 'Get a running instance of the class AutoCAD.Application
    ACAD.ActiveDocument.SendCommand ("qaflags" & vbCr & "2" & vbCr) 'This is needed for the operation
    ACAD.ActiveDocument.SendCommand ("massprop" & vbCr & "all" & vbCr & vbCr & "y" & vbCr & vbCr) 'Print a message to the AutoCAD® command line
End Sub

Thanks for your help!

Tom

0 Likes