"Plot" or "copy" a drawing display directly to Excel?

"Plot" or "copy" a drawing display directly to Excel?

Anonymous
Not applicable
1,548 Views
4 Replies
Message 1 of 5

"Plot" or "copy" a drawing display directly to Excel?

Anonymous
Not applicable

Hi All,

I'm a beginner doing the Autocad development stuff with VBA with limited experience. Recently I got stuck on this assignment to modify a drawing file (hide some lines in certain layers) and then export the current view to an excel file to make a checklist.

I could do Ctrl+A, Ctrl+C from Autocad and Ctrl+V in Excel, manually, but when it comes to VBA programming, is there a simple way to get this done?

What I  have in mind now is to plot the drawing to an image file, and copy this file to a cell in Excel. But I don't really want to generate these image files and delete them later.

 

Another thing is how to get the maximum dimensions of a drawing profile in X and Y axis? I came across this obj.GetBoundingBox method, which displays the bottom left and upper right coordinates of an virtual enclosing box to the profile, but that only works with a certain type of objects only, i.e. lineObj, arcObj... How can I select all the elements in a drawing profile, and get the maximum X Y dimensions? The GetBoundingBox Method seems not working with AcadSeletionSet Object.

 

Any ideas or code recommends are welcome. Thanks

0 Likes
Accepted solutions (1)
1,549 Views
4 Replies
Replies (4)
Message 2 of 5

Ed__Jobe
Mentor
Mentor

Have you tried the EXTMIN and EXTMAX  system variables?

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 3 of 5

Anonymous
Not applicable

Thanks Ed that's something I've learned, although I haven't tried it yet... 

 

And I've found the following link explaining the SetVariable/GetVariable Method.

https://knowledge.autodesk.com/search-result/caas/CloudHelp/cloudhelp/2016/ENU/AutoCAD-ActiveX/files...

 

But when searching on Google I found people talking about the little bugs with these two system variables. They always return the value with a tiny little difference from the actual value (by less than 1mm), which is pretty weird.

0 Likes
Message 4 of 5

norman.yuan
Mentor
Mentor
Accepted solution

When you use Ctrl+A/C/V to select, copy and paste things from AutoCAD into Excel sheet, I guess what you get is OLE linked/embedded image in Excel. If that is what you really wanted, there is no easy way to do it with AutoCAD/Excel VBA. You probably need to dig a much deeper hole into Windows APIs, which would be very hard for most MS Office/AutoCAD programmers. On the other hand, do you really need place many OLE linked/embedded AutoCAD objects, shiwn as image in Excel sheet for any practical reason? I can hardly think of any.

 

With AutoCAD COM API/VBA, you can print/plot drawing or export drawing as image file (PDF, PNG, WMF...) for the drawing content of your selection (layout, window, extents...). Then you can insert the generated image into Excel sheet, or database, or used by whatever application.

 

The thing is that you need to be quite familiar with AutoCAD before you can program it. Without knowing what exactly you want to achieve (rather than link/embed OLE objects into Excel sheet, which I fully doubt its usefulness), I cannot offer more suggestions.

 


@Anonymous wrote:

 

But when searching on Google I found people talking about the little bugs with these two system variables. They always return the value with a tiny little difference from the actual value (by less than 1mm), which is pretty weird.


Also, the thing you refer as "pretty weird", is not weird at all: the value is "Double" type, stored in computer as floating point number, 2 double numbers cannot be EXACTLY the same. It only make sense to say to double numbers are the same with given precision, say, with certain decimals.

Norman Yuan

Drive CAD With Code

EESignature

0 Likes
Message 5 of 5

Anonymous
Not applicable

Thanks Norman.

 

What we are doing at the moment is to grab a couple of 2D drawing profiles(.dxf) and send them to supplier for plasma/laser cutting. So we want to generate a spreadsheet containing the profiles of the parts, with other information, for the staff to do visual inspection or counting checks on receiving the parts.

 

I'm using the Thisdrawing.Export() method now to generate .bmp images only, which is quite handy. But I'll probably have to do more searching about other methods so the program can plot in jpg., png., and other formats like you said.

0 Likes