Jump to content

Carriage return in lisp-created MText


Recommended Posts

Posted
car = beginning of list (what list?)

 

cdr = end of list (what list?)

 

"(what list?)"

The list of point coordinate values.

 

Consider that your variable 'a' (whether obtained using getpoint or otherwise) holds a 2D or 3D list of point values:

(<X-value> <Y-value> [Z-value])

For example, something like:

(1.23 2.45 3.56)

 

Now observe the following console demonstration:

_$ (setq a '(1.23 2.45 3.56))
(1.23 2.45 3.56)
_$ (car a)
1.23
_$ (cdr a)
(2.45 3.56)
_$ (1- (car a))
0.23
_$ (cons (1- (car a)) (cdr a))
(0.23 2.45 3.56)

 

As for mapcar, forget it

 

It's not as complicated as it may first appear, the expression:

(mapcar '- a '(1 0 0))

Is equivalent to:

(list (- (car a) 1) (- (cadr a) 0) (- (caddr a) 0))

 

So, using the above example for the point 'a':

_$ (setq a '(1.23 2.45 3.56))
(1.23 2.45 3.56)

Then the mapcar expression:

_$ (mapcar '- a '(1 0 0))
(0.23 2.45 3.56)

Is the same as:

_$ (list (- 1.23 1) (- 2.45 0) (- 3.56 0))
(0.23 2.45 3.56)

 

You may find my mapcar tutorial helpful in this respect.

  • Replies 22
  • Created
  • Last Reply

Top Posters In This Topic

  • Happy Hobbit

    7

  • Lee Mac

    5

  • robertbon

    5

  • Tharwat

    4

Posted (edited)

I can see that mapcar could be very useful in manipulating lists

 

I wonder if it might help defining 3 entmake expressions

 

At the moment to define rectangles I have:

 

    (if (< w 15)
     (progn ; 'then' make mtext at ends
     ;;;------------------- mtext on LH side   ---------------------;;;

      (entmake ;; Append the following DXF data to the drawing database
           (list ;; Construct a list containing the following DXF data
              '(000 . "MTEXT")          ;; Entity type
              '(100 . "AcDbEntity")     ;; Subclass marker
              '(100 . "AcDbMText")      ;; Subclass marker
        (cons 10 (polar a pi 1))            ;; Insertion point
              '(001 . "Bacon \n& Eggs") ;; Content
              '(040 . 1.5)              ;; Height
              (cons 050 ang)              ;; Rotation in radians
       '(071 . 6)                ;; Justification: 2 = Top Centre, 4 = Middle Left, 6 = Middle Right

           ) ;; end list
       ) ;; end entmake

   (princ) ;; Suppress the output of the value returned by the last evaluated expression

 ;;;------------------- mtext on RH side   ---------------------;;;
 
      (entmake ;; Append the following DXF data to the drawing database
           (list ;; Construct a list containing the following DXF data
              '(000 . "MTEXT")          ;; Entity type
              '(100 . "AcDbEntity")     ;; Subclass marker
              '(100 . "AcDbMText")      ;; Subclass marker
        (cons 10 (polar b 0 1))            ;; Insertion point
              '(001 . "Bacon \n& Eggs") ;; Content
              (cons 050 ang)              ;; Rotation in radians
              '(040 . 1.5)              ;; Height
       '(071 . 4)                ;; Justification 2 = Top Centre, Justification 4 = Middle Left, Justification 6 = Middle Right
           ) ;; end list
       ) ;; end entmake

   (princ) ;; Suppress the output of the value returned by the last evaluated expression
);; End progn

;;;------------------- mtext on RH side of 'a' rotated 90 degrees  ---------------------;;;
 (progn
   
      (entmake ;; Append the following DXF data to the drawing database
           (list ;; Construct a list containing the following DXF data
              '(000 . "MTEXT")		;; Entity type
              '(100 . "AcDbEntity")	;; Subclass marker
              '(100 . "AcDbMText")	;; Subclass marker
        (cons 10 (polar a ang 1.5))		;; Insertion point
              '(001 . "Bacon & Eggs")	;; Content [single line]
              '(040 . 2.0)		;; Height
       (cons 050 per)     	;; Rotation in radians
       '(071 . 2)		;; Justification 2 = Top Centre, Justification 4 = Middle Left, Justification 6 = Middle Right
           ) ;; end list
       ) ;; end entmake
   
   ); end progn
     
   ); end (if (< w 15)

 

Could the 3 'entmake' expressions be condensed into one bearing in mind the 3 different text justifications, 2 line text twice & two different text heights?

 

Sorry to be a pain

 

Harry

Edited by Happy Hobbit
Posted

Further to the above, I'm trying to sort a if or and statement. It's to keep the mtext readable no matter what angle the main entity is drawn at.

The code I'm using:

 

(defun c:Slotmtx (/ a a1 a2 ang b b1 b2 dist dist2 hght ins obm r ssize trot w)
(setvar "plinewid" 0)
(command "ORTHO" "OFF")
(command "SNAP" "ON")
(setq obm (getvar "blipmode"))
(initget 7)
(setvar "blipmode" 1)
(initget 1)
(setq a (getpoint "\nLocate first center: "))
(initget 1)
(setq b (getpoint a "\nLocate second center: "))
(setvar "blipmode" 0)
(setq ang (angle a b))
(initget "10 20 30 40 50 60 Custom")
 (setq ssize (cond ((getkword "\nWidth of slot? [10/20/30/40/50/60/Custom] <10>: "))
                          ("10")))

(cond
   ((eq ssize "10")
 (setq w 10)
   )
   ((eq ssize "20")
 (setq w 20)
   )
       ((eq ssize "30")
 (setq w 30)
   )
       ((eq ssize "40")
 (setq w 40)
   )
       ((eq ssize "50")
 (setq w 50)
   )
       ((eq ssize "60")
 (setq w 60)
   )
   ((eq ssize "Custom")
 (setq w (getreal "\nCustom Slot Size?"))
    )	      
 );end cond

(setq r (/ w 2))
(setq a1 (polar a (- ang (/ pi 2)) r)
a2 (polar a (+ ang (/ pi 2)) r)
b1 (polar b (- ang (/ pi 2)) r)
b2 (polar b (+ ang (/ pi 2)) r)
dist (distance a b)
dist2 (/ dist 2)
ins (polar a ang dist2)
hght (/ w 4)
);end setq
(setvar "cmdecho" 0)
(command ".pline" a1 b1 "A" b2 "L" a2 "A" "CL")

;;;------------------- Start insert mtext function ---------------------;;;
 (if(or (<= ang (* pi 0.5)) (> ang (* pi 1.5)))
(setq trot ang)
(setq trot (+ ang pi ))
           );end if

  (command "-layer" "M" "TEXT" "C" "3" "" "");; sets layer to TEXT or creates layer TEXT if it doesn't exist
;;;------------------- MC mtext in centre of box  ---------------------;;;
       (entmake                                ;; Append the following DXF data to the drawing database
           (list                               ;; Construct a list containing the following DXF data
              '(000 . "MTEXT")                 ;; Entity type
              '(100 . "AcDbEntity")            ;; Subclass marker
              '(100 . "AcDbMText")             ;; Subclass marker
   		(cons 10 ins)         		;; Insertion point
              '(001 . "SLOT\n No. ")           ;; Content
              	(cons 040 hght)              	;; Height
            	(cons 050 trot) 		;; Rotation in radians
          	'(071 . 5)			;; Justification: 2 = TC, 4 = ML, 5 = MC, 6 = MR
           )					;; end list
       )					;; end entmake
 ;;;------------------- End insert mtext function   ---------------------;;;  
(setvar "cmdecho" 1)
(setvar "blipmode" obm)
(command ".BLIPMODE" "off")
(princ)
)

 

I'm not sure the code is right, although the following seems to work ok:

 

(if(or (<= ang (* pi 0.5)) (> ang (* pi 1.5)))

 

My code is missing the 'less than 180°' bit

 

Please can anyone help me construct an 'if and or' to suit?

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