Jump to content
eyeofnewt555

Hatch Name to Multileader Lisp?

Recommended Posts

eyeofnewt555

Hey guys!

 

Do y'all know of a LISP that will label a hatch based on its name? Similar to what AlanJT did here with block name->mleader.

 

Bonus points if you can get it to work with AlanJT's code, so I only need one command to label my blocks and hatches. And if this isn't possible, then is there a LISP for populating an mleader with a palette display description?

 

Any help would be great! Thanks.

Share this post


Link to post
Share on other sites
Lee Mac

Try the following, quickly written code:

(defun c:hbml ( / blk ent enx str )
   (setq blk (vla-get-blocks (vla-get-activedocument (vlax-get-acad-object))))
   (while
       (progn (setvar 'errno 0) (setq ent (car (entsel "\nSelect block or hatch: ")))
           (cond
               (   (= 7 (getvar 'errno))
                   (princ "\nMissed, try again.")
               )
               (   (null ent) nil)
               (   (= "INSERT" (cdr (assoc 0 (setq enx (entget ent)))))
                   (if (= "" (setq str (vla-get-comments (vla-item blk (vla-get-name (vlax-ename->vla-object ent))))))
                       (princ "\nSelected block has no description.")
                   )
               )
               (   (= "HATCH" (cdr (assoc 0 enx)))
                   (setq str (cdr (assoc 2 enx))) nil
               )
           )
       )
   )
   (if ent (vl-cmdf "_.mleader" "\\" "\\" str))
   (princ)
)
(vl-load-com) (princ)

Share this post


Link to post
Share on other sites
eyeofnewt555

Oh my gosh, THE Lee Mac responded to me :notworthy:

 

And you combined it with the block->mleader lisp!

 

If I can bother you once more--is there a way to combine it with this (block name->mleader) lisp, rather than the block description->mleader? Sorry I just figured out how to link to specific posts in a thread.

 

For blocks, having the leader automatically begin at the block's insertion point is handy (one click instead of two), but I'm not sure where it would start for hatches.

 

Thank you so much, Lee Mac!

Share this post


Link to post
Share on other sites
broncos15

Hint: Look at the vlax-get-property portion of the code.

Share this post


Link to post
Share on other sites
eyeofnewt555

Broncos15, unfortunately, I'm super new to lisps. I tried making sense of it, but it's still a foreign language to me. But thanks for the hint!

Share this post


Link to post
Share on other sites
Grrr

Quickly modified LM's code, here you go:

(defun c:hbml ( / blk ent enx str )
   (setq blk (vla-get-blocks (vla-get-activedocument (vlax-get-acad-object))))
   (while
       (progn (setvar 'errno 0) (setq ent (car (entsel "\nSelect block or hatch: ")))
           (cond
               (   (= 7 (getvar 'errno))
                   (princ "\nMissed, try again.")
               )
               (   (null ent) nil)
               (   (= "INSERT" (cdr (assoc 0 (setq enx (entget ent)))))
                   (if (= "" (setq str (vla-get-effectivename (vlax-ename->vla-object ent))))
                       (princ "\nCannot find block's name.")
                   )
               )
               (   (= "HATCH" (cdr (assoc 0 enx)))
                   (setq str (cdr (assoc 2 enx))) nil
               )
           )
       )
   )
   (if ent (vl-cmdf "_.mleader" "\\" "\\" str))
   (princ)
)
(vl-load-com) (princ)

Share this post


Link to post
Share on other sites
eyeofnewt555

Grrr, thanks a ton! Sooo, do you know how I would make it so the multileader originates at the block insertion point? Just makes for one less click.

 

Also, is there a way to make it work like most native commands where you can select the object first and then run the command on it?

 

Thanks!

Share this post


Link to post
Share on other sites
Grrr
Grrr, thanks a ton! Sooo, do you know how I would make it so the multileader originates at the block insertion point? Just makes for one less click.

 

Also, is there a way to make it work like most native commands where you can select the object first and then run the command on it?

 

Thanks!

 

Sure:

(defun c:hbml ( / SelectedFirst blk ent enx str inspt bbox mn mx MC )
   (setq blk (vla-get-blocks (vla-get-activedocument (vlax-get-acad-object))))

(if (and (setq SelectedFirst (ssget "_I")) (= (sslength SelectedFirst) 1) )
	(sssetfirst nil nil) 
)
(if SelectedFirst
	(progn
		(setq ent (ssname SelectedFirst 0))
		(cond
			( (= "INSERT" (cdr (assoc 0 (setq enx (entget ent))))) 
				(setq str (vla-get-effectivename (vlax-ename->vla-object ent)))
				(setq inspt (cdr (assoc 10 enx)))
				(command "_.mleader" inspt "\\" str)
			)
			( (= "HATCH" (cdr (assoc 0 enx)))
				(setq str (cdr (assoc 2 enx))) nil
				(setq bbox (vla-getboundingbox (vlax-ename->vla-object ent) 'mn 'mx))
				(setq MC (mapcar '(lambda (x1 x2) (/ (+ x1 x2) 2.0)) (trans (vlax-safearray->list mn) 0 1) (trans (vlax-safearray->list mx) 0 1) ))
				(command "_.mleader" MC "\\" str)
			)
		)
	) ; progn TRUE
	(progn
		(while ; false
			(progn (setvar 'errno 0) (setq ent (car (entsel "\nSelect block or hatch: ")))
				(cond
					(   (= 7 (getvar 'errno))
						(princ "\nMissed, try again.")
					)
					(   (null ent) nil)
					(   (= "INSERT" (cdr (assoc 0 (setq enx (entget ent)))))
						(if (= "" (setq str (vla-get-effectivename (vlax-ename->vla-object ent))))
							(princ "\nCannot find block's name.")
						)
					)
					(   (= "HATCH" (cdr (assoc 0 enx)))
						(setq str (cdr (assoc 2 enx))) nil
					)
				)
			)
		) ; while
		
		(cond
			( (= "INSERT" (cdr (assoc 0 (setq enx (entget ent))))) 
				(setq inspt (cdr (assoc 10 enx)))
				(vl-cmdf "_.mleader" inspt "\\" str)
			)
			( (= "HATCH" (cdr (assoc 0 enx)))
				(setq bbox (vla-getboundingbox (vlax-ename->vla-object ent) 'mn 'mx))
				(setq MC (mapcar '(lambda (x1 x2) (/ (+ x1 x2) 2.0)) (trans (vlax-safearray->list mn) 0 1) (trans (vlax-safearray->list mx) 0 1) ))
				(vl-cmdf "_.mleader" MC "\\" str)
			)
		)
	); progn FALSE
);if 
(princ)
)
(vl-load-com) (princ)



I'm a hobby coder, so it might need some professional eye check.

Share this post


Link to post
Share on other sites
Lee Mac
Oh my gosh, THE Lee Mac responded to me :notworthy:

 

And you combined it with the block->mleader lisp!

 

You're most welcome; thank you for your adulation.

 

If I can bother you once more--is there a way to combine it with this (block name->mleader) lisp, rather than the block description->mleader? Sorry I just figured out how to link to specific posts in a thread.

 

do you know how I would make it so the multileader originates at the block insertion point? Just makes for one less click.

 

Also, is there a way to make it work like most native commands where you can select the object first and then run the command on it?

 

This should fulfil your requests:

(defun c:hbml ( / enx sel )
   (if (setq sel (ssget "_+.:E:S" '((0 . "INSERT,HATCH"))))
       (progn
           (command "_.mleader")
           (if (= "INSERT" (cdr (assoc 0 (setq enx (entget (ssname sel 0))))))
               (command "_non" (trans (cdr (assoc 10 enx)) (cdr (assoc -1 enx)) 1))
               (command "\\")
           )
           (command "\\" (cdr (assoc 2 enx)))
       )
   )
   (princ)
)

@Grrr, try right-clicking at the single-selection prompt ;)

Share this post


Link to post
Share on other sites
Grrr

Well theres no need to mention that Lee Mac is the best (almost everything I learnt is from him).

Anyway I would use vla-get-effectivename method in his code (assuming he was lazy to write it in) :D

 

This code is useless for me, but I follow Tharwat's advice to practice on people's requests.

Share this post


Link to post
Share on other sites
Tharwat

Anyway I would use vla-get-effectivename method in his code (assuming he was lazy to write it in) :D

:lol:

 

This code is useless for me, but I follow Tharwat's advice to practice on people's requests.

That was a good try indeed and no one was born a master so we all learn from our and other's mistakes.

 

So throw the dust away from you and keep on walking forward to reach the peak.

Share this post


Link to post
Share on other sites
eyeofnewt555

Lee Mac, you are amazing. Thank you so much. It's gonna be a huge help around the office.

Share this post


Link to post
Share on other sites
Lee Mac
Lee Mac, you are amazing. Thank you so much. It's gonna be a huge help around the office.

 

Excellent, glad to hear it :)

Share this post


Link to post
Share on other sites
eyeofnewt555

Alright, MacMaster, hopefully this is the final modification request.

 

We recently switched our process and now it would be handy to have almost exactly this lisp (from post #9), but with some slight changes.

 

The block mleader now needs to populate from the block's description, rather than name. So very similar to the first bit of code you wrote (post #2), but with the multileader automatically starting at the insertion point.

 

I promise I did try fiddling with the code to make it work myself, but I've got miles to go before I can really make sense of the magic you do.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×