Author Topic: LISP working in AutoCAD but not in BricsCAD  (Read 1374 times)

0 Members and 1 Guest are viewing this topic.

mailmaverick

  • Bull Frog
  • Posts: 493
LISP working in AutoCAD but not in BricsCAD
« on: August 03, 2023, 01:23:59 PM »
Hi,
I have a LISP which is working in AutoCAD but not in Bricscad.
In AutoCAD, the program completes within few seconds whereas in BricsCAD, it goes into indefinite loop.

CAD file and LISP file is attached. Please help.

ribarm

  • Gator
  • Posts: 3274
  • Marko Ribar, architect
Re: LISP working in AutoCAD but not in BricsCAD
« Reply #1 on: August 03, 2023, 02:02:20 PM »
It seems you missed in providing sub function MP:Echo...
Here is my output on textscreen...
Code: [Select]
: TEST

; ----- LISP : Call Stack -----
; [0]...C:TEST
; [1].....LISTEXPLODABLEBLOCKSWITHDIMLEADBLK <<--
;
; ----- Error around expression -----
; (MP:ECHO NIL)
;
; error : no function definition <MP:ECHO> ; expected FUNCTION at [eval]
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube


ribarm

  • Gator
  • Posts: 3274
  • Marko Ribar, architect
Re: LISP working in AutoCAD but not in BricsCAD
« Reply #3 on: August 03, 2023, 03:24:35 PM »
Seems to be working...
Small dialog box pops up and it is processing... There is also something happening on command line, but I haven't waited to see if it finishes as I don't quite know what's the purpose of routine on DWG provided... You are seems exploding nested blocks, but what does that matter in drawing that is IMHO completed drawing plan/project...
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

mailmaverick

  • Bull Frog
  • Posts: 493
Re: LISP working in AutoCAD but not in BricsCAD
« Reply #4 on: August 03, 2023, 07:51:49 PM »
Problem is not in MP:Echo. It is already loaded as per the link provided by DanAllen.
Also, the purpose is to explode all blocks before giving the drawing to anyone outside organisation. Exploding inside blocks doesn't disturb the dimensions, leaders etc which if exploded directly using 'EXPLODE' causes dimensions texts and arrows to go haywire. See attached drawing in which when you explode the block directly, the dimensions get disturbed.

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8702
  • AKA Daniel
Re: LISP working in AutoCAD but not in BricsCAD
« Reply #5 on: August 04, 2023, 09:05:47 AM »
What’s to prevent people from wblocking the exploded block?

BIGAL

  • Swamp Rat
  • Posts: 1414
  • 40 + years of using Autocad
Re: LISP working in AutoCAD but not in BricsCAD
« Reply #6 on: August 05, 2023, 12:25:34 AM »
What version of Bricscad some VL functions were not in earlier versions.

Other suggestion is put (princ "\n1") in code then further down (princ "\n2") etc look for last number gives a clue where to start looking.
A man who never made a mistake never made anything

mailmaverick

  • Bull Frog
  • Posts: 493
Re: LISP working in AutoCAD but not in BricsCAD
« Reply #7 on: August 05, 2023, 05:50:49 AM »
I am using BricsCAD latest version (v23).
Also as you said that some VL functions were not in earlier versions. If that was the case, the program would give undefined function error but it doesn't. It just goes into infinite loop. So all the functions used in the LISP are read by BricsCAD.

ribarm

  • Gator
  • Posts: 3274
  • Marko Ribar, architect
Re: LISP working in AutoCAD but not in BricsCAD
« Reply #8 on: August 05, 2023, 01:00:17 PM »
I am using BricsCAD latest version (v23).
Also as you said that some VL functions were not in earlier versions. If that was the case, the program would give undefined function error but it doesn't. It just goes into infinite loop. So all the functions used in the LISP are read by BricsCAD.


I took some time to remedy your code... Looks better and on my end it functions, but on some other DWG, as your is finished story... When I run on your DWG it iterates through blocks - pass 1, pass 2, pass ... And there is nothing to explode... When I on the other hand create block within block on blank DWG it does what should... HTH., M.R.

