Author Topic: reading Blocks from the table  (Read 1764 times)

0 Members and 1 Guest are viewing this topic.

S.Langhammer

  • Guest
reading Blocks from the table
« on: February 11, 2013, 05:57:59 AM »
Hello there everyone!
I'm currently working on a Lisp script to read out entity information out of a drawing. Suddenly a colleague of mine notices: wait a moment there aren't enough entities in your exported file!
After a little research we found the problem: the entities i didn't find were block references! The actual entities turn out to be tricky little bastards, hiding in the block table.
Now I'm asking, is there a way to get the entity names (dxf group code -1) of those blocks? Best possible is someone knew a routine to list themright away, then i should be able to get the rest on my own.

For info: I'm using BricsCAD, so a lot of AutoCAD commands wont work.

Thanks a lot for every bit of help I get!

irneb

  • Water Moccasin
  • Posts: 1794
  • ACad R9-2016, Revit Arch 6-2016
Re: reading Blocks from the table
« Reply #1 on: February 11, 2013, 07:10:45 AM »
tblnext and tblobjname to get the block definitions. From that using entnext would get their internal entities.

If you mean you didn't find the block references in the DWG (not inside other blocks), then how did you step through the DWG? Using ssget or entnext or ActiveX?
Common sense - the curse in disguise. Because if you have it, you have to live with those that don't.

S.Langhammer

  • Guest
Re: reading Blocks from the table
« Reply #2 on: February 11, 2013, 07:19:44 AM »
Well up until now I only stepped through the model space via entnext.
Actually I make a filtered list of entities within the modelspace first  and read the entity Information from that list.

Code - Auto/Visual Lisp: [Select]
  1. (defun getMSpList(/ en enlist eset cntr)        ;makes a list of all relevant entities within the drawing
  2.         (setq mSpList(list))
  3.         (setq eset (ssget "X"))
  4.         (if (/= eset nil)
  5.                 (progn
  6.                         (setq cntr 0)
  7.                         (setq en (ssname eset cntr))
  8.                         (setq enlist(entget en))
  9.                         (while (< cntr (sslength eset))
  10.                                 (if (/= en nil)
  11.                                         (progn
  12.                                                 (setq enlist(entget en))
  13.                                                 (setq en (entnext en))
  14.                                                 (if (/= (cdr(assoc 0 enlist)) "VIEWPORT") ;;; ignore viewports
  15.                                                         (if (/= (cdr(assoc 0 enlist)) "OLE2FRAME") ;;; ignore ole2frames
  16.                                                                 (if (/= (cdr(assoc 0 enlist)) "OLEFRAME") ;;; ignore oleframes
  17.                                                                         (setq mSpList(append mSpList(list enlist)))
  18.                                                                 )
  19.                                                         )
  20.                                                 )       ;;; end exclusion if
  21.                                         )       ;;; end if-progn
  22.                                 )       ;;; end nil-if
  23.                                 (setq cntr (+ cntr 1))
  24.                         )       ;;;end while
  25.                 )       ;;; end if-progn
  26.                 (princ "!!!No ENTITIES WITHIN THE DRAWING!!!\n")
  27.         )       ;;; end if
  28.         mSpList
  29. )       ;;; end getMSpList
  30.  

S.Langhammer

  • Guest
Re: reading Blocks from the table
« Reply #3 on: February 11, 2013, 10:29:55 AM »
Does this look like it could work to anyone of you?

