Jump to content

Recommended Posts

Posted

Hi, I have a problem that occurs to me every day.

Received autocad files containing symbol legends without quantities, I then have to create excel files that list the quantities of these blocks in these files.

With dataextraction it is very simple and immediate, the problem I have, however, is that in these excel files I need to add the image of the computed block because often its name alone is not helpful.

Do you know any procedures that could help me?

The "preview" images of the block are available in designcenter, but I haven't found a way to use them.

Greetings

 

Posted

Found this https://smallbusiness.chron.com/import-autocad-drawing-excel-45945.html

 

Ok got an image in excel but lots of white space.

 

So tried a screen grab then a paste to a cell that worked real well a good size.

image.png.6a9024ea47a1e177517243ce6be27f4b.png

 

Another way make a image of the block say plot to jpg then insert into excel manually this worked. You can drive excel from Autocad but no idea how to do the insert part. I am sure a macro record will give hints. 

 

Sub Macro1()
    ActiveSheet.Pictures.Insert("C:\CAD-TOOLS\images\fabs.png").Select
End Sub

I don't have a problem working with Excel from Acad so need line above as VL code starts with (vlax-invoke-method I would just google for help.

Posted

Copy and Paste Special (Paste is AutoCAD Object) as Image, AutoCAD Object or Bitmap.

 

I usually Paste as AutoCAD Object, then right-click and Ungroup makes it an Excel Object and you can reduce the whitespace by dragging the handles on the box. I get varying results. 

 

Or you can crop to just the block to remove the extra.

 

You can Import>Object to bring them in as well.

 

Having only done occasionally, I never looked for any Macros. You might ask around on some Excel forums.

Posted

Ok found a way in excel to bring in images via a macro select a cell then run macro.

 

Sub Macro1()
Dim strFile As String

strFile = Application.GetOpenFilename(FileFilter:="Excel files (*.png*), *.jpg*", Title:="Choose an image file to open", MultiSelect:=False)
 
ActiveSheet.Pictures.Insert(strFile).Select
 
End Sub

 

Ok for VL getting somewhere the myxl is the excel application, the pictures are in "Shapes" this returns a variable and a dump shows how many. 

 

(vlax-get-property  (vlax-get-property myxl "ActiveSheet") "Shapes"))

So looking for add a shape.

Posted

Hello and thanks for the replies.

My problem is not importing the images into excel, but obtaining a series of images of the blocks automatically from the export of autocad My problem is not importing the images into excel, but obtaining a series of images of the blocks automatically from the export of autocad (without awkward copy and paste screenshots)...but I don't think it can be done.

Posted

Uhmm...I just read an interesting command that I didn't know about...jpgout...maybe it could help me!

Greetings!

Posted

That is what I was hinting can plot a jpg or png of a block to file then choose that file using the macro I posted in excel. 

 

I am sure it can be done , I just have to work out the VBA code as VL code. Its not a straight conversion. 

 

ActiveSheet.Pictures.Insert(strFile).Select , it looks like pictures are Shapes as mentioned problem is how to 'Add a picture. The real wiz on this problem Fixo has unfortunately passed away.

Posted

Hi, don't worry about importing single images into an excel file, I will surely find the solution!
In the meantime, I've taken a big step forward to automate the whole process!

I tried jpgout and it's perfect!
1) I created a test file that I called "test legend"

2) I found a lisp that allows me to export every single block of a file, as a single dwg file and I made a folder of all the single "test legend" files

3) I tried with Lee Mac's superlisp called ScriptWriterV1-2 to write the operations that should be done on all the single exported blocks to apply the jpgout command to each one...Unfortunately, among these operations there is a passage that I can't encode, when the jpgout command opens the window where it proposes to save and with what name, at that moment I should be able to communicate a simple "enter" but I can't!

 

This is my "script"

_.open *file* _.zoom _e _.jpgout  _enter _t _esc _.save  _Y _.close

How can I, when the jpgout command dialog opens, do the equivalent of "press the save button"?

 

https://drive.google.com/file/d/1pKv6-5fZKeLxnjEdvQn9IL7CAfGJvbqM/view?usp=share_link

 

Posted

"I tried jpgout and it's perfect!"

 

Dont need a script if you want all blocks in one dwg. Just get "Extmax"  and work out a point away from anything in  it, then loop through the block table and get each block name, insert the block at this point, scale 1, rot 0, next get bounding box, a simple plot lisp using jpgout writes the jpg file as block name. Use Fit based on the window of the bounding box. Then erase entlast, and insert next block.

 

Its the same as making a legend of blocks. 

 

