+ Reply to Thread
Page 1 of 2 1 2 LastLast
Results 1 to 10 of 16
  1. #1
    Super Member
    Using
    AutoCAD 2010
    Join Date
    Dec 2010
    Posts
    643

    Default ABC's of Autolisp by George Omura : Data type convertion is needed

    Registered forum members do not see this ad.

    hi
    its my first day in "ABC's of Autolisp by George Omura" class. i tried to use this code but its not working. im sure its data type mismatch.

    i simply want to program to draw a line from pt1 to pt2

    Code:
    (defun C:test()
      (setq pt1 (list (getpoint)))
      (setq pt2 (list (getpoint)))
      (command "Line" pt1 pt2)
      
        );end defun
    Thanks

  2. #2
    Super Member
    Using
    AutoCAD 2010
    Join Date
    Dec 2010
    Posts
    643

    Default

    why i cant use the CAR and CADR functions to retrieve list component obtained with getpoint function?

  3. #3
    Senior Member GP_'s Avatar
    Using
    AutoCAD 2014
    Join Date
    Oct 2010
    Location
    Vercelli, Italy
    Posts
    244

    Default

    Code:
    (defun C:test()
      (setq pt1 (getpoint))
      (setq pt2 (getpoint))
      (command "Line" pt1 pt2 "")
     
    );end defun

  4. #4
    Super Member
    Using
    AutoCAD 2010
    Join Date
    Dec 2010
    Posts
    643

    Default

    thanks GP

    hy i cant use the CAR and CADR functions to retrieve list component obtained with getpoint function?

  5. #5
    Forum Deity BlackBox's Avatar
    Computer Details
    BlackBox's Computer Details
    Operating System:
    Windows 8.1 Professional, Server 2012 R2 Datacenter
    Computer:
    Dell Precision T3600
    CPU:
    Hex-Core Intel Xeon 3.2Ghz
    RAM:
    32GB
    Graphics:
    3GB NVIDIA Quadro K4000
    Primary Storage:
    256GB SSD
    Secondary Storage:
    1TB Western Digital VelociRaptor 10K RPM
    Monitor:
    Dual 24" Dell Ultrasharp Widescreen Monitors
    Using
    Civil 3D 2015
    Join Date
    Nov 2009
    Posts
    4,604

    Default

    You could just incorporate the pause function:

    Code:
    (defun c:TEST ()
      (command "._line" pause pause "")
      (princ)
    )
    ... But this may cause undesired behavior following a right click being entered in lieu of a point specification. This adaptation is a bit less prone to this undesired behavior:

    Code:
    (defun c:TEST ()
      (command "._line")
      (princ)
    )
    ... If the requirement is to use two variables, then consider using local in lieu of global variables, and avoid potential errors in the Command call by using an If statement:

    Code:
    (defun c:TEST (/ point1 point2)
      (if (and (setq point1 (getpoint "\nSpecify start point: "))
               (not (initget 32))
               (setq point2 (getpoint point1 "\nSpecify end point: "))
          )
        (command "._line" point1 point2 "")
        (prompt "\n** Invalid point ** ")
      )
      (princ)
    )
    "Potential has a shelf life." - Margaret Atwood

    Autodesk Exchange Apps
    ~ Autoloader ~ AutoCAD Security

  6. #6
    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
    16,763

    Default

    Quote Originally Posted by samifox View Post
    [w]hy i cant use the CAR and CADR functions to retrieve list component obtained with getpoint function?
    Here is an example to consider:
    Code:
    (defun c:getpt ( / pt )
        (if (setq pt (getpoint "\nPick a point, any point: "))
            (princ
                (strcat
                    "\nX = " (rtos (car pt))
                    "\nY = " (rtos (cadr pt))
                    "\nZ = " (rtos (caddr pt))
                )
            )
        )
        (princ)
    )
    Lee Mac ProgrammingTwitterExchange App StoreDropbox (500MB free)

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

  7. #7
    Super Member
    Using
    AutoCAD 2010
    Join Date
    Dec 2010
    Posts
    643

    Default

    i saw some using command "LINE","._LINE" what is the difference? when you say "IF" and "AND" ,logically is like making nested IF expressions. right?

  8. #8
    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
    16,763

    Default

    Quote Originally Posted by samifox View Post
    i saw some using command "LINE","._LINE" what is the difference?
    See here:
    http://www.cadforum.cz/cadforum_en/qaID.asp?tip=2425
    Lee Mac ProgrammingTwitterExchange App StoreDropbox (500MB free)

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

  9. #9
    Forum Deity BlackBox's Avatar
    Computer Details
    BlackBox's Computer Details
    Operating System:
    Windows 8.1 Professional, Server 2012 R2 Datacenter
    Computer:
    Dell Precision T3600
    CPU:
    Hex-Core Intel Xeon 3.2Ghz
    RAM:
    32GB
    Graphics:
    3GB NVIDIA Quadro K4000
    Primary Storage:
    256GB SSD
    Secondary Storage:
    1TB Western Digital VelociRaptor 10K RPM
    Monitor:
    Dual 24" Dell Ultrasharp Widescreen Monitors
    Using
    Civil 3D 2015
    Join Date
    Nov 2009
    Posts
    4,604

    Default

    Quote Originally Posted by samifox View Post
    ... when you say "IF" and "AND" ,logically is like making nested IF expressions. right?
    In your original code in the OP, were you to right click instead of select the second point (for example), you would experience undesired behavior.

    In this circumstance, the If statement is testing for the two valid points needed to supply the following Command call the arguments need to complete the command successfully.

    The And statement simply allows for more than one non-Nil returned value to be required, in this case being point1, and point2 local variables, in order for the If statement's test expression to pass.
    "Potential has a shelf life." - Margaret Atwood

    Autodesk Exchange Apps
    ~ Autoloader ~ AutoCAD Security

  10. #10
    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
    16,763

    Default

    Registered forum members do not see this ad.

    In addition to BlackBox's explanation:

    Quote Originally Posted by samifox View Post
    When you say "IF" and "AND", logically is like making nested IF expressions. right?
    Correct, the following expression...
    Code:
    (if
        (and
            <test-expression-1>
            <test-expression-2>
            <test-expression-3>
        )
        <then-expression-1>
        <else-expression-1>
    )
    ...could alternatively be written:
    Code:
    (if <test-expression-1>
        (if <test-expression-2>
            (if <test-expression-3>
                <then-expression-1>
                <else-expression-1>
            )
            <else-expression-2>
        )
        <else-expression-3>
    )
    Here, each nested if statement forms the then-expression for the previous if statment.

    Though, where additional else-expressions are not required, I'm sure that most would agree that the use of an and statement is far more readable and concise than multiple nested if statements.
    Lee Mac ProgrammingTwitterExchange App StoreDropbox (500MB free)

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

Similar Threads

  1. sample files from George Omura Mastering AutoCAD 2010
    By Klariya in forum AutoCAD 2D Drafting, Object Properties & Interface
    Replies: 32
    Last Post: 29th Sep 2012, 12:56 pm
  2. Novedge interviews George Omura, the most popular AutoCAD writer
    By folini in forum AutoCAD Drawing Management & Output
    Replies: 0
    Last Post: 19th Sep 2007, 04:19 pm
  3. George Omura Releases Another Great AutoCAD Book
    By Between the Lines in forum AutoCAD RSS Feeds
    Replies: 0
    Last Post: 5th Sep 2006, 01:43 pm
  4. Ellen Finklestein vs. George Omura.
    By Cadastrophic in forum AutoCAD Drawing Management & Output
    Replies: 2
    Last Post: 3rd Apr 2005, 04:15 pm
  5. Replies: 0
    Last Post: 17th Feb 2003, 10:49 am

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