Hello.
I have ACAD 2013 and I run from Excel 2007 a VBA code that uses ACAD API.
As the experienced of you probably know, it isn't possible to handle "DRAWORDER" and "PASTECLIP" methods through VBA. You must use "SendCommand" for that.
The problem is that "SendCommand" makes ACAD visible, a thing I cannot allow to happen, since the project should be used by external costumers of my company.
Even if I set "Acad_App_Object.Visible = False" immidiately after the "SendCommand", there is about one second that the ACAD window shows up and can be seen on screen and in taskbar (Windows OS).
Does someone have any idea how to implement a solution for this issue?
I use "PASTECLIP" for pasting an Excel range into a layout's paperspace (and I cannot use any other data import methods, because the original Excel appearance, sizes and complete designs must remain).
Then, I loop on all objects in that layout, and once I find the OLE type, I use "DRAWORDER" with the "Handle" property of that pasted OLE, to move it to back, behind all objects in layout.
Finally, the layout is plotted.
Here is my current relevant code section:
MainSheet.Range(first_cell,last_cell).CopyPicture xlScreen, xlPicture '<==== That's the Excel range copying (as picture) adoc.SendCommand "_PasteClip 1.6,1.6" & vbCr adoc.Application.Visible = False Dim iter_obj As AcadObject, xl_ole As IAcadOle For Each iter_obj In adoc.PaperSpace If (TypeOf iter_obj Is IAcadOle) Then Set xl_ole = iter_obj xl_ole.Layer = "Excel" adoc.SendCommand "_DRAWORDER" & vbCr & "(handent """ & xl_ole.Handle & """)" & vbCr & vbCr & "_B" & vbCr adoc.Application.Visible = False End If Next iter_obj
You can see I had to use "adoc.Application.Visible = False" twice, and though, as I said, it is far from being acceptable.
Thanks in advance for any help!
Meir
Well, the way how AutoCAD is used in the process sounds a bit problematic to me (automating an instance of AutoCAD and let external customerS to do something (generate a drawing with an Excel sheet inserted?).
Yes, AutoCAD will be surely become visible, depending on what it is asked to do. Running command by SendCommand is the most likely reason, but there could be other reasons. The bottom line is: it is inevitable eventually. That is how AutoCAD as desktop app is designed.
However, with AutoCAD2013, have you tried to use Acad console? It is designed to manipulate drawing without visible UI. However, I am not sure if it can be automated the same way as regular AutoCAD instance. If not, you may do thing the other way around: start the process from AutoCAD console side and automate Excel to obtain the paste clip...
Lf you currently only want to solve DrawOrder without SendCommand, then yes, there is undocumented way to do it with VBA code in AutoCAD:
For each block definition, including ModelSpace/PaperSpace, there is en extensionDictionary, called "ACAD_SORTENTS". You use code to get this dictionary and call its NoveToTop/Bottom() method, which taks an Entity array as argument.
Code would look like:
Dim dic As AcadDictionary
Set dic=ThisDrawing.PaperSpace.GetExtensionDictionary
Dim sortDic As AcadDictionary
On Error resume Next
Set sortDic=dic.getObject("ACAD_SORTENTS")
If sortDic Is Nothing Then
Set sortDic=dic.AddObject("ACAD_SORTENTS","AcDbSortentsTable")
End If
On Error GoTo 0
''Get a selectionSet and place them into an array
Dim varEnts() As AcadEntity
.....
sortDic.MoveTop varEnts
Norman Yuan
Hello norman.yuan
Thanks a lot for your answer and sorry for the late reply.
Your DrawOrder alternative is very useful (From some reason I had to declare "dic" and "sortDic" as "AcadObject" to avoid error messages).
Can you please give me a little VBA example demonstrating how to run and access ACAD console? I've tried to search some information with no success.
And what about "PasteClip"? No any way of doing the whole method through API? Perhaps by accessing the system clipboard? I'm mainly familiar with Excel enviroment rather than ACAD.
Again: Thanks a lot for your help so far and for your future possible help!
Meir
I do not have access to Acad2013 currently, thus not tried AutoCAD 2013 Core Console. You can go to read this:
and search the topic online (but do not expect a lot inormation you will get). However, I do not believe you can use VBA code to AutoCAD console. If you have to "PasteClip" for the exact Excel Sheet clip, probably SendCommand() is the only doable option, I guess. If so, there is no guarantee the running AutoCAD instance will not become visible for some reason.
Norman Yuan