Author Topic: trying to write my first lisp and i need a bit of help  (Read 13366 times)

0 Members and 1 Guest are viewing this topic.

daron

  • Guest
trying to write my first lisp and i need a bit of help
« Reply #15 on: July 26, 2005, 03:09:34 PM »
Let's clean up your code a little. You're doing fine though.
Code: [Select]

(defun c:mto (/ ename elist)
     (setq ename (car (entsel "\nSelect text: "))
              elist (entget ename)
     )
)

If you were to run this, you'd get a return value; that bunch of info.
[22](73 . 0) is the 23rd item in a LIST containing group code 73 and 0. This is what you've seen called a dxf value or a dotted pair. So far I can tell that your selected text is left justified. What's the value of code 72, 10 and 11?

Extra credit: What other group codes might you find useful from that list and what will 73, 72, 10 and 11 tell me?

daron

  • Guest
trying to write my first lisp and i need a bit of help
« Reply #16 on: July 26, 2005, 03:18:30 PM »
Oh Dan, I just noticed. When you are looking at the (73 . 0), you're seeing it as a real i.e. 73.0. That's not what it is. What it is is a key-value construct. In other words, the 73 is a key and the 0 is the value. The dot in the middle is the separator and it is separated from the key and the value by a space on either side. Check the cons function. It should help a little. Also, I'm sure in Stig's tutorial, he covers assoc and cons. When you look at the 10 and 11 keys, you'll notice there is no dot separator. It still is a key. The cons function should also make this make sense.

Eloquintet

  • Gator
  • Posts: 3206
trying to write my first lisp and i need a bit of help
« Reply #17 on: July 26, 2005, 03:34:18 PM »
i saw what you mean when i was pulling up the info. i did think that was an integer and not a dotted pair. i just got done reading data types  :oops: am i in the ballpark here


******************************************************

Group 72 and 73 integer codes
 
Group 73

 Group 72

 
3 (top)
 TLeft
 TCenter
 TRight
 
 
 
 
2 (middle)
 MLeft
 MCenter
 MRight
 
 
 
 
1 (bottom)
 BLeft
 BCenter
 BRight
 
 
 
 
0 (baseline)
 Left
 Center
 Right
 Aligned
 Middle
 Fit
 
********************************************************


72
 Horizontal text justification type (optional, default = 0) integer codes (not bit-coded)

0 = Left; 1= Center; 2 = Right

3 = Aligned (if vertical alignment = 0)

4 = Middle (if vertical alignment = 0)

5 = Fit (if vertical alignment = 0)

See the Group 72 and 73 integer codes table for clarification
 
*******************************************************

73
 Vertical text justification type (optional, default = 0): integer codes (not bit-coded):

0 = Baseline; 1 = Bottom; 2 = Middle; 3 = Top

See the Group 72 and 73 integer codes table for clarification


*****************************************************

10
 First alignment point (in OCS)

DXF: X value; APP: 3D point



************************************************************

11
 Second alignment point (in OCS) (optional)

DXF: X value; APP: 3D point

This value is meaningful only if the value of a 72 or 73 group is nonzero (if the justification is anything other than baseline/left)
Dan

AutoCAD Architecture 2015

daron

  • Guest
trying to write my first lisp and i need a bit of help
« Reply #18 on: July 26, 2005, 03:56:01 PM »
Yes, think of it like a matrix. In fact, if you look at the very bottom of that page, you'll see how 3,2 is Top Right. Now, I'm going to go on the premise that your text is 0,0 Left. At this point, all we need to get is the value of 10. Add to the code:
Code: [Select]
(defun c:mto (/ ename elist)
     (setq ename (car (entsel "\nSelect text: "))
              elist (entget ename)
              code10 (assoc 10 elist)
     )
)

To decipher that a little, assoc = associate. What are we associating? Group code 10. What are we associating it to? The entity list that this particular 10 is in. In code: (assoc 10 elist). When you inspect that piece, you'll end up with four sets of numbers and 10 will be the first one. The code above is a fully functioning program. In autocad, after running mto, type !code10. What's returned? Type !elist or !ename. You should get nil as the return on the last two. Why? and why is that not the case with code 10?

