Results 1 to 8 of 8

Thread: Divide the value stored in system variable Distance

  1. #1
    Member
    Join Date
    2004-03
    Location
    Holly, Michigan
    Posts
    39

    Question Divide the value stored in system variable Distance

    I am writing a LISP code to give me the distance in decimal feet. Here is what I have so far:

    Code:
     
    ;gives distance in decimal feet
    
    (defun C:FE ()
    (command "-units" "2" "3" "1" "3" "0.000" "n")
    (command "DIST" pause pause)
    (setq convert 12)
    (/ DISTANCE convert)
    (princ)
    )
    The problem is in the division of the distance variable. When the distance command is used, it stores a read-only variable called "DISTANCE". All I want to do is divde this variable by 12 to give me feet. I am setting up a "convert" variable because I thought that AutoLISP wouldn't let me divde the variable DISTANCE by the number twelve directly, as in:

    Code:
    (/ DISTANCE 12)
    I would appreciate any responses to this problem.

    Blaine

  2. #2
    All AUGI, all the time CAB2k's Avatar
    Join Date
    2002-12
    Location
    Brandon, Florida
    Posts
    687

    Default Re: Divide the value stored in system variable Distance

    Try this:
    Code:
    (defun c:test (/ dec decft)
      (setq des (getdist "\nEnter or pick your distance."))
      (setq decft (/ des 12.0))
      (print decft)
      (princ)
    )

  3. #3
    Member
    Join Date
    2004-03
    Location
    Holly, Michigan
    Posts
    39

    Question Re: Divide the value stored in system variable Distance

    That worked. Thanks! However, I would like to know why what I had did not work. If I am going to learn AutoLISP, I need to be able to understand why what I had did not work.

    Also, I believe that I am correct in my understanding that the portion of code after the defun is defining the local variables, but I don't understand why that is important or needed.

    Thanks,

    Blaine

  4. #4
    Administrator Opie's Avatar
    Join Date
    2002-01
    Location
    jUSt Here (a lot)
    Posts
    6,836

    Default Re: Divide the value stored in system variable Distance

    Quote Originally Posted by blaine.67000
    That worked. Thanks! However, I would like to know why what I had did not work. If I am going to learn AutoLISP, I need to be able to understand why what I had did not work.

    Also, I believe that I am correct in my understanding that the portion of code after the defun is defining the local variables, but I don't understand why that is important or needed.

    Thanks,

    Blaine
    Are you referring to the DISTANCE system variable? You would need to get the value of the variable first before placing it within a function.
    Code:
    (/ (getvar "DISTANCE") 12)
    If you have a technical question, please find the appropriate forum and ask it there.
    You will get a quicker response from your fellow AUGI members than if you sent it to me via a PM or email.
    jUSt

  5. #5
    Member
    Join Date
    2004-03
    Location
    Holly, Michigan
    Posts
    39

    Default Re: Divide the value stored in system variable Distance

    Quote Originally Posted by Opie

    Are you referring to the DISTANCE system variable? You would need to get the value of the variable first before placing it within a function.
    Yes, I am. And putting in the getvar function to retreive the DISTANCE system variable makes sense......I think.
    Last edited by blaine.67000; 2006-06-22 at 04:48 PM.

  6. #6
    Administrator Opie's Avatar
    Join Date
    2002-01
    Location
    jUSt Here (a lot)
    Posts
    6,836

    Default Re: Divide the value stored in system variable Distance

    Quote Originally Posted by blaine.67000
    Yes, I am. And putting in the getvar function to retreive the DISTANCE system variable makes sense......I think.
    You would need to do this with any system variables.
    If you have a technical question, please find the appropriate forum and ask it there.
    You will get a quicker response from your fellow AUGI members than if you sent it to me via a PM or email.
    jUSt

  7. #7
    Member
    Join Date
    2004-03
    Location
    Holly, Michigan
    Posts
    39

    Default Re: Divide the value stored in system variable Distance

    Quote Originally Posted by blaine.67000
    Also, I believe that I am correct in my understanding that the portion of code after the defun is defining the local variables, but I don't understand why that is important or needed.
    Opie,

    Can you comment on my above question regarding local variables.

    Thanks,

    Blaine

  8. #8
    Administrator Opie's Avatar
    Join Date
    2002-01
    Location
    jUSt Here (a lot)
    Posts
    6,836

    Default Re: Divide the value stored in system variable Distance

    Quote Originally Posted by blaine.67000
    Opie,

    Can you comment on my above question regarding local variables.

    Thanks,

    Blaine
    See this post. I know it doesn't relate to this actual routine, but it does explain the local variables a little.
    If you have a technical question, please find the appropriate forum and ask it there.
    You will get a quicker response from your fellow AUGI members than if you sent it to me via a PM or email.
    jUSt

Similar Threads

  1. 2011: Undocumented System Variable Value
    By BeKirra in forum AutoCAD General
    Replies: 4
    Last Post: 2011-01-29, 04:08 PM
  2. Distance System Crash
    By revacservice in forum AutoCAD General
    Replies: 5
    Last Post: 2009-06-22, 01:30 PM
  3. System Variable User?
    By SRBalliet in forum AutoCAD General
    Replies: 2
    Last Post: 2008-05-02, 01:01 PM
  4. System Variable Reactor
    By pnorman in forum AutoLISP
    Replies: 2
    Last Post: 2005-04-12, 03:54 AM

Posting Permissions

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