+ Reply to Thread
Page 1 of 2 1 2 LastLast
Results 1 to 10 of 11
  1. #1
    Quantum Mechanic Lee Mac's Avatar
    Computer Details
    Lee Mac's Computer Details
    Operating System:
    Windows 7 Ultimate (32-bit)
    Discipline
    Multi-disciplinary
    Lee Mac's Discipline Details
    Discipline
    Multi-disciplinary
    Details
    Custom Programming / Software Customisation
    Using
    AutoCAD 2013
    Join Date
    Aug 2008
    Location
    London, England
    Posts
    15,708

    Default Doubting my LISP Logic...

    Registered forum members do not see this ad.

    I have been trying to set a list of variables using mapcar, but can't seem to get them to hold the values. I am not sure why...

    I have tried:

    Code:
    (defun c:test (/ vlst v1 v2 v3)
      (setq vlst (list v1 v2 v3))
      (mapcar '(lambda (x y) (setq x y)) vlst '(1 2 3))
      (princ))
    to set the symbols "v1" "v2" & "v3" to 1, 2, 3 respectively, but this just keeps the variable "vlst" to (nil nil nil), and won't set them.

    Maybe I am having a stupid moment, or maybe there is a completely different function needed to accomplish this, but any ideas or opinions are welcomed.

    Cheers

    Lee
    Lee Mac Programming

    With Mathematics there is the possibility of perfect rigour, so why settle for less?

    Just another Swamper

  2. #2
    Senior Member
    Computer Details
    jammie's Computer Details
    Operating System:
    Ubuntu / XP / W8
    Discipline
    Civil
    jammie's Discipline Details
    Occupation
    Design Technician
    Discipline
    Civil
    Using
    AutoCAD 2012
    Join Date
    May 2006
    Location
    Ireland
    Posts
    299

    Default

    Hey Lee,

    I think the problem lies with declaring the symbols V1,V2 &V3 as variable names using SETQ.

    Using the function (setq x y) you are actually pass two arguments; X to create the variable and Y to assign it a value.


    In this instance I think SET would seem to be more appropiate

    From the acad support on SET

    The set function is similar to setq except that set evaluates both of its arguments whereas setq only evaluates its second argument

    Try the following

    Code:
      
      (defun c:test (/ vlst)
      (setq vlst '(v1 v2 v3))
      (mapcar '(lambda (x y) (set x y)) vlst '(1 2 3))
      (princ))
    Hope this is of some help,

    Jammie

  3. #3
    Super Member ASMI's Avatar
    Using
    AutoCAD 2008
    Join Date
    Nov 2005
    Location
    Oceanus Procellarum, Moon
    Posts
    1,427

    Default

    Lambda isn't need:

    Code:
    Command: (mapcar 'set '(v1 v2 v3) '(1 17.2 "Lee Mac"))
    (1 17.2 "Lee Mac")
    Code:
    Command: !v1
    1
    Command: !v2
    17.2
    Command: !v3
    "Lee Mac"

  4. #4
    Quantum Mechanic Lee Mac's Avatar
    Computer Details
    Lee Mac's Computer Details
    Operating System:
    Windows 7 Ultimate (32-bit)
    Discipline
    Multi-disciplinary
    Lee Mac's Discipline Details
    Discipline
    Multi-disciplinary
    Details
    Custom Programming / Software Customisation
    Using
    AutoCAD 2013
    Join Date
    Aug 2008
    Location
    London, England
    Posts
    15,708

    Default

    Quote Originally Posted by jammie View Post
    Hey Lee,

    I think the problem lies with declaring the symbols V1,V2 &V3 as variable names using SETQ.

    Using the function (setq x y) you are actually pass two arguments; X to create the variable and Y to assign it a value.


    In this instance I think SET would seem to be more appropiate

    From the acad support on SET




    Try the following

    Code:
      
      (defun c:test (/ vlst)
      (setq vlst '(v1 v2 v3))
      (mapcar '(lambda (x y) (set x y)) vlst '(1 2 3))
      (princ))
    Hope this is of some help,

    Jammie
    Quote Originally Posted by ASMI View Post
    Lambda isn't need:

    Code:
    Command: (mapcar 'set '(v1 v2 v3) '(1 17.2 "Lee Mac"))
    (1 17.2 "Lee Mac")
    Code:
    Command: !v1
    1
    Command: !v2
    17.2
    Command: !v3
    "Lee Mac"

    Ahhh! Many thanks guys for your time and patience

    I have never used "set" and so it didn't come to mind when thinking of which functions to use.

    Thank you both for such clear explanations

    Cheers

    Lee
    Lee Mac Programming

    With Mathematics there is the possibility of perfect rigour, so why settle for less?

    Just another Swamper

  5. #5
    Quantum Mechanic Lee Mac's Avatar
    Computer Details
    Lee Mac's Computer Details
    Operating System:
    Windows 7 Ultimate (32-bit)
    Discipline
    Multi-disciplinary
    Lee Mac's Discipline Details
    Discipline
    Multi-disciplinary
    Details
    Custom Programming / Software Customisation
    Using
    AutoCAD 2013
    Join Date
    Aug 2008
    Location
    London, England
    Posts
    15,708

    Default

    Thanks guys, put the knowledge to good use

    Code:
    ;; ============ Num.lsp ===============
    ;;
    ;;  FUNCTION:
    ;;  Will sequentially place numerical
    ;;  text upon mouse click, with optional
    ;;  prefix and suffix.
    ;;
    ;;  SYNTAX: num
    ;;
    ;;  AUTHOR:
    ;;  Copyright (c) 2009, Lee McDonnell
    ;;  (Contact Lee Mac, CADTutor.net)
    ;;
    ;;  PLATFORMS:
    ;;  No Restrictions,
    ;;  only tested in ACAD 2004.
    ;;
    ;;  VERSION:
    ;;  1.0  ~  05.04.2009
    ;;
    ;; ====================================
    
    
    (defun c:num  (/ vlst ovar dVars tmpVars pt)
      (setq    vlst '("OSMODE" "CLAYER")
        ovar (mapcar 'getvar vlst))
      (setvar "OSMODE" 0)
      (or (tblsearch "LAYER" "NumText")
          (vla-put-color
        (vla-add
          (vla-get-layers
            (vla-get-ActiveDocument
              (vlax-get-acad-object))) "NumText") acYellow))
      (setq dVars '(sNum inNum Pref Suff))
      (mapcar '(lambda (x y) (or (boundp x) (set x y))) dVars '(1 1 "" ""))
      (setq tmpVars (list (getreal (strcat "\nSpecify Starting Number <" (rtos sNum 2 2) ">: "))
                  (getreal (strcat "\nSpecify Increment <" (rtos inNum 2 2) ">: "))
                  (getstring (strcat "\nSpecify Prefix <" (if (eq "" Pref) "-None-" Pref) ">: "))
                  (getstring (strcat "\nSpecify Suffix <" (if (eq "" Suff) "-None-" Suff) ">: "))))
      (mapcar '(lambda (x y) (or (or (not x) (eq "" x)) (set y x))) tmpVars dVars)
      (while (setq pt (getpoint "\nClick for Text... "))
        (Make_Text pt (strcat Pref (rtos sNum 2 2) Suff))
        (setq sNum (+ sNum inNum)))
      (mapcar 'setvar vlst ovar)
      (princ))
    
    (defun Make_Text  (txt_pt txt_val)
      (entmake (list '(0 . "TEXT")
             '(8 . "NumText")
             (cons 10 txt_pt)
             (cons 40 (max 2.5 (getvar "TEXTSIZE")))
             (cons 1 txt_val)
             '(50 . 0.0)
             (cons 7 (getvar "TEXTSTYLE"))
             '(71 . 0)
             '(72 . 1)
             '(73 . 2)
             (cons 11 txt_pt))))
    Lee Mac Programming

    With Mathematics there is the possibility of perfect rigour, so why settle for less?

    Just another Swamper

  6. #6
    Senior Member
    Computer Details
    jammie's Computer Details
    Operating System:
    Ubuntu / XP / W8
    Discipline
    Civil
    jammie's Discipline Details
    Occupation
    Design Technician
    Discipline
    Civil
    Using
    AutoCAD 2012
    Join Date
    May 2006
    Location
    Ireland
    Posts
    299

    Default

    Your welcome Lee,

    Glad to be of help. I learned a bit more about Set and Setq myself from this post

    Nice work with the routine as well

    -Jammie

  7. #7
    Quantum Mechanic Lee Mac's Avatar
    Computer Details
    Lee Mac's Computer Details
    Operating System:
    Windows 7 Ultimate (32-bit)
    Discipline
    Multi-disciplinary
    Lee Mac's Discipline Details
    Discipline
    Multi-disciplinary
    Details
    Custom Programming / Software Customisation
    Using
    AutoCAD 2013
    Join Date
    Aug 2008
    Location
    London, England
    Posts
    15,708

    Default

    Quote Originally Posted by jammie View Post
    Your welcome Lee,

    Glad to be of help. I learned a bit more about Set and Setq myself from this post

    Nice work with the routine as well

    -Jammie
    Cheers Jammie
    Lee Mac Programming

    With Mathematics there is the possibility of perfect rigour, so why settle for less?

    Just another Swamper

  8. #8
    Senior Member
    Computer Details
    StevJ's Computer Details
    Operating System:
    Xp Pro
    Using
    AutoCAD 2006
    Join Date
    Sep 2008
    Location
    Bremerton, Wa
    Posts
    100

    Default

    That's a really nice program, Lee, but in order for a leading zero to be retained, I have to make it the prefix, or include it as part of the prefix. Is there a way around this characteristic of the program? Prefix VB and number 0801 becomes VB801 unless I make the prefix VB0.

    I ask because you have made the program easy to modify, so that if I don't need a prefix or suffix, those lines can be commented out, and they will not be a bother. But until 2010, I could sure use a leading zero.

    Thanks,
    Steve

  9. #9
    Quantum Mechanic Lee Mac's Avatar
    Computer Details
    Lee Mac's Computer Details
    Operating System:
    Windows 7 Ultimate (32-bit)
    Discipline
    Multi-disciplinary
    Lee Mac's Discipline Details
    Discipline
    Multi-disciplinary
    Details
    Custom Programming / Software Customisation
    Using
    AutoCAD 2013
    Join Date
    Aug 2008
    Location
    London, England
    Posts
    15,708

    Default

    Well, this is a quick fix, but not ideal

    Code:
    ;; ============ Num.lsp ===============
    ;;
    ;;  FUNCTION:
    ;;  Will sequentially place numerical
    ;;  text upon mouse click, with optional
    ;;  prefix and suffix.
    ;;
    ;;  SYNTAX: num
    ;;
    ;;  AUTHOR:
    ;;  Copyright (c) 2009, Lee McDonnell
    ;;  (Contact Lee Mac, CADTutor.net)
    ;;
    ;;  PLATFORMS:
    ;;  No Restrictions,
    ;;  only tested in ACAD 2004.
    ;;
    ;;  VERSION:
    ;;  1.0  ~  05.04.2009
    ;;
    ;; ====================================
    
    
    (defun c:num  (/ vlst ovar dVars tmpVars pt)
      (vl-load-com)
    
      (setq Zer0 T)   ; Leading Zero (T or nil)
      
      (setq    vlst '("OSMODE" "CLAYER")
        ovar (mapcar 'getvar vlst))
      (setvar "OSMODE" 0)
      (or (tblsearch "LAYER" "NumText")
          (vla-put-color
        (vla-add
          (vla-get-layers
            (vla-get-ActiveDocument
              (vlax-get-acad-object))) "NumText") acYellow))
      (setq dVars '(sNum inNum Pref Suff))
      (mapcar '(lambda (x y) (or (boundp x) (set x y))) dVars '(1 1 "" ""))
      (setq tmpVars (list (getreal (strcat "\nSpecify Starting Number <" (rtos sNum 2 2) ">: "))
                  (getreal (strcat "\nSpecify Increment <" (rtos inNum 2 2) ">: "))
                  (getstring (strcat "\nSpecify Prefix <" (if (eq "" Pref) "-None-" Pref) ">: "))
                  (getstring (strcat "\nSpecify Suffix <" (if (eq "" Suff) "-None-" Suff) ">: "))))
      (mapcar '(lambda (x y) (or (or (not x) (eq "" x)) (set y x))) tmpVars dVars)
      (while (setq pt (getpoint "\nClick for Text... "))
        (Make_Text pt (strcat Pref (if Zer0 "0" "") (rtos sNum 2 2) Suff))
        (setq sNum (+ sNum inNum)))
      (mapcar 'setvar vlst ovar)
      (princ))
    
    (defun Make_Text  (txt_pt txt_val)
      (entmake (list '(0 . "TEXT")
             '(8 . "NumText")
             (cons 10 txt_pt)
             (cons 40 (max 2.5 (getvar "TEXTSIZE")))
             (cons 1 txt_val)
             '(50 . 0.0)
             (cons 7 (getvar "TEXTSTYLE"))
             '(71 . 0)
             '(72 . 1)
             '(73 . 2)
             (cons 11 txt_pt))))
    Lee Mac Programming

    With Mathematics there is the possibility of perfect rigour, so why settle for less?

    Just another Swamper

  10. #10
    Senior Member
    Computer Details
    StevJ's Computer Details
    Operating System:
    Xp Pro
    Using
    AutoCAD 2006
    Join Date
    Sep 2008
    Location
    Bremerton, Wa
    Posts
    100

    Default

    Registered forum members do not see this ad.

    That did it. Thanks, Lee.

    Steve

Similar Threads

  1. Running a lisp in another lisp??
    By neekcotrack in forum AutoLISP, Visual LISP & DCL
    Replies: 3
    Last Post: 26th Aug 2008, 04:02 am
  2. Lisp Call Lisp Problem
    By neekcotrack in forum AutoLISP, Visual LISP & DCL
    Replies: 1
    Last Post: 23rd Aug 2008, 12:56 pm
  3. problem, trying to running a list of lisp from within a lisp
    By twind2000 in forum AutoLISP, Visual LISP & DCL
    Replies: 4
    Last Post: 20th Aug 2007, 04:27 pm
  4. calling another lisp from within my lisp
    By thalon in forum AutoLISP, Visual LISP & DCL
    Replies: 2
    Last Post: 22nd Feb 2006, 09:56 pm

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts