Author Topic: Setting variable based on arguments in list  (Read 2844 times)

0 Members and 1 Guest are viewing this topic.

SPDCad

  • Bull Frog
  • Posts: 453
Setting variable based on arguments in list
« on: June 01, 2005, 02:31:40 PM »
Is it possible to set a list of values to variables when the number of values in the list may change.

example

Given list A = ( 0 1 2 3 4 5 6) has 7 arguments
Set A= 0, B= 1, C=2…etc

Given list B= (0 1 2 3 4) has 5 arguments
Setq A=0,b=1,c=2…etc.

The reason why I am asking is for system variable programme I am writing where I don’t always need to set the system variable to 0.  I usually set “cmdecho” off, blipmode “off”,  ‘Osmode’ to 0, as well as others, but I don’t always need ‘Osmode’ set to 0 as well as other system variables. So when I  don’t need it set to zero I want to exclude it from my list.
So say (SET_VAR LST) would be the programme I would use and the number of variable I would need would vary based on the number of arguments in the list.

I hope I explained what i am asking well enough.
Any help would be greatly appreciated.
Thanks
SPD
AutoCAD 2010, w/ OpenDCL

visit: http://reachme.at/spd_designs

JohnK

  • Administrator
  • Seagull
  • Posts: 10652
Setting variable based on arguments in list
« Reply #1 on: June 01, 2005, 02:43:51 PM »
Im not sure I follow your question but I think I understand the overall requirments.

I had a situation where I needed to be sure the users osnaps were off so my solution to this was to develop smarter tools to do the thinking for me. (I just knew I wanted my snaps off at a certian point and I wanted them back on at another so I created this procedure.)

I think you can use this to ensure that the users snaps are on when they are suposed to be on and off when they are suposed to be off.

                                                                                 
Code: [Select]

;;;===================================================================;
;;; SetOsnaps                                                         ;
;;;-------------------------------------------------------------------;
;;; This function accepts a integer of 1 or 0 (on or off) to set the  ;
;;; end users osnap value to enabled or disabled.                     ;
;;;                                                                   ;
;;; Argument: 1 = Enable the users osnaps                             ;
;;;           0 = Disable the users osnaps                            ;
;;;                                                                   ;
;;; Usage: (SetOsnaps 1) or (SetOsnaps 0)                             ;
;;;                                                                   ;
;;; Author: John Kaul                                                 ;
;;;===================================================================;
(defun SetOsnaps (value)
  (cond
    ((= value 1)
     (if
       (>= (getvar "osmode") 16383)
       (setvar "osmode" (boole 6 (getvar "osmode") 16384))
       )
     )
    ((=  value 0)
     (if
       (<= (getvar "osmode") 16383)
       (setvar "osmode" (boole 6 (getvar "osmode") 16384))
       )
     )
    )
  (princ)
)



Here is an example
Code: [Select]
(defun c:myline ()
  (SetOsnaps 0)
  ;; I do NOT want snaps enabled
  (command "line")
  )


So I guess my solution is to develop smarter tools to accompany your procedures.
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

Mark

  • Custom Title
  • Seagull
  • Posts: 28762
Setting variable based on arguments in list
« Reply #2 on: June 01, 2005, 03:06:57 PM »
A little confused myself.

Let me just through this out there for the sake of conversation. :)

Code: [Select]

  (setq lst '(0 1 2 3 4 5))
  (setq vars '(a b c d e f g))
 
  (setq cntr 0)
 
  (foreach v vars
(set v (nth cntr lst))
(setq cntr (1+ cntr))
)

TheSwamp.org  (serving the CAD community since 2003)

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Setting variable based on arguments in list
« Reply #3 on: June 01, 2005, 03:12:51 PM »
Perhaps this. The post is long but the concept simple.
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

whdjr

  • Guest
Setting variable based on arguments in list
« Reply #4 on: June 01, 2005, 03:18:36 PM »
Sort of elaborating on Mark's post you could 'increment' the variables using their ascii values.

Code: [Select]
(setq lst '(0 1 2 3 4 5))

(setq cntr 65)

(foreach item lst (set (read (chr cntr)) item) (setq cntr (1+ cntr)))

SPDCad

  • Bull Frog
  • Posts: 453
Setting variable based on arguments in list
« Reply #5 on: June 01, 2005, 04:33:41 PM »
Maybe a little pseudo code will help explain my problem better.

Code: [Select]
Input SET_VAR (VARIABLES VALUES)
set NUM = length VARIABLES
set     C = 1
set     D =  "1"

repeat NUM
set A = strcat “A” D
set C = + 1 C
        set D = itoa C
Here is where my problem lies
set the value A =  variable value of the variable listed in the Variable list
ie. A1 = osmode value
    A2 = cmdecho value
);repeat

What I am looking for is similar to a pointer from the C language.

Hope this explains my problem a little more.
AutoCAD 2010, w/ OpenDCL

visit: http://reachme.at/spd_designs

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Setting variable based on arguments in list
« Reply #6 on: June 01, 2005, 04:50:50 PM »
Sorry SPD but you're not providing very clear details (to me anyway).

What you seem to be indicating is indirect addressing, and there's been a few examples provided in this thread.

A simple example: (mapcar 'set '(a b c) '(1 2 3)).

Note that (mapcar 'set '(a b c) '(1 2 3 4 5)) works without modification too; this is standard mapcar behavior.

Providing the exact data you intend to pass in the arguments VARIABLES and VALUES may be illuminating too.

BTW, did you check the link I provided earlier?

(Sorry if I sound a bit terse; kinda bagged this afternoon).

Cheers.
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst