Jump to content

Recommended Posts

Posted

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.

Posted

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)

Posted

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!

Posted

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

Posted

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!

Posted

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)

Posted

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!

Posted
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.

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

Posted

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.

Posted

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.

Posted

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

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

 

Excellent, glad to hear it :)

  • 7 months later...
Posted

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.

  • 6 years later...
Posted
On 5/26/2016 at 11:47 PM, Lee Mac said:

 

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

 

 

 

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

I found this lisp to be great, can anyone help add the area below? for example the picture below:image.thumb.png.5af29284fcac9cf72b34762b3325672d.png

Posted

Look at this line 

(setq str (cdr (assoc 2 enx))) nil

You will Have to convert the enx to a VL object then can get the property Area and convert to a string (setq str (rtos area 2 3)) you can add superscript 2. 

Posted
On 8/22/2023 at 1:44 PM, BIGAL said:

Look at this line 

(setq str (cdr (assoc 2 enx))) nil

You will Have to convert the enx to a VL object then can get the property Area and convert to a string (setq str (rtos area 2 3)) you can add superscript 2. 

Can you be more specific? I'm new to lisp. And you can adjust on this lisp to add area and make the multileader originates at the pick point.
 

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

 

Posted
(defun C:hbml (/ pnt qty obj lst)
	(setq sset (car (entsel)))
	(setq obj (vlax-ename->vla-object sset))
	(setq 1st (vla-get-area obj))
	(setq qty (strcat "Area = "   (rtos 1st 2 3)))
	(if (and 	
			(setq pnt (getpoint "\nPick Leader Base point: "))
			(setq pnt (trans pnt 1 0))
		)
		(command "_.mleader" "_none" pnt PAUSE qty)
	)
(princ)
)

try this.

3 hours ago, Dien nguyen said:

Can you be more specific? I'm new to lisp. And you can adjust on this lisp to add area and make the multileader originates at the pick point.
 

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

 

 

  • Like 1

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
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
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.

×
×
  • Create New...