Code - Auto/Visual Lisp: [Select]
  1. (defun C:Test (/ *error* MP:Echo exnest exnest:explode LM:name->effectivename listExplodableBlockswithDimLeadBlk _kpblc-conv-vla-to-list fun_explode explinside adoc osm ort qaf ctb pass expblklist totblks cnt origblk )
  2.  
  3.   (defun *error* ( m )
  4.     (if osm
  5.       (setvar 'osmode osm)
  6.     )
  7.     (if ort
  8.       (setvar 'orthomode ort)
  9.     )
  10.     (if qaf
  11.       (setvar 'qaflags qaf)
  12.     )
  13.     (if ctb
  14.       (setvar 'ctab ctb)
  15.     )
  16.     (if adoc
  17.       (vla-endundomark adoc)
  18.     )
  19.     (if m
  20.       (prompt m)
  21.     )
  22.     (princ)
  23.   )
  24.  
  25.   (defun MP:Echo ( x / cmdecho millisecs ceiling )
  26.     (cond
  27.       ( (null (setq ceiling 2000 millisecs (getvar 'millisecs)))
  28.       )
  29.       ( (/= 'int (type *MP:Echo:MilliSecs*))
  30.         (setq *MP:Echo:MilliSecs* millisecs)
  31.       )
  32.       ( (< ceiling (- millisecs *MP:Echo:MilliSecs*))
  33.         (setq cmdecho (getvar 'cmdecho))
  34.         (setvar 'cmdecho 0)
  35.         (vl-cmdf ".delay" 0)
  36.         (setvar 'cmdecho cmdecho)
  37.         (setq *MP:Echo:MilliSecs* millisecs)
  38.       )
  39.     )
  40.     (if (eq 'str (type x))
  41.       (setvar 'modemacro (vl-string-trim "\n\r\t" x))
  42.     )
  43.     (princ x)
  44.     (princ)
  45.   )
  46.   (defun exnest ( ent / obj )
  47.     ;; explode nested blocks only (not the parent block)
  48.     (if ent
  49.       (progn
  50.         (vlax-for obj (vla-item (vla-get-blocks adoc) (LM:name->effectivename (cdr (assoc 2 (entget ent)))))
  51.           (exnest:explode obj)
  52.         )
  53.         (vla-regen adoc acallviewports)
  54.       )
  55.     )
  56.     (princ)
  57.   )
  58.   (defun exnest:explode ( obj / lst )
  59.     (if
  60.       (and
  61.         (= "AcDbBlockReference" (vla-get-objectname obj))
  62.         (vlax-write-enabled-p obj)
  63.         (not (vl-catch-all-error-p (setq lst (vl-catch-all-apply 'vlax-invoke (list obj 'explode)))))
  64.       )
  65.       (progn
  66.         (foreach obj lst
  67.           (exnest:explode obj)
  68.         )
  69.         (vla-delete obj)
  70.       )
  71.     )
  72.   )
  73.   (defun LM:name->effectivename ( blk / rep )
  74.     ;; Block Name -> Effective Block Name
  75.     ;; blk - [str] Block name
  76.     (if
  77.       (and
  78.         (wcmatch blk "`**")
  79.         (setq rep (cdadr (assoc -3 (entget (cdr (assoc 330 (entget (tblobjname "block" blk)))) '("AcDbBlockRepBTag")))))
  80.         (setq rep (handent (cdr (assoc 1005 rep))))
  81.       )
  82.       (cdr (assoc 2 (entget rep)))
  83.       blk
  84.     )
  85.   )
  86.   (defun listExplodableBlockswithDimLeadBlk ( / blk blks count ent expblklst fndcnt idx n n1 o objn ss step )
  87.     ;; Lists explodable blocks with Dimensions, Leaders, Blocks inside
  88.     (setq expblklst (list))
  89.     (setq fndcnt 0)
  90.     (if (setq ss (ssget "_X" (list (cons 410 (getvar 'ctab)) (cons 0 "*BLOCK*,*INSERT*"))))
  91.       (progn (setq step (max 1 (fix (/ (sslength ss) 100))))
  92.         (repeat (setq n1 (sslength ss))
  93.           (if (eq (rem n1 step) 0)
  94.             (progn
  95.               (acet-ui-status
  96.                 (strcat (itoa n1)
  97.                         " blocks remaining, out of total of "
  98.                         (itoa (sslength ss))
  99.                         " blocks.\nFound "
  100.                         (itoa fndcnt)
  101.                         " blocks to be Exploded."
  102.                 )
  103.               )
  104.               (MP:Echo nil)
  105.               (while (< 0 (getvar 'cmdactive))
  106.                 (command "")
  107.               )
  108.               (command "_.delay" 0)
  109.             )
  110.           )
  111.           (setq ent (ssname ss (setq n1 (1- n1))))
  112.           (if
  113.             (eq
  114.               (vla-get-explodable (vla-item (vla-get-blocks (vla-get-activedocument (vlax-get-acad-object))) (cdr (assoc 2 (entget ent))))) :vlax-true
  115.             )
  116.             (progn                        ;insert object
  117.               (setq o (vlax-ename->vla-object ent)
  118.                     n (vla-get-effectivename o) ;name
  119.               )
  120.               (if (not (vl-catch-all-error-p (vl-catch-all-apply 'vla-item (list blks n))))
  121.                 (progn
  122.                   (setq blk (vla-item blks n)
  123.                         idx -1
  124.                         count (vla-get-count blk)
  125.                   )
  126.                   (while (< (setq idx (1+ idx)) count)
  127.                     (setq n (vla-item blk idx))
  128.                     (setq objn (strcase (vla-get-objectname n)))
  129.                     (if
  130.                       (or
  131.                         (vl-string-search "DIMENSION" objn)
  132.                         (vl-string-search "LEADER" objn)
  133.                         (vl-string-search "INSERT" objn)
  134.                         (vl-string-search "BLOCK" objn)
  135.                       )
  136.                       (progn ;;
  137.                         (setq fndcnt (1+ fndcnt))
  138.                         (setq expblklst (append expblklst (list ent)))
  139.                         (setq idx count)
  140.                       )
  141.                     )
  142.                   )
  143.                 )
  144.               )
  145.             )
  146.           )
  147.         )
  148.       )
  149.     )
  150.     expblklst
  151.   )
  152.   (defun _kpblc-conv-vla-to-list ( value / res )
  153.     (cond
  154.       ( (listp value)
  155.         (mapcar (function _kpblc-conv-vla-to-list) value)
  156.       )
  157.       ( (= (type value) 'variant)
  158.         (_kpblc-conv-vla-to-list (vlax-variant-value value))
  159.       )
  160.       ( (= (type value) 'safearray)
  161.         (if (>= (vlax-safearray-get-u-bound value 1) 0)
  162.           (_kpblc-conv-vla-to-list (vlax-safearray->list value))
  163.         ) ;_ end of if
  164.       )
  165.       ( (and (= (type value) 'vla-object) (vlax-property-available-p value 'count))
  166.         (vlax-for sub value (setq res (cons sub res)))
  167.       )
  168.       ( t value )
  169.     ) ;_ end of cond
  170.   ) ;_ end of defun
  171.   (defun fun_explode ( ent / res def )
  172.     (cond
  173.       ( (vlax-method-applicable-p ent 'explode)
  174.         (foreach sub (vla-explode ent) (fun_explode sub))
  175.         (vla-erase ent)
  176.       )
  177.       ;;((wcmatch (strcase (vla-get-objectname ent)) "ACDB*DIM*")
  178.       ( T
  179.         (setq def (vla-item (vla-get-blocks adoc) (cdr (assoc 2 (entget (vlax-vla-object->ename ent)))))
  180.               def (_kpblc-conv-vla-to-list def)
  181.         ) ;_ end of setq
  182.         (vla-copyobjects
  183.           adoc
  184.           (vlax-make-variant
  185.             (vlax-safearray-fill (vlax-make-safearray vlax-vbobject (cons 0 (1- (length def)))) def)
  186.           ) ;_ end of vlax-make-variant
  187.           (vla-objectidtoobject adoc (vla-get-ownerid ent))
  188.         ) ;_ end of vla-CopyObjects
  189.         (vla-erase ent)
  190.       )
  191.     ) ;_ end of cond
  192.   ) ;_ end of defun
  193.   (defun explinside ( ent / sub )
  194.     ;; Source : http://www.theswamp.org/index.php?topic=56094.0
  195.     (cond ;_ end of type
  196.       ( (/= (type ent) 'ename) ;_ end of /=
  197.         (princ "\nNothing selected")
  198.       )
  199.           (setq ent
  200.             (vl-catch-all-apply
  201.               (function
  202.                 (lambda () (vla-item (vla-get-blocks adoc) (vla-get-effectivename (vlax-ename->vla-object ent))))
  203.               ) ;_ end of function
  204.             ) ;_ end of vl-catch-all-apply
  205.           ) ;_ end of setq
  206.         ) ;_ end of vl-catch-all-error-p
  207.         (princ "\nCan't recognize block definition")
  208.       )
  209.       ( T
  210.         ;;(vla-startundomark adoc)
  211.         (vlax-for sub ent (vl-catch-all-apply (function (lambda () (fun_explode sub)))))
  212.         ;;(vla-endundomark adoc)
  213.       )
  214.     ) ;_ end of cond
  215.     (princ)
  216.   ) ;_ end of defun
  217.   ;;
  218.   ;;
  219.   ;;
  220.   ;;
  221.   ;;
  222.   ;;----------------------------------------------------------------------;;
  223.   ;;                         Actual Program Started                       ;;
  224.   ;;----------------------------------------------------------------------;;
  225.   ;;
  226.   ;;
  227.   (if (= 8 (logand 8 (getvar 'undoctl)))
  228.     (vla-endundomark adoc)
  229.   )
  230.   (setq osm (getvar 'osmode))
  231.   (setvar 'osmode 0)
  232.   (setq ort (getvar 'orthomode))
  233.   (setvar 'orthomode 0)
  234.   (acet-ui-status "ExplodeInsideBlocks")
  235.   (command)
  236.   (setq qaf (getvar 'qaflags))
  237.   (setvar "QAFLAGS" 0)
  238.   (setq ctb (getvar 'ctab))
  239.   (setvar 'ctab "Model")
  240.   (command)
  241.   (setq pass 0)
  242.   (while (setq expblklist (listExplodableBlockswithDimLeadBlk))
  243.     (setq totblks (length expblklist))
  244.     (setq cnt 1)
  245.     (foreach blk expblklist
  246.       (acet-ui-status
  247.         (strcat "Pass " (itoa pass) " : Exploding Inside block " (itoa cnt) " of total " (itoa totblks))
  248.       )
  249.       (MP:Echo nil)
  250.       (while (< 0 (getvar 'cmdactive))
  251.         (command "")
  252.       )
  253.       (command "_.delay" 0)
  254.       (command)
  255.       (setq origblk blk)
  256.       (exnest origblk)
  257.       (explinside origblk)
  258.       (exnest origblk)
  259.       (explinside origblk)
  260.       (command)
  261.       (setvar "QAFLAGS" 1)
  262.       (vl-cmdf "_.explode" origblk)
  263.       (while (< 0 (getvar 'cmdactive))
  264.         (command "")
  265.       )
  266.       (setvar "QAFLAGS" 0)
  267.       (setq cnt (1+ cnt))
  268.     )
  269.     (setq pass (1+ pass))
  270.   )
  271.   (command)
  272.   (acet-ui-status)
  273.   (*error* nil)
  274. )
  275.  

Regards...
« Last Edit: August 05, 2023, 01:43:04 PM by ribarm »
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube