Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

LISP not reading description of dynamic block.

8 REPLIES 8
SOLVED
Reply
Message 1 of 9
mlehky
348 Views, 8 Replies

LISP not reading description of dynamic block.

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)

8 REPLIES 8
Message 2 of 9
komondormrex
in reply to: mlehky

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)
 )

 

 

Message 3 of 9
mlehky
in reply to: komondormrex

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?

Message 4 of 9
Moshe-A
in reply to: mlehky

@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)
 )

 

 

 

Message 5 of 9
mlehky
in reply to: mlehky

Both solutions work! Thanks a ton guys 🙂

 

Message 6 of 9
ВeekeeCZ
in reply to: mlehky

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.

Message 7 of 9
komondormrex
in reply to: Moshe-A

 


@Moshe-A wrote:

hope autolisp in LT 2024 supports activex


unfortunately it does not

Message 8 of 9
mlehky
in reply to: ВeekeeCZ

Also works! You guys are awesome. And thanks for the explanation.
Message 9 of 9
Sea-Haven
in reply to: mlehky

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.

Post to forums  

AutoCAD Inside the Factory


Autodesk Design & Make Report