TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: hudster on April 19, 2005, 08:02:54 AM

Title: Mtext
Post by: hudster on April 19, 2005, 08:02:54 AM
I'm attempting to write a lisp to move notes to a set distance under the last note.

As these notes are in mtext, is there a way I can extract the height of a peiece of mtext, not the text height.

i.e if there is 2 lines it's the text height + 1.66 (for the text gap).

any ideas?
Title: Mtext
Post by: Mark on April 19, 2005, 08:32:35 AM
DXF group code 43 of the mtext entity.

Quote
43  Vertical height of the mtext entity


Do you know to extract the DXF code from the entity?
Title: Mtext
Post by: hudster on April 19, 2005, 08:57:56 AM
not yet :(
Title: Mtext
Post by: daron on April 19, 2005, 09:02:41 AM
Yes you do. I know for a fact that Stig has taught you about cdr and assoc.
Title: Mtext
Post by: Mark on April 19, 2005, 09:09:35 AM
May be a bit confusing.
Code: [Select]

; if user selects something
 (if (setq ent (car (entsel "\nSelect MTEXT: ")))
   ; if the selected entity is MTEXT
   (if (= (cdr (assoc 0 (entget ent))) "MTEXT")
     ; set variable 'mt_height' (real)
     (setq mt_height (cdr (assoc 43 (entget ent))))
     )
   )
Title: Mtext
Post by: hudster on April 19, 2005, 09:14:42 AM
Quote from: Daron
Yes you do. I know for a fact that Stig has taught you about cdr and assoc.


I'm behind in my class work :(

[/hangs head in shame/]
Title: Mtext
Post by: daron on April 19, 2005, 09:29:10 AM
It's okay. Just take it as a hint.
Title: Mtext
Post by: hudster on April 19, 2005, 12:01:32 PM
Right i've manged to extract the part I want using assoc.

so i now have (43 . 10.8333), but I can't extract the 10.8333 part I want.

I get this

Code: [Select]
Command: !DIST1
(43 . 10.8333)

Command: (CADR DIST1)
; error: bad argument type: consp 10.8333


so how can I extract the bit I need?
Title: Mtext
Post by: Mark on April 19, 2005, 12:04:19 PM
Code: [Select]
(cdr dist1) not cadr. see above post of mine.
Title: Mtext
Post by: hudster on April 19, 2005, 12:05:02 PM
:oops:
Title: Mtext
Post by: hudster on April 19, 2005, 02:13:20 PM
Right I've almost got it now.

I've extracted the co-ordinates of the mtext insertion point using (setq insrt (assoc 10 ss1) and get this as a result, (10 66.667 641.144).

To change the Y co-ordinate do I have to break down the list to indivdual strings to change the Y co-ordinate or can I change it another way?
Title: Mtext
Post by: daron on April 19, 2005, 04:05:54 PM
look into subst and >this< (http://www.theswamp.org/phpBB2/viewtopic.php?t=4590)
Title: Mtext
Post by: daron on April 20, 2005, 08:35:45 AM
How are you doing with this? Need more?
Title: Mtext
Post by: hudster on April 20, 2005, 03:59:50 PM
I was looking at subst, but it doesn't really do what I want it to.

What I want is to take the co-ordinates of the Mtext insertion, subtract the mtext height from the Y co-ordinate and use this value as a point to copy to.

What I did, was use the list command to build a new point list to use as a co-ordinate, but I think there must be another, better way to do this.
Title: Mtext
Post by: Jeff_M on April 20, 2005, 04:13:58 PM
Here's how to do it using subst:
Code: [Select]
(setq ss1 (entget (car (entsel "\nSelect mtext: "))))
(setq insrt (cdr (assoc 10 ss1)))
(setq hgt (cdr (assoc 43 ss1)))
(setq new_insrt (subst (- (cadr insrt) hgt)(cadr insrt) insrt))

But, I would suggest recreating the list since this will fail if the X & Y values are identical.
Code: [Select]
(setq new_insrt (list (car insrt) (- (cadr insrt) hgt) (caddr insrt)))
Title: Mtext
Post by: hudster on April 20, 2005, 05:21:04 PM
cool.

I did everything the same up to the last line, then i went off into a ramble, breaking down the points to individual values before altering them and reconstructing the list.

I still have a lot to learn. :shock: