Author Topic: AutoLISP routine help!!!! (by collegeCAD)  (Read 41397 times)

0 Members and 1 Guest are viewing this topic.

t-bear

  • Guest
AutoLISP routine help!!!! (by collegeCAD)
« Reply #15 on: September 30, 2003, 06:40:32 PM »
Lousy spelling is one of Se7en's better traits.....we won't talk about the nastier ones. :lol:  :twisted:
I've been following this thread since its beginning (over "there") and you guys never cease to amaze me.  After running the "newbie" through all those hoops, 7  tells us he likes the first code better.......why am I not surprised?
Well....test in 15 min....gotta go.

T-

daron

  • Guest
AutoLISP routine help!!!! (by collegeCAD)
« Reply #16 on: September 30, 2003, 07:04:23 PM »
I know it is (7's spelling). I just couldn't let that one go. I could just imagine CC coming in here for help of a function that doesn't exist. I certainly don't want to offend, but 7, is your spelling really bad, or are you jaust a non-typist? I've seen others who could out-spell anybody, but when it comes to typing, they're so intent on staring at the keyboard trying to find all the keys and get out what they type so fast, that they appear to not be able to spell. I've also heard that drafters aren't good speller's. I can't figure that one out. Isn't that the job of a drafter, to be able to communicate well?

JohnK

  • Administrator
  • Seagull
  • Posts: 10603
AutoLISP routine help!!!! (by collegeCAD)
« Reply #17 on: September 30, 2003, 08:12:07 PM »
No, no offence. I cant spell worth crap! (plus im typing on a laptop so the keys are a little to closs together for my taste.) But anyways...

That's fine. Put it in pseudo code. (You did teach him pseudo code didnt you.)
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

collegeACAD

  • Guest
AutoLISP routine help!!!! (by collegeCAD)
« Reply #18 on: September 30, 2003, 09:40:00 PM »
My teacher's name is Thomas Longnecker... very cool guy.

I heard mention of Plano... I live there (as I'm sure you know)... anyone else in the area?

Here's my final project. I plan on developing it further along the road... maybe setting up my limits, making my coffee in the morning, creating my title block, etc. Who knows where it will take me.:
Code: [Select]

;;; "User Friendly Layer Setup"
;;; layersetup1.lsp
;;; By: Jon Nelson
;;; DFTG1352
;;; Thomas Longnecker


(defun c:layersetup ()
  (setvar "cmdecho" 0)      
  (command "linetype" "load" "*" "acad.lin" "")
  (vl-load-com)
  (setq n nil)
  (setq tn t)
  (alert "The following linetypes WILL NOT be used w/ this AutoLISP routine:
   
                        - ISO 128 (ISO/DIS 12011) linetypes
                                  - HOT_WATER_SUPPLY
                                         - GAS_LINE
                                   
Setting these linetypes to a certain layer can only be done manually."
)
  (while tn
    (setq n (append n (list (getstring t "\nPlease enter a new layer name or [Enter] to continue: ")))
 )
    (if (= (last n) "")
      (setq n (vl-remove "" n)
   tn nil)
      )
    )  
  (foreach item n
    (alert "For layer color, use one of the\nfollowing standard color names:\n\n- Red\n- Yellow\n- Green
- Cyan\n- Blue\n- Magenta\n- White\n- 8 (dark gray)\n- 9 (light gray)"
  )
    (initget 1 "Red Yellow Green Cyan Blue Magenta White 8 9")
    (setq c
  (getkword (strcat "\nPlease enter a STANDARD COLOR NAME for "
    item
    "'s layer: ")
 )
    )
    (alert "
For linetypes, use one of the\nlisted lintetypes:\n
- Batting SSSSSSSSSSSSSSS
- Border __ __ . __ __ .
- BORDER2 __.__.__.__.__.
- BORDERX2 ____  ____  .  
- BYBlock _______________
- BYLayer _______________
- CEnter ____ _ ____ _ _
- CENTER2 ___ _ ___ _ ___
- CENTERX2 ________  __  _
- COntinuous _______________
- DASHDOT __ . __ . __ .
- DASHDOTX2 ____  .  ____  
- DASHED __ __ __ __ __
- DASHED2 _ _ _ _ _ _ _ _
- DASHEDX2 ____  ____  ___
- DIvide ____ . . ____ .
- DIVIDE2 __..__..__..__.
- DIVIDEX2 ________  .  .
- DOT . . . . . . . .
- DOT2 ...............
- DOTX2 .  .  .  .  .  
- FENCELINE1 ----0-----0----
- FENCELINE2 ----[]-----[]--
- Hidden __ __ __ __ __
- HIDDEN2 _ _ _ _ _ _ _ _
- HIDDENX2 ____ ____ ____
- Phantom ______  __  __
- PHANTOM2 ___ _ _ ___ _ _
- PHANTOMX2 ____________  
- Tracks -|-|-|-|-|-|-|-
- Zigzag VVVVVVVVVVVVV
\nYes, there is a reason that some of the letters are capitalized.
")
    (initget 1 "BAtting Border BORDER2 BORDERX2 BYBlock BYLayer CEnter CENTER2 CENTERX2
                COntinuous DASHDOT DASHDOTX2 DASHED DASHED2 DASHEDX2 DIvide DIVIDE2 DIVIDEX2
                DOT DOT2 DOTX2 FENCELINE1 FENCELINE2 Hidden HIDDEN2 HIDDENX2 Phantom PHANTOM2
                PHANTOMX2 Tracks Zigzag")
    (setq l
  (getkword (strcat "\n\nPlease enter a linetype for "
    item
    "'s layer: ")
  )    
    )
    (command "LAYER" "MAKE" item "COLOR" c item "LTYPE" l item "")
  )
  (setq current (getstring t "\nPlease enter which layer you would like to make current: "))
  (command "layer" "s" current "")
  (setvar "cmdecho" 1)
  (princ)  
)

(prompt "Enter LAYERSETUP to start")



I have a modified version, w/out as many pop-ups... here's that code:

Code: [Select]

;;; "Layer Setup"
;;; layersetup2.lsp
;;; By: Jon Nelson
;;; DFTG1352
;;; Thomas Longnecker


(defun c:layersetup ()
  (setvar "cmdecho" 0)      
  (command "linetype" "load" "*" "acad.lin" "")
  (vl-load-com)
  (setq n nil)
  (setq tn t)
  (alert "The following linetypes WILL NOT be used w/ this AutoLISP routine:
   
                        - ISO 128 (ISO/DIS 12011) linetypes
                                  - HOT_WATER_SUPPLY
                                         - GAS_LINE
                                   
Setting these linetypes to a certain layer can only be done manually."
)
  (while tn
    (setq n (append n (list (getstring t "\nPlease enter a new layer name or [Enter] to continue: ")))
 )
    (if (= (last n) "")
      (setq n (vl-remove "" n)
   tn nil)
      )
    )  
  (foreach item n    
    (initget 1 "Red Yellow Green Cyan Blue Magenta White 8 9")
    (setq c
  (getkword (strcat "\nPlease enter a STANDARD COLOR NAME for "
    item
    "'s layer: ")
 )
    )
    (initget 1 "BAtting Border BORDER2 BORDERX2 BYBlock BYLayer CEnter CENTER2 CENTERX2
                COntinuous DASHDOT DASHDOTX2 DASHED DASHED2 DASHEDX2 DIvide DIVIDE2 DIVIDEX2
                DOT DOT2 DOTX2 FENCELINE1 FENCELINE2 Hidden HIDDEN2 HIDDENX2 Phantom PHANTOM2
                PHANTOMX2 Tracks Zigzag")
    (setq l
  (getkword (strcat "\nPlease enter a linetype for "
    item
    "'s layer: ")
  )    
    )
    (command "LAYER" "MAKE" item "COLOR" c item "LTYPE" l item "")
  )
  (setq current (getstring t "\nPlease enter which layer you would like to make current: "))
  (command "layer" "s" current "")
  (setvar "cmdecho" 1)
  (princ)  
)

(prompt "Enter LAYERSETUP to start")


Here's the original, "fixed" of course. It's buggy as Daron originally mentioned. If you fart wrong around the program, it errors out:
Code: [Select]

(DEFUN c:LAYERSETUP()
  (COMMAND "LINETYPE" "LOAD" "*" "ACAD.LIN" "")
  (SETQ X (GETINT "\n How many layers would you like?  "))
  (REPEAT X
    (SETQ N (GETSTRING T "\n Please enter the new layer name:  "))
    (SETQ C (GETSTRING "\n Please enter the new layer's color:  "))
    (SETQ L (GETSTRING "\n Please enter the linetype for this layer: "))
    (COMMAND "LAYER" "MAKE" N "COLOR" C N "LTYPE" L N "")
  )  
  (PRINC)
)



If any admins read this, I was wondering if you could change my handle to collegeCAD since it got screwed up the first time I registered... I guess just post up in here and let me know that it's changed so I can change the username on the login page. Thanks. ;)

Take care for now, I'll check the thread later on tonight when I get home. Happy hour is calling me. Cheers!

Mark

  • Custom Title
  • Seagull
  • Posts: 28753
AutoLISP routine help!!!! (by collegeCAD)
« Reply #19 on: October 01, 2003, 02:42:10 AM »
Quote from: collegeACAD

If any admins read this, I was wondering if you could change my handle to collegeCAD since it got screwed up the first time I registered... I guess just post up in here and let me know that it's changed so I can change the username on the login page. Thanks. ;)


Your first attempt failed because of a bad e-mail address.
Quote
<email@address removed>:
65.54.254.145 does not like recipient.
Remote host said: 550 Requested action not taken: mailbox unavailable
Giving up on 65.54.254.145.


I have reset the account for CollegeCAD with the original requested password.

Please use a valid e-mail address, thanks. I go out of my way to ensure that e-maill addresses on this forum are kept private. Unless you include it in your sig no one can see it but me!

Mark
TheSwamp.org  (serving the CAD community since 2003)

collegeCAD

  • Guest
AutoLISP routine help!!!! (by collegeCAD)
« Reply #20 on: October 01, 2003, 05:29:47 AM »
Quote from: Mark Thomas
Quote from: collegeACAD

If any admins read this, I was wondering if you could change my handle to collegeCAD since it got screwed up the first time I registered... I guess just post up in here and let me know that it's changed so I can change the username on the login page. Thanks. ;)


Your first attempt failed because of a bad e-mail address.
Quote
<email@address removed>:
65.54.254.145 does not like recipient.
Remote host said: 550 Requested action not taken: mailbox unavailable
Giving up on 65.54.254.145.


I have reset the account for CollegeCAD with the original requested password.

Please use a valid e-mail address, thanks. I go out of my way to ensure that e-maill addresses on this forum are kept private. Unless you include it in your sig no one can see it but me!

Mark


Much abliged, hats off to you ;)

SMadsen

  • Guest
AutoLISP routine help!!!! (by collegeCAD)
« Reply #21 on: October 01, 2003, 09:47:25 AM »
Quote from: Daron
Stig, you doing a side job in Plano, Texas?
Well, I do run an email-based course in basic AutoLISP in Denmark (in Danish, of course). Doesn't attract alot of students, though, but it managed to put butter on the bread now and then.
Oh, let me know if there's a market for it in USA and I'll start translating it!! :)

JohnK

  • Administrator
  • Seagull
  • Posts: 10603
AutoLISP routine help!!!! (by collegeCAD)
« Reply #22 on: October 01, 2003, 09:58:43 AM »
Stig, that would prolly be a cool idea. I dont know for sure, but im sure there might be some bites.
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

daron

  • Guest
AutoLISP routine help!!!! (by collegeCAD)
« Reply #23 on: October 01, 2003, 10:23:15 AM »
Quote from: SMadsen
Well, I do run an email-based course in basic AutoLISP in Denmark (in Danish, of course). Doesn't attract alot of students, though, but it managed to put butter on the bread now and then.
Oh, let me know if there's a market for it in USA and I'll start translating it!! :)


What Se7en said, but why I asked was to get a jab in at se7en when he said "You can NEVER know it all."

SMadsen

  • Guest
AutoLISP routine help!!!! (by collegeCAD)
« Reply #24 on: October 01, 2003, 12:10:41 PM »
collegeCAD, good job! and congrats with your 'A'

I took the liberty of making a few suggestions to your code. It's still a schoolbook example (!), so I hope you have covered some of the stuff already. Maybe there are some things in it you can use, maybe not.

Code: [Select]
;;; "User Friendly Layer Setup"
;;; layersetup1.lsp
;;; By: Jon Nelson
;;; DFTG1352
;;; Thomas Longnecker

;;; Altered and commented by someone else

(defun c:layersetup ()
  (setq cmd (getvar "CMDECHO"))
  (setvar "cmdecho" 0)
 
  ;; Loading already loaded linetypes will result in
  ;; a prompt that will cause the routine to get stuck
  ;; in the LINETYPE command. This can be avoided by
  ;; setting the sysvar EXPERT to 3 before calling the
  ;; command.
  ;; Of course, with all changes in the users environment,
  ;; remember to reset it after you're done with it! The
  ;; same goes for CMDECHO above.
  (setq expert (getvar "EXPERT"))
  (setvar "EXPERT" 3)
  (command "linetype" "load" "*" "acad.lin" "")
  (setvar "EXPERT" expert)

  (vl-load-com)
  (setq n nil)
  (setq tn t)

  (while tn
    ;; For verifying symbol names in AutoLISP there is an
    ;; often overlooked function called SNVALID. Instead of
    ;; explaining here what it does, it'll be a good excercise
    ;; to look it up in the help reference. In short, it can be
    ;; used to verify layer names:
    (setq layName (getstring t "\nPlease enter a new layer name or [Enter] to continue: "))
    (if (snvalid layName)
      (setq n (append (list layName) n))
      (setq tn nil)
    )
  )
 
  (foreach item n
    ;; You seem to be well aware of the INITGET function, but
    ;; are you also aware that other GETxxx functions can accept
    ;; keywords? Because the LAYER command can accept integers, why
    ;; not use GETINT to retrieve the color?
    ;; However, because GETINT accepts integers between –32,768 and
    ;; 32,767 we need to verify the input before proceeding, so we'll
    ;; use tn as a flag once again to allow for multiple tries.
    (setq tn T)
    (while tn
      (initget 1 "Red Yellow Green Cyan Blue Magenta White")
      (setq layColor (getint (strcat "\nPlease enter a STANDARD COLOR NAME for "
                                     item
                                     "'s layer: "
                             )
                     )
      )
      (if (or (= (type layColor) 'STR) (< 1 layColor 255))
        (setq tn nil)
        (princ "\nInvalid color. Try again")
      )
    )

    ;; The above code should take care of input that any
    ;; AutoCAD user is familiar with so I don't think there
    ;; is a need to inform of valid inputs

    ;; If you want to inform about available linetypes then
    ;; it's possible to use the linetypes that are actually
    ;; available on the machine. I've known people who thought it
    ;; might save resources to delete some of these linetypes they
    ;; never use anyway from the acad.lin file.
    ;; Of course, getting the linetype pseudo-appearances are a
    ;; little harder so we'll save that for another time :)

    ;; The DRAWBACK of this method is that it's really hard to convert
    ;; the names and use them in a initget! But as a compensation for
    ;; our own codes sake we'll build a list to verify input.

    ;; By the way, I don't see why you are having problems with
    ;; complex linetypes?

    ;; First, reset some variables (no local vars, remember? :)
    (setq ltype nil ltypeInfo "" ltypeList nil)

    ;; Then run through the linetype table to pick up each name
    ;; of the actually available linetypes
    (while (setq ltype (tblnext "LTYPE" (not ltype)))
      (setq ltypeInfo (strcat ltypeInfo "\n" (cdr (assoc 2 ltype)))
            ltypeList (cons (cdr (assoc 2 ltype)) ltypeList)
      )
    )

    ;; We'll use tn again as a flag to control a loop until a
    ;; valid input is bagged. I don't think throwing an alert in
    ;; the users face is attractive. Instead we can provide an
    ;; alert with the info if the user desires. In order to do this
    ;; we can utilize bit 128 of INITGET that allows any arbitrary
    ;; input (= linetype name) and still have a chance to catch
    ;; the users request for help ("?")
    (setq tn T)
    (while tn
      (initget 128 "? Continuous")
      (setq ltype (getkword (strcat "\n\nPlease enter a linetype for "
                                    item
                                    "'s layer or [?/Continuous]: "
                            )
                  )
      )
      (if (= ltype "?")
        (alert (strcat "For linetypes, use one of the\nlisted lintetypes:\n" ltypeInfo))
        ;; Because linetypes are returned in uppercase by the
        ;; linetype table and the user could have used any
        ;; case he like, we'll convert his string to uppercase
        ;; before comparing it. Of course, if linetype is "Continuous"
        ;; then simply proceed
        ;; Also, because GETKWORD returns nil (and not "") on empty
        ;; response, we'll check for this.
        (if (and ltype (or (= ltype "Continuous") (member (strcase ltype) ltypeList)))
          (setq tn nil)
          (princ "\nInvalid linetype name. Try again")
        )
      )
    )

    (command "LAYER" "MAKE" item "COLOR" layColor item "LTYPE" ltype item "")
  )
  (setq
    current (getstring t "\nPlease enter which layer you would like to make current: ")
  )
  ;; Just making sure that the layer name input here is
  ;; a valid one by looking it up in the layer table before
  ;; trying to set it active
  (if (tblsearch "LAYER" current)
    (command "layer" "s" current "")
    (princ "\nNo such layer .. take a typing lesson!")
  )
  ;; Reset environment to what it was
  (setvar "cmdecho" cmd)
  (princ)
)

(prompt "Enter LAYERSETUP to start")

daron

  • Guest
AutoLISP routine help!!!! (by collegeCAD)
« Reply #25 on: October 01, 2003, 12:37:48 PM »
Beautiful Stig. I especially like the "...take a typing class.". CC, now do see why else I brought you over here? If your instructor gave you an A for what you turned in, something like this should break the bell curve and the grading system. Not to say that your's wasn't good, but man... like I said, if you can get what Stig's saying here, you might be able to teach your instructor a thing or two. Have you looked at this thread posted by Rugaroo? Stig gets into a really good discussion about lists and how to use them.

SMadsen

  • Guest
AutoLISP routine help!!!! (by collegeCAD)
« Reply #26 on: October 01, 2003, 01:02:11 PM »
Quote from: Daron
If your instructor gave you an A for what you turned in, something like this should break the bell curve and the grading system.
"Hey, that's cheating!" ... "Nah, that's life"

daron

  • Guest
AutoLISP routine help!!!! (by collegeCAD)
« Reply #27 on: October 01, 2003, 01:23:15 PM »
Just to clarify, I would never tell someone to cheat or turn in something that someone else wrote. That's plagiarism. All I meant was that if CC were at the level of what you wrote, now, it would break the curve. In the near future, as long as CC keeps coming back here and asking questions, he WILL be at the level to write something of that magnitude and I'm sure his instructor will be grading him tougher and expect more out of him.

JohnK

  • Administrator
  • Seagull
  • Posts: 10603
AutoLISP routine help!!!! (by collegeCAD)
« Reply #28 on: October 01, 2003, 01:26:34 PM »
Its getting alot better. however I would make one MINOR adjustment. I would use the "acad_colordlg" to offer a way to pick the color on the screen.
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

SMadsen

  • Guest
AutoLISP routine help!!!! (by collegeCAD)
« Reply #29 on: October 01, 2003, 01:51:46 PM »
Se7en, the visible kind of guy, eh?  :shock:

I agree, that would be cool.