I'm going home now. Your homework assignment is this: study assoc, cons, and list. Also, find the functions that will strip the key (10) out of the list we've just assoc'd and play with them a little.

Eloquintet

  • Gator
  • Posts: 3206
trying to write my first lisp and i need a bit of help
« Reply #19 on: July 26, 2005, 04:18:11 PM »
ok daron i plan to print this out and view it at home when i can focus better, there's insanity going on all around me. thanks for all of your help
Dan

AutoCAD Architecture 2015

Eloquintet

  • Gator
  • Posts: 3206
trying to write my first lisp and i need a bit of help
« Reply #20 on: July 27, 2005, 09:32:31 AM »
i'd like to study the topics you say but i'm thinking it would probably be a good idea to read stigs tutorial in the order it was presented. i think i should be trying more of his exercises as i'm going along so the concepts stick. i actually think i might refresh on lessons 1 and 2 because i read those awhile ago and haven't retained everything  :oops: so that's what i'll be doing today
Dan

AutoCAD Architecture 2015

daron

  • Guest
trying to write my first lisp and i need a bit of help
« Reply #21 on: July 27, 2005, 09:59:11 AM »
Dan, I'd stick with this and use his tutorials as a reference. Hold on. Two things: 1) It hasn't stuck because it hasn't been applied. 2) Lesson 1 and 2 are both good, but hold on to reading lesson 2 for now. We'll get into that as we build this if you stay with me. I'm walking you through this. Let's get you understanding what to use for the purposes you desire, then lesson 2 will make more sense than ever before. Lesson 1 is a fine primer. If you want to read any tutorial, go to lesson3 and focus in on the 10th page. These are the functions I need you to understand for the point we're at with your program we're building here.

Don't bail out on me, Dan. Sure Stig's turorial's are great, but if you never put them down to real application no amount of greatness will ever be retained. Take whatever time you need to do your daily work, but keep this thread going. You will start to understand.

When I was learning, I had someone right there to walk me through it. It took me months to get many concepts down and I was always asking him questions about how to automate this or that. He put a lot into teaching me. You have it better. You have many people who'd bend over backwards to help you build your knowledge in this area. Take hold of it. Don't let this procedure die. Stay with me.

Eloquintet

  • Gator
  • Posts: 3206
trying to write my first lisp and i need a bit of help
« Reply #22 on: July 27, 2005, 10:51:20 AM »
i'm with you daron it's just that my boss really wants me to work on the tools for text masking . i have four lisps:1 that will mask selected text (which is working) 2 which will mask all text (which is not working) 3 which will unmask selected text (which is not working) and 4 which will unmask all text (which is working). basically all i did was include an an ssget and an ssget "x" in both then comment out one or the other but it's not working. here's all four so once i can get that out of the way i can get back to our discussion:


this is working*************************

