Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 10/08/2021 in all areas

  1. I use reactors to save the last entity to a variable when a command such as paste or copy will start, then collect the new entities created when a command ends. I access those entities with a command that uses the variable for selection, example c:SEPP selects previous created, c:MPP moves previous created. (I use c:MP to move previous selection). (defun c:ML () (command "MOVE" "L" "") (princ)) (defun c:MP () (command "MOVE" "P" "") (princ)) (defun c:MPP () (if (not SAA_Previous) (setq SAA_Previous "P"))(command "MOVE" SAA_Previous "") (princ)) ;; move previous from saved variable (defun c:SEPP () (if (not SAA_Previous) (setq SAA_Previous "P"))(command "SELECT" SAA_Previous "")(sssetfirst SAA_Previous SAA_Previous) (princ)) (defun c:CP () (command "COPY" "P" "") (princ)) (defun c:CPP () (if (not SAA_Previous) (setq SAA_Previous "P"))(command "COPY" SAA_Previous "") (princ)) ;; move previous from saved variable I don't have time to extract just the reactor code for above as an example, but attached is my full reactor file. It won't run by itself as it depends on lots of subroutines from another file, but it contains the full structure of setting up reactors based on Eric Schneider's Autolay and vlr-manager. Search for SAA_Previous_Last for where it is called by the reactors. This code does the same as mhupp above, except deals with last subentities. ;;;============================================================================== ;;; Returns selection set of all entities after passed in entity name ;;; taken from CAD Cookbook utilities ;;;============================================================================== (defun SAA_AFTER (ename / ss) (setq ss (ssadd)) ;create selection set (if ename (while (setq ename (entnext ename)) (ssadd ename ss) ;add entities to set ) ;;; (setq ss (ssget "X")) ;if no last entity, get all ) ;end if (if (> (sslength ss) 0) ss) ;return nil if no entities ) ;;;============================================================================== ;;; Returns last entity, even subentities on polylines ;;; used to ensure SAA_AFTER skips to the next full entity, not just a subentity ;;; ;;; by roy_043 from http://www.theswamp.org/index.php?topic=35626.msg408522#msg408522 ;;;============================================================================== (defun SAA_GetLast ( / ent newEnt) (setq ent (entlast)) (while (and ent (setq newEnt (entnext ent)) ) (setq ent newEnt) ) ent ) saa_reactors.lsp
    1 point
  2. @ekko if you hover over the heart on the bottom right of peoples post you can click thank you. rather then quoting each post (spam for future people). + it helps people get on the leader board.
    1 point
  3. Like this (setq ent (car (entsel "\nPick text"))) (command "justifytext" ent "" "MC") (setq pt (cdr (assoc 11 (entget ent)))) (command "undo" 1) No Justifytext in Bricscad V20 ?
    1 point
  4. They normally are simplest, and usually work really well. My one I did a while ago and have learnt new stuff since then so there is probably a neater way to do that. I looked at this this morning for a short while (busy week here....), i spotted a slight difference in the centre points between text middle centre justification and the centre of the text bounding box that Lee uses, probably won't make any difference though in all reality. (my one is a part of another LISP to move the text to the centre of an object, a rectangle or circle or whatever and so having middle centre justification, then entmod dxf group 11 to a point, and then reset the justification to what it was works for me)
    1 point
  5. -I wrote this last night but forgot to hit the post button, this is what I have done before.... but Lee Mac always has a nicer way to do things- Probably a nicer way to do this, but tis is what I do (defun c:gettextcentre ( / txtset Edata ptx_old pty_old pty_new ptx_new mycons) (setq txtset (ssget '((0 . "*TEXT")))) ;get text. Can use entget instead and also alter the line below (setq Edata (entget (ssname txtset 0))) (setq mycons 10) (if (/= 0 (nth 1 (cdr (assoc 11 Edata))))(setq mycons 11)) ;;if text alignment isn't left use cons 11 (setq ptx_old (nth 1 (assoc mycons Edata))) ;;current insertion point x (setq pty_old (nth 2 (assoc mycons Edata))) ;;and y (command "_.justifytext" txtset "" "MC") ;;set text alignment to Middle Centre (setq Edata (entget (ssname txtset 0))) (setq ptx_new (nth 1 (assoc mycons Edata))) ;; get centre coordinates (setq pty_new (nth 2 (assoc mycons Edata))) (if (< ptx_old ptx_new)(setq alignx "L")) (if (> ptx_old ptx_new)(setq alignx "R")) (if (= ptx_old ptx_new)(setq alignx "C")) (if (> pty_old pty_new)(setq aligny "T")) (if (< pty_old pty_new)(setq aligny "B")) (if (= pty_old pty_new)(setq aligny "M")) (setq xyalign (strcat aligny alignx)) (command "_.justifytext" txtset "" xyalign) ;;reset text alignment to as before (princ (assoc 11 Edata)) ;;return centre point as a list )
    1 point
  6. Calculate the bounding box of the text object, and then calculate the midpoint of the diagonal, e.g.: (defun c:test ( / b e ) (cond ( (not (setq e (car (nentsel))))) ( (not (setq b (LM:textbox (entget e)))) (princ "\nInvalid object selected - please select text, mtext or attribute.") ) ( (entmake (list '(000 . "POINT") (cons 010 (trans (mapcar '(lambda ( a b ) (/ (+ a b) 2.0)) (car b) (caddr b)) e 0)) (assoc 210 (entget e)) ) ) ) ( (princ "\nUnable to create central point.")) ) (princ) ) ;; Text Box - Lee Mac (based on code by gile) ;; Returns the bounding box of a text, mtext, or attribute entity (in OCS) (defun LM:textbox ( enx / bpt hgt jus lst ocs org rot wid ) (cond ( (and (= "ATTRIB" (cdr (assoc 000 enx))) (= "Embedded Object" (cdr (assoc 101 enx))) ) (LM:textbox (cons '(000 . "MTEXT") (member '(101 . "Embedded Object") enx))) ) ( (cond ( (wcmatch (cdr (assoc 000 enx)) "ATTRIB,TEXT") (setq bpt (cdr (assoc 010 enx)) rot (cdr (assoc 050 enx)) lst (textbox enx) lst (list (car lst) (list (caadr lst) (cadar lst)) (cadr lst) (list (caar lst) (cadadr lst))) ) ) ( (= "MTEXT" (cdr (assoc 000 enx))) (setq ocs (cdr (assoc 210 enx)) bpt (trans (cdr (assoc 010 enx)) 0 ocs) rot (angle '(0.0 0.0) (trans (cdr (assoc 011 enx)) 0 ocs)) wid (cdr (assoc 042 enx)) hgt (cdr (assoc 043 enx)) jus (cdr (assoc 071 enx)) org (list (cond ((member jus '(2 5 8)) (/ wid -2.0)) ((member jus '(3 6 9)) (- wid)) (0.0)) (cond ((member jus '(1 2 3)) (- hgt)) ((member jus '(4 5 6)) (/ hgt -2.0)) (0.0)) ) lst (list org (mapcar '+ org (list wid 0)) (mapcar '+ org (list wid hgt)) (mapcar '+ org (list 0 hgt))) ) ) ) ( (lambda ( m ) (mapcar '(lambda ( p ) (mapcar '+ (mxv m p) bpt)) lst)) (list (list (cos rot) (sin (- rot)) 0.0) (list (sin rot) (cos rot) 0.0) '(0.0 0.0 1.0) ) ) ) ) ) ;; Matrix x Vector - Vladimir Nesterovsky ;; Args: m - nxn matrix, v - vector in R^n (defun mxv ( m v ) (mapcar '(lambda ( r ) (apply '+ (mapcar '* r v))) m) ) ;; Matrix x Vector - Vladimir Nesterovsky ;; Args: m - nxn matrix, v - vector in R^n (defun mxv ( m v ) (mapcar '(lambda ( r ) (apply '+ (mapcar '* r v))) m) )
    1 point
  7. @mhupp You have to check that the justification is not left otherwise code 11 is '(0 0 0). (defun c:foo (/ ent pt) (if (setq ent (entsel "\nSelect Text To find Center Point: ")) (setq pt (cdr (assoc (if (= 0 (cdr (assoc 73 (entget (car ent))))) 10 11 ) (entget (car ent)) ) ) ) ) )
    1 point
×
×
  • Create New...