Code - Auto/Visual Lisp: [Select]
  1. (defun getBlockList(/ en  cntr listBlock subList)
  2.         (while (setq listBlock (tblnext "BLOCK" T))
  3.                 (getBlkRefData listBlock)
  4.         )
  5. );;; ende getBlockList
  6. ;;;
  7.  
  8. (defun C:Block_EnameListNested (blockName / ename ret) ; Return value: List of enames of block nested entities from Block Definition
  9.         (setq ename (tblobjname "block" blockName)
  10.                 ret(list))
  11.         (if ename
  12.                 (while (setq ename (entnext ename))
  13.                         (setq ret (append ret (list (entget ename))))
  14.                 )
  15.         )
  16.         ret
  17. )
  18. ;;;
  19. (defun getBlkRefData(inBlock / entTyp entLyr dstr entHan entPt entPtStr entFla entNam entNam2 subList dTabs entFlaStr) ;;;Blockreferenz
  20.         (setq blkRefCntr (+ blkRefCntr 1))
  21.         (setq dataList(list))
  22.         (setq subList(list))
  23.  
  24.         (setq entTyp(cdr(assoc 0 inBlock)))
  25.         (setq entHan(cdr(assoc 5 inBlock)))
  26.         (setq entLyr(cdr(assoc 8 inBlock)))
  27.         (setq entNam(cdr(assoc 2 inBlock)))    
  28.         (setq entPt(cdr(assoc 10 inBlock)))
  29.         (setq entPtStr(strcat (rtos(car entPt)2 4)spcr(rtos(cadr entPt)2 4)spcr(rtos(caddr entPt)2 4)))
  30.         (if (assoc 70 inBlock)
  31.                 (progn
  32.                         (setq entFla(cdr(assoc 70 inBlock)))
  33.                         (setq entFlaStr(itoa entFla))
  34.                 )
  35.         )
  36.         ;
  37.         (depthTabs)
  38.         (setq dStr "")
  39.         (setq dStr (strcat dStr entTyp spcr))
  40.         (setq dStr (strcat dStr entHan spcr))
  41.         (setq dStr (strcat dStr entLyr spcr
  42.         (setq dStr (strcat dStr entNam spcr))  
  43.         (setq dStr (strcat dStr entPtStr spcr))
  44.         (if entFlaStr
  45.                 (setq dStr (strcat dStr entFlaStr spcr))
  46.                 (setq dStr (strcat dStr "" spcr))
  47.         )
  48.         (setq dStr (strcat dTabs dStr "\n"))
  49.         (setq dataList(append dataList(list (strcat dStr))))   
  50.         (setq subList(append(Block_EnameListNested (cdr (assoc 2 inBlock))) inBlock ) )
  51.         (setq deep (+ deep 1))
  52.         (getinfoWithInsert subList)
  53.         (setq deep (- deep 1))
  54.         (setq endMark(list))
  55.         (depthTabs)
  56.         (setq endMark(append endMark(list (strcat dTabs "End of " entHan "\n"))))
  57.         (setq dataList(append dataList endMark))
  58.         (fileWrite dataList)
  59.         (princ)
  60. )       ;;; ende getBlkRRefData
  61. ;;;
  62.  

Assuming getBlockList is called by the main program. Please tell me if you see any Major misstakes.
« Last Edit: February 11, 2013, 10:34:32 AM by S.Langhammer »

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: reading Blocks from the table
« Reply #4 on: February 11, 2013, 06:24:30 PM »
If I were you I would consider exploding all inserts in the selection instead of digging through all the (nested) blocks. I have read some of your posts on this forum and on the BricsCAD forum and I still don't understand what you are trying to do. If you are trying to create a dxf-type file you should look into the DXFOUT command. With this command you can specify a selection and a precision.

If you decide to explode all inserts you will have to create some kind of loop to also explode the nested inserts.

If you don't explode the inserts you may have to 'translate' nested entities to the coordinate systems of the successive parent blocks. I have mentioned this on the BricsCAD forum. But judging from this post you have misunderstood. For example a circle in a block definition can look like an ellipse if an insert of that block is scaled unevenly.

S.Langhammer

  • Guest
Re: reading Blocks from the table
« Reply #5 on: February 12, 2013, 02:11:16 AM »
The file I aim to create isn't exactly a dxf-file. You could say its a reduced and formated version of a dxf. The Thing is, that our DXF import doesn't work properly (I wasn't told what the exact problem is), so we had to come up with something different. In the end my export writes the file about this way:

Code: [Select]
BLOCK,RIPPEN,0,0,0,0,
LINE,17D47,A_HEIZKOERPER,-.07,0,0,-.07,.75,0,.75,
LINE,17D48,A_HEIZKOERPER,-.07,0,0,-.07,-.75,0,.75,
LINE,17D49,A_HEIZKOERPER,-.145,.75,0,-.145,-.75,0,1.5,
LINE,17D4A,A_HEIZKOERPER,-.145,.75,0,-.145,.95,0,.2,
LINE,17D4B,A_HEIZKOERPER,-.145,-.75,0,-.145,-.95,0,.2,
LINE,17D4C,A_HEIZKOERPER,-.07,-.75,0,-.22,-.75,0,.15,
LINE,17D4D,A_HEIZKOERPER,-.22,-.75,0,-.22,.75,0,1.5,
LINE,17D4E,A_HEIZKOERPER,-.22,.75,0,-.07,.75,0,.15,
End of RIPPEN,

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: reading Blocks from the table
« Reply #6 on: February 12, 2013, 04:09:03 AM »
our DXF import doesn't work properly (I wasn't told what the exact problem is)
This may be a version issue. Using the SAVEAS command you can create DXF files for different CAD versions. Versions 'AutoCAD Release 9' (very old) up to 'AutoCAD 2010' are supported by BricsCAD. Version 'AutoCAD Release 11/12 ASCII DXF' may work for you.
« Last Edit: February 12, 2013, 04:12:23 AM by roy_043 »

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: reading Blocks from the table
« Reply #7 on: February 12, 2013, 09:32:56 AM »
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: reading Blocks from the table
« Reply #8 on: February 12, 2013, 09:34:33 AM »
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.