Have a look at this as a starting point.

 

(defun wow ( / )
(setvar 'attreq 0)
(vlax-for block (vla-get-blocks (vla-get-activedocument (vlax-get-acad-object)))
(setq bname (vla-get-name block))
(if (= (substr bname 1 1) "*")
(princ)
(command "-insert" bname "0,0" 1.0 1.0 0.0)
)
(princ)
)
)
(wow)

 

Ha Ha for me 188 blocks.

Posted

Uhm...maybe I don't' understand...

I want:

1) create a folder of all blocks of a file as individual dwg files...ok done

2) create in the same folder an image file of each dwg block file...ok almost done

Almost done because I have to do it manually, opening every single dwg block file and applying the jpgout command

But I would like to do it automatically using a script... the image file name is always the same as the dwg block file name

I will definitely try your lisp to see what all the fuss is about

hello

Posted (edited)

I have Bricscad V20 and it does not have Jpgout un fortunately. Has BMPout which grabs current screen so is big file, I did though find a way around it shrunk my screen to about a 1/8 of full size bitmap was like 118kb. 

 

So you want a dwg with nothing in model space. Then try these changes it should make a jpg for all blocks in dwg, then use the excel macro above to select.

 

(defun wow ( / )
(setq predwg (getvar 'dwgprefix))

(command "-insert" (strcat bname predwg) "0,0" 1.0 1.0 0.0)
jpgout extents bname  put correct command here
(command "erase" (entlast) "")

 

Edited by BIGAL
Posted

You would be better off bringing the blocks directly to Excel as AutoCAD Objects or Excel Objects.

 

Or sending them from AutoCAD to Excel.

 

I found a paid solution in the APP Store....DWG to XLS | AutoCAD | Autodesk App Store

 

You might search around for a free solution, I am almost positive I have seen an import Macro somewhere on an Excel forum, maybe StackOverflow, StackExchange or Reddit if not the Microsoft Forums.

 

It's pretty fast doing it manually once you get the method down.

 

 

Posted

The key words are "you will have one Line (SHAPE) in XLS" that is what I found that objects become a shape, not a picture. Still looking for how to insert, looks like can possibly resize as when you insert a jpg etc you can get at its properties via CAD, cell location start and end, plus width.

 

Posted

The problem I can't solve is how to run the jpgout command with a script because it needs enter and esc keys!

The sequence is:

jpgout

save in the opened window

t (="tutti" in English A I presume), so I write t with a space

Esc key for close the command jpgout...how I can?

Save

Y

Close

Posted

Just had a play, the easiest way is to use plot via a lisp, use "Publish to web jpg" I used paper size 640x480, I selected a window around a block, used FIT, and got a good result.

 

Need to write a routine to insert a block do a bounding box then use it in a plot lisp. Something like this for the plot.

 

(COMMAND "-PLOT"  "Y"  "" "Publish To Web JPG"
	       "VGA (640.00 x 480.00 Pixels" "m" "LANDSCAPE"  "N"   "W"  ll ur "F"  "C"
	       "y" "Acad.ctb" "Y" "n" "n" "n" pdfName "N" "y"
    ) 

 

Posted

Or

11 hours ago, BIGAL said:

The key words are "you will have one Line (SHAPE) in XLS" that is what I found that objects become a shape, not a picture. Still looking for how to insert, looks like can possibly resize as when you insert a jpg etc you can get at its properties via CAD, cell location start and end, plus width.

 

If you export a line, you get a line. They are Excel shapes, much better than images, just like actual AutoCAD Objects are better than images.

 

I'm done here.

Posted

I have found another way to automatize the jpgout process!

with Action Recorder I recorded the whole procedure (unfortunately it still asks me to give an enter in the filename phase to save)...

Now I'm looking for a way to apply the recorded action to all files in a folder...do you think it can be done?

Posted

Eureka! I (almost) did it!

I recorded the jpgout command procedure and closed it, then put the Actrecord command call and recorded action call into the listing for ScriptWriterV1-2 and it works!

Unfortunately I have to give the enter command when saving the .jpg filename for each file...I wonder if there is a way to avoid it...

However it works! given a path to ScriptWriterV1-2 I create its own jpg file for each dwg file!

 

Row to enter into ScriptWriterV1-2:

_.open *file* _.zoom _e _.actrecord _.JPGOUT_procedura _.save  _Y _.close

Posted

Your opening statement was "I need to add the image of the computed block" and that has been the direction I have been going in export out jpgs of your blocks within 1 dwg. You should be able to put it all together with what I have provided. 

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...