Hello guys,
Im new to LISP and in need of help. Iam trying to create a LISP, that reads a description of a dynamic block (file attached) and then print that description into MLeader. The LISP works fine with a block that has no dynamic functions, but doesnt work with black that has dynamic functions. Any ideas as to why? I tried reading up on to each command in the LISP, but cant seem to find the problem. Is there something basic Iam missing? (Iam working with Autocad LT 2024)
Solved! Go to Solution.
Solved by ВeekeeCZ. Go to Solution.
Solved by Moshe-A. Go to Solution.
Solved by komondormrex. Go to Solution.
hello,
sort of [corrected]
(defun c:d2ml ( / s description)
(and (princ "\nPick a block :")
(setq s (ssget "_+.:S:E" '((0 . "INSERT"))))
(if (/= "" (setq description (vla-get-comments (vla-item
(vla-get-blocks (vla-get-activedocument (vlax-get-acad-object)))
(vla-get-effectivename (vlax-ename->vla-object (ssname s 0)))
)
)
)
)
(command "_mleader" pause pause description)
(alert "Block does not have a description <!>")
)
)
(princ)
)
Thanks for the reply! Iam no longer getting error with LISP not finding the description, however the mleader does not get created. Is it just on my side?
@mlehky hi,
First as a beginner, this is very good lisp program 😀
The reason it does not work is the dynamic block. as soon as you start using a dynamic block action, it's name is changes to *Un which means a user defined block (known in AutoCAD as anonymous block) so the following expression
(cdr (assoc 2 (entget (ssname s 0))))
return the anonymous name but the (tblobjname) wants the block real name (called effective block name)
so the solution here is to switch to activex by getting the effective block name (see line 5)
replace line 4 with line 5 and problem solved.
hope autolisp in LT 2024 supports activex
enjoy
Moshe
(defun c:d2ml ( / bn s d l n e)
(and (princ "\nPick a block :")
(setq s (ssget "_+.:S:E" '((0 . "INSERT"))))
; (or (setq d (cdr (assoc 4 (entget (tblobjname "BLOCK" (cdr (assoc 2 (entget (ssname s 0)))))))))
(or (setq d (cdr (assoc 4 (entget (tblobjname "BLOCK" (vla-get-effectivename (vlax-ename->vla-object (ssname s 0))))))))
(alert "Block does not have a description <!>")
)
(setq l (entlast))
(vl-cmdf "_.Mleader" "\\" "\\" "")
(and (not (= l (setq n (entlast))))
(entmod (subst (cons 304 d) (assoc 304 (setq e (entget n))) e))
)
)
(princ)
)
You can try also this change.
(defun c:d2ml ( / s d l n e) (and (princ "\nPick a block :") (setq s (ssget "_+.:S:E" '((0 . "INSERT")))) (or (setq d (cdr (assoc 4 (entget (tblobjname "BLOCK" (getpropertyvalue (ssname s 0) "BlockTableRecord/Name")))))) (alert "Block does not have a description <!>") ) (setq l (entlast)) (vl-cmdf "_.Mleader" "\\" "\\" "") (and (not (= l (setq n (entlast)))) (entmod (subst (cons 304 d) (assoc 304 (setq e (entget n))) e)) ) ) (princ) )
Your code worked fine with regular blocks or dynblocks without any change in dynproperties. Once you change any, dynblock reference converts into an anonymous block (*U3) and loses code 4 in entity definition which is a description.
Use LIST command to see :
Block Name: "MATICE M10 DIN 985 230411"
Anonymous Name: "*U2"
So you need to get a definition of the original block not from an anonymous clone.
Try this
(defun c:d2ml ( / s d ent)
(prompt "\nPick a block :")
(if (setq s (ssget "_+.:S:E" '((0 . "INSERT"))))
(progn
(setq ent (entget (ssname s 0)))
(if (= (setq d (cdr (assoc 4 (entget (tblobjname "BLOCK" (cdr (assoc 2 ent ))))))) "")
(alert "Block does not have a description <!>")
(vl-cmdf "_.Mleader" (cdr (assoc 10 ent)) (getpoint "\npick next point ") d)
)
)
)
(princ)
)
(c:d2ml)
Can't find what you're looking for? Ask the community or share your knowledge.