LISP not working - make block

Hi, I asked this question a while ago but not sorted. The LISP below makes a block of selected objects, it works as posted for other but not on my machine. This is the second computer it's not working on. Is there a setting I need to change?

(defun c:make_block_at_selected_point (/ bkn eee i ndx nm ssst st)
(if (and (setq ssst (ssget)) (setq st (getpoint "\nPick Base Point: ")))
(progn (setq ndx 0)
(setq time (rtos (getvar "CDATE") 2 6)) ; Format YYYYMMDD.HHMMSS
(setq year (substr time 3 2)) ; Two digits instead of four
(setq month (substr time 5 2))
(setq day (substr time 7 2))
(setq hour (substr time 10 2)) ; Increment of 3 from day to account for "." character
(setq minutes (substr time 12 2))
(setq seconds (substr time 14 2))
(while (tblobjname "block" (setq nm (strcat "Block-" year month day hour minutes seconds))))
(entmake (list '(0 . "BLOCK")
'(100 . "AcDbEntity")
'(67 . 0)
'(8 . "0")
'(100 . "AcDbBlockReference")
(cons 2 nm)
(cons 10 st)
'(70 . 0)
)
)
(repeat (sslength ssst)
(entmake (cdr (entget (ssname ssst ndx))))
(entdel (ssname ssst ndx))
(setq ndx (+ 1 ndx))
)
(entmake '((0 . "ENDBLK") (100 . "AcDbBlockEnd") (8 . "0")))
(entmake (list (cons 0 "INSERT")
(cons 2 nm)
(cons 6 (getvar "CELTYPE"))
(cons 8 (getvar "CLAYER"))
(cons 66 0)
(cons 10 st)
(cons 41 1)
(cons 42 1)
(cons 43 1)
(cons 50 0)
(cons 71 0)
(cons 44 0)
(cons 45 0)
)
)
)
)
(princ)
)

Comments

  • Have a look at this example note the "endblock" is the very last line in making the block.

  • Thanks but the code is very different and I won't be able to make it work since what I have was from other people's assistance.

    By the way, there is a line with ENDBLK in posted code

  • What went wrong:

    Wrong subclass in BLOCK definition
    used AcDbBlockReference instead of AcDbBlockBegin

    Invalid / unnecessary DXF codes in INSERT
    71, 44, 45 caused issues (MINSERT behavior / rejection)

    Broken name loop
    while had no body, could hang on duplicate names

    It seems attached code works.

  • NedCAD, this works, so thanks very much for posting, it may help others as well. I'm not good at LISP at all and generally find it hard to get to a solution, in almost all instances have had to rely on someone to pretty much fix it. Not being a code expert, I manage to get by for other languages such as Visual Basic and HTML/CSS, only because so much is available online, and if not can post on a forum with confidence. With LISP, it's been very difficult and haven't been able to get past the hurdle of understanding the structure of the language, let alone details. I did post regarding this code a few months ago but wasn't resolved, this time it was, consider your skills as a rarity.