Jump to content

Hatch Name to Multileader Lisp?


eyeofnewt555
 Share

Recommended Posts

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.

Link to comment
Share on other sites

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)

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

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)

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

  • 7 months later...

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.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...