Code: [Select]
(defun C:TMS (/ MASK_LIST ENT SS)
;;(command "_.texttofront" "T")
;;(setq SS (ssget "x" '((0 . "mtext"))))
(setq ss (ssget))
(setq MASK_LIST
(list
(cons 90 3)
(cons 63 256)
(cons 45 1.5)
(cons 441 1616860)
)
N 0
)
(if SS
(repeat (sslength SS)
(setq ENT (entget (ssname SS N)))
(setq ENT (append ENT MASK_LIST))
(entmod ENT)
(setq N (1+ N))
)
)
(command "_.texttofront" "T")
(princ)
)


below is not working*********** it returns nil???

Code: [Select]
(defun C:TMA (/ MASK_LIST ENT SS)
;;(command "_.texttofront" "T")
(setq SS (ssget "x" '((0 . "mtext"))))
;;(setq ss (ssget))
(setq MASK_LIST
(list
(cons 90 3)
(cons 63 256)
(cons 45 1.5)
(cons 441 1616860)
)
N 0
)
(if SS
(repeat (sslength SS)
(setq ENT (entget (ssname SS N)))
(setq ENT (append ENT MASK_LIST))
(entmod ENT)
(setq N (1+ N))
)
)
(command "_.texttofront" "T")
(princ)
)




this is not working************************ it returns ; error: extra right paren on input?????????

Code: [Select]
(defun C:UTMS (/ SS N)
(vl-load-com)
;;(setq SS (ssget "x" '((0 . "mtext")))
(setq ss (ssget))    
N 0
)
(if SS
(repeat (sslength SS)
(vla-put-backgroundfill
(vlax-ename->vla-object (ssname SS N))
0
)
(setq N (1+ N))
)
)
(princ)
)


this is working*****************************


Code: [Select]
(defun C:UTMA (/ SS N)
(vl-load-com)
(setq SS (ssget "x" '((0 . "mtext")))
;;(setq ss (ssget))
N 0
)
(if SS
(repeat (sslength SS)
(vla-put-backgroundfill
(vlax-ename->vla-object (ssname SS N))
0
)
(setq N (1+ N))
)
)
(princ)
)
Dan

AutoCAD Architecture 2015

Eloquintet

  • Gator
  • Posts: 3206
trying to write my first lisp and i need a bit of help
« Reply #23 on: July 27, 2005, 10:53:02 AM »
i actually just finished lesson 3 so that is pretty fresh
Dan

AutoCAD Architecture 2015

daron

  • Guest
trying to write my first lisp and i need a bit of help
« Reply #24 on: July 27, 2005, 11:02:15 AM »
Quote
error: extra right paren on input?????????

I don't know if this will make it work, but they always say, programming is 95% debugging, or something like that. I'll point you for where to look, but I'm not going to show you what the problem is. First take the error message to heart and remember that in lisp, for every open paren you need to close it. Here's the area to look at:
Code: [Select]
(setq ss (ssget)) N 0)
Hint: is the setq closed? If so, what function would N be performing? IOW, there's a right paren you need to get rid of.

Eloquintet

  • Gator
  • Posts: 3206
trying to write my first lisp and i need a bit of help
« Reply #25 on: July 27, 2005, 11:23:55 AM »
nevermind i got it. the first one was that i didn't put a space after i loaded it in my button. the second was the extra paren after ssget proceed... 8)
Dan

AutoCAD Architecture 2015

daron

  • Guest
trying to write my first lisp and i need a bit of help
« Reply #26 on: July 27, 2005, 11:43:13 AM »
Now that you got that all figured out, where do we stand in our app? I'll repost it.
Code: [Select]
(defun c:mto (/ ename elist)
     (setq ename (car (entsel "\nSelect text: "))
              elist (entget ename)
              code10 (assoc 10 elist)
     )
)

So far, we have a USUBR that return a group code list. After running mto you're returned:
(10 x-coord y-coord z-coord)
Type in autocad !ename, !elist and !code10.
Why do the first two return nil (and they should) and the last one return the list or return value. This should be covered in lesson2 I believe.

On to the next portion, how can you lose the 10 in the returned list? IOW, what function "Returns a list containing all but the first element of the specified list"?

Eloquintet

  • Gator
  • Posts: 3206
trying to write my first lisp and i need a bit of help
« Reply #27 on: July 27, 2005, 11:49:34 AM »
ummm cdr heeeeeey i didn't even peak  8)
Dan

AutoCAD Architecture 2015

Eloquintet

  • Gator
  • Posts: 3206
trying to write my first lisp and i need a bit of help
« Reply #28 on: July 27, 2005, 11:54:49 AM »
mine has another paren at the end. yours returns malformed list here's mine:

Code: [Select]
(defun c:mto (/ ename elist)
     (setq ename (car (entsel "\nSelect text: "))
              elist (entget ename)
              code10 (assoc 10 elist)
     )
)
Dan

AutoCAD Architecture 2015

Eloquintet

  • Gator
  • Posts: 3206
trying to write my first lisp and i need a bit of help
« Reply #29 on: July 27, 2005, 12:05:47 PM »
ididn't get the last result when i ran that line i got nil as well but i'm guessing it's because they have no values attached to them??
Dan

AutoCAD Architecture 2015