+ Reply to Thread
Page 1 of 2 1 2 LastLast
Results 1 to 10 of 14
  1. #1
    Full Member
    Discipline
    Civil
    Using
    AutoCAD 2015
    Join Date
    May 2016
    Posts
    79

    Default Hatch Name to Multileader Lisp?

    Registered forum members do not see this ad.

    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.

  2. #2
    Quantum Mechanic Lee Mac's Avatar
    Computer Details
    Lee Mac's Computer Details
    Operating System:
    Windows 7 Ultimate (32-bit)
    Discipline
    Multi-disciplinary
    Lee Mac's Discipline Details
    Discipline
    Multi-disciplinary
    Details
    Custom Programming / Software Customisation
    Using
    AutoCAD 2013
    Join Date
    Aug 2008
    Location
    London, England
    Posts
    19,322

    Default

    Try the following, quickly written code:
    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)
    Lee Mac ProgrammingTwitterExchange App StoreDropbox (500MB free)

    With Mathematics there is the possibility of perfect rigour, so why settle for less?

  3. #3
    Full Member
    Discipline
    Civil
    Using
    AutoCAD 2015
    Join Date
    May 2016
    Posts
    79

    Default

    Oh my gosh, THE Lee Mac responded to me

    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!

  4. #4
    Super Member
    Using
    Civil 3D 2015
    Join Date
    Aug 2015
    Posts
    508

    Default

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

  5. #5
    Full Member
    Discipline
    Civil
    Using
    AutoCAD 2015
    Join Date
    May 2016
    Posts
    79

    Default

    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!

  6. #6
    Super Member
    Discipline
    Multi-disciplinary
    Using
    AutoCAD 2015
    Join Date
    Nov 2013
    Posts
    1,067

    Default

    Quickly modified LM's code, here you go:
    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-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)

  7. #7
    Full Member
    Discipline
    Civil
    Using
    AutoCAD 2015
    Join Date
    May 2016
    Posts
    79

    Default

    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!

  8. #8
    Super Member
    Discipline
    Multi-disciplinary
    Using
    AutoCAD 2015
    Join Date
    Nov 2013
    Posts
    1,067

    Default

    Quote Originally Posted by eyeofnewt555 View Post
    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:
    Code:
    (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.

  9. #9
    Quantum Mechanic Lee Mac's Avatar
    Computer Details
    Lee Mac's Computer Details
    Operating System:
    Windows 7 Ultimate (32-bit)
    Discipline
    Multi-disciplinary
    Lee Mac's Discipline Details
    Discipline
    Multi-disciplinary
    Details
    Custom Programming / Software Customisation
    Using
    AutoCAD 2013
    Join Date
    Aug 2008
    Location
    London, England
    Posts
    19,322

    Default

    Quote Originally Posted by eyeofnewt555 View Post
    Oh my gosh, THE Lee Mac responded to me

    And you combined it with the block->mleader lisp!
    You're most welcome; thank you for your adulation.

    Quote Originally Posted by eyeofnewt555 View Post
    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.
    Quote Originally Posted by eyeofnewt555 View Post
    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:
    Code:
    (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
    Lee Mac ProgrammingTwitterExchange App StoreDropbox (500MB free)

    With Mathematics there is the possibility of perfect rigour, so why settle for less?

  10. #10
    Super Member
    Discipline
    Multi-disciplinary
    Using
    AutoCAD 2015
    Join Date
    Nov 2013
    Posts
    1,067

    Default

    Registered forum members do not see this ad.

    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)

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

Similar Threads

  1. Replies: 14
    Last Post: 21st Jan 2015, 06:23 am
  2. Setting multileader scale via lisp
    By pixel8er in forum AutoLISP, Visual LISP & DCL
    Replies: 2
    Last Post: 1st Sep 2013, 04:29 pm
  3. Lisp for hatch
    By vnanhvu in forum AutoLISP, Visual LISP & DCL
    Replies: 9
    Last Post: 30th May 2011, 06:34 pm
  4. Background Mask for Multileader LISP (needs editing)
    By tomjas in forum AutoLISP, Visual LISP & DCL
    Replies: 0
    Last Post: 6th Aug 2010, 10:35 am
  5. Multileader Text Lisp
    By kamig in forum AutoLISP, Visual LISP & DCL
    Replies: 7
    Last Post: 7th Jul 2009, 05:29 pm

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts