Author Topic: Importing block list inside OLE sheet  (Read 223 times)

0 Members and 1 Guest are viewing this topic.

dibraz0rd

  • Mosquito
  • Posts: 5
Importing block list inside OLE sheet
« on: April 23, 2021, 09:41:39 AM »
Hello guys! I am pretty new to TheSwamp - I've read many posts in last years but this is my first time posting, hehe.

Let me explain a situation: I actually use a .lisp script that export all the blocks (just like the BCOUNT command, but exporting onto a .csv file). The problem is that: everytime I need to open this .csv file and copy data inside the OLE Object (Excel Sheet) inside my .dwg drawing.

Is there a way to export it directly from .lisp code to the OLE object?

Code: [Select]
(defun c:lista_blocos  (/ _doc nm ds b ly f lst fl op)
 (vlax-for l  (vla-get-layouts
                (setq _doc
                       (vla-get-ActiveDocument (vlax-get-acad-object))))
   (vlax-for o  (vla-get-block l)
     (if (and (eq (vla-get-objectname o) "AcDbBlockReference")
              (setq nm (vla-get-effectivename o))
              (setq ds
                     (if (vlax-property-available-p
                           (setq b (vla-item (vla-get-blocks _doc) nm))
                           'comments)
                       (vla-get-comments b)
                       "")
                    )
              (setq ly (vla-get-layer o))
              )
       (if (vl-some '(lambda (x)
                       (and (eq ly (car x))
                            (eq nm (cadr x))
                            (setq f x)
                            )
                       )
                    lst)
         (setq lst (subst (list ly nm (1+ (caddr f)) ds) f lst))
         (setq lst (cons (list ly nm 1 ds) lst))
         )
       )
     )
   )
 (setq lst (vl-sort lst '(lambda (j k) (< (car j) (car k)))))
 (cond ((not lst)
        (alert "Esse desenho não tem blocos!"))
       ((and (setq fl (getfiled "Selecione outro desenho"
                                (getvar 'DWGPREFIX)
                                "csv"
                                1))
             (setq op (open fl "w"))
             )
        (write-line "Layer Name:;Block Name:;QTY;Description" op)
        (mapcar '(lambda (x)
                   (write-line
                     (strcat (car x)
                             ";"
                             (cadr x)
                             ";"
                             (itoa (caddr x))
                             ";"
                             (nth 3 x))
                     op))
                lst)
        (close op)
        )
       )
 (princ)
 )(vl-load-com)


ronjonp

  • Needs a day job
  • Posts: 7283
Re: Importing block list inside OLE sheet
« Reply #1 on: April 23, 2021, 12:51:42 PM »
Not that I'm aware of. You could put this information into a table though?

Windows 10 x64 - AutoCAD /C3D 2020

Custom Build PC

dibraz0rd

  • Mosquito
  • Posts: 5
Re: Importing block list inside OLE sheet
« Reply #2 on: April 23, 2021, 01:31:10 PM »
That is the problem - this exported data needs to be filtered first. Example:

* Block name: 500x500 (before filter)
* Block name: Insulation panel - 500 x 500 mm (BFG66D8) (after filter)

Since you said that it cannot be made the way I told, can you imagine another way to create this bill of materials inside drawing? (filtering before put it into a table on the drawing).

Thanks again for your help!

« Last Edit: April 23, 2021, 01:35:13 PM by dibraz0rd »

HOSNEYALAA

  • Newt
  • Posts: 73
Re: Importing block list inside OLE sheet
« Reply #3 on: April 23, 2021, 01:34:32 PM »
Attached file example

dibraz0rd

  • Mosquito
  • Posts: 5
Re: Importing block list inside OLE sheet
« Reply #4 on: April 23, 2021, 01:46:27 PM »
Look - I have uploaded an example that how it works today and how it is supposed to work.

Step 1) Insert the blocks into drawing - user do it manually and it can't be done automatically.
Step 2) User uses a .lisp command to export an .csv table with all the blocks (description/qty) in drawing.
Step 3) User needs to open an existing OLE object (Excel file) inside the drawing, then opening the .csv and copying the block list into the OLE object.
Step 4) Then, he returns to drawing (closing the OLE object) and the list of materials is updated.

How it is supposed to be:

Step 1) Insert the blocks into drawing - user do it manually and it can't be done automatically.
Step 2) User uses a .lisp or VBA command to export a table with all the blocks into some place inside the drawing.
Step 3) The table with the block list and filtered names appear in the drawing and the process is done.

Hope I could clarify something.

tombu

  • Bull Frog
  • Posts: 238
  • ByLayer=>Not0
Re: Importing block list inside OLE sheet
« Reply #5 on: April 23, 2021, 03:09:46 PM »
Looks like you're creating a Bill of Materials
Creating a Bill of Materials (BOM) in AutoCAD and AutoCAD LT https://knowledge.autodesk.com/support/autocad/learn-explore/caas/sfdcarticles/sfdcarticles/Creating-a-Bill-of-Materials-BOM-in-AutoCAD-and-AutoCAD-LT.html

Lots of BIM table coding examples using blocks out there.
Lee Mac did one that puts the image of each block in the first column.
AutoCAD tables are a lot easier to work with than an OLE object and can be updated easier.
Tom Beauford P.S.M.
Leon County FL Public Works - Windows 7 64 bit AutoCAD Civil 3D

dibraz0rd

  • Mosquito
  • Posts: 5
Re: Importing block list inside OLE sheet
« Reply #6 on: April 23, 2021, 03:40:22 PM »
That is great!

I am using ZWCAD instead of AutoCAD, but the procedures should be the same.

Thank you for your support!