+ Reply to Thread
Results 1 to 6 of 6
  1. #1
    Forum Newbie
    Using
    AutoCAD 2006
    Join Date
    Nov 2007
    Posts
    3

    Question How to make vlisp wait for autocad to draw

    Registered forum members do not see this ad.

    I'm trying to write an simple function in vlisp to make a number of (22) boxes with a certain space in between, the code runs as follows:

    Code:
    (defun C:test ()
      (setq mensur 360)
      (setq hal_bredd 8)
      (setq nyckel_langd 90)
      (setq antal 22)
      (setq loop 0)
      (setq langd 0)
    
    
      (while (< loop antal)
        (setq loop (1+ loop))
        (if (> loop 5) (setq hal_bredd 7))
        (if (> loop 10) (setq hal_bredd 6))
        (if (> loop 13) (setq hal_bredd 5))
        (if (> loop 16) (setq hal_bredd 4))
        
        
        
        (setq langd (+ langd (/ (- mensur langd) 17.817)))
        (setq start (list (- 0 (+ langd (/ hal_bredd 2))) (- 0 (/ nyckel_langd 2))))
        (setq slut (list (- 0 (- langd (/ hal_bredd 2))) (/ nyckel_langd 2)))
        (command "_.box" start slut)
      )
    )
    The problem is that it seemes like vlisp does not wait for autocad to draw the first box before it sends the command to draw the second and so on, the sizes and positions of the boxes ends up different and randomized every time. Is there some way to make vlisp wait for autocad to draw the box before telling it to draw the next one?

    I know that command is'nt the best way to draw with vlisp but if I can get away with it I would be glad since this is a one time function, but any solution is welcome.

  2. #2
    Super Moderator fuccaro's Avatar
    Using
    AutoCAD 2006
    Join Date
    Nov 2002
    Location
    Romania, Marosvasarhely
    Posts
    3,543

    Default

    Welcome Tirithen!
    I don't have AutoCAD here.
    I see you use the COMMAND function to draw the boxes, so you could use the CMDACTIVE sysvar to pause the code. After the COMMANND "BOX"... I would include a loop to be repeated until the mentioned sysvar becomes nil.
    This is the answer to your question to make lisp to wait AutoCAD. But firstly I would run again the code but with OSNAP turned off. Well, just my try.
    It's nice to be nice, but sometimes is nicer to be evil!.
    Tip: Please do not PM or email me with CAD questions - use the forums, you'll get an answer sooner.

  3. #3
    Senior Member devitg's Avatar
    Computer Details
    devitg's Computer Details
    Operating System:
    XP
    Monitor:
    VG2021WM VIEW SONIC
    Using
    AutoCAD 2008
    Join Date
    Apr 2005
    Location
    CORDOBA ARGENTINA
    Posts
    107

    Default slow dwg or not , that is the question

    The box command need at least 3 data , you provide only 2 START and SLUT , you need the third value for the height.

    I add the way to set osmode to 0 , or NON , and to reset it as prevous to the lisp, and add the 5 as height.

    I do not know if it is what do you want to do.

    (defun C:slow-dwg ()
    (setq mensur 360)
    (setq hal_bredd 8 )
    (setq nyckel_langd 90)
    (setq antal 22)
    (setq loop 0)
    (setq langd 0)
    (setq old-osmode(getvar "osmode" ))
    (setvar "osmode" 0)

    (while (< loop antal)
    (setq loop (1+ loop))
    (if (> loop 5) (setq hal_bredd 7))
    (if (> loop 10) (setq hal_bredd 6))
    (if (> loop 13) (setq hal_bredd 5))
    (if (> loop 16) (setq hal_bredd 4))



    (setq langd (+ langd (/ (- mensur langd) 17.817)))
    (setq start (list (- 0 (+ langd (/ hal_bredd 2))) (- 0 (/ nyckel_langd 2))))
    (setq slut (list (- 0 (- langd (/ hal_bredd 2))) (/ nyckel_langd 2)))
    (command "_.box" start slut 5.0 )
    )

    (setvar "osmode" old-osmode)
    )
    Attached Files

  4. #4
    Forum Newbie
    Using
    AutoCAD 2006
    Join Date
    Nov 2007
    Posts
    3

    Default

    Thanks for the welcome! :-)
    Yes I see that now, I've mixed my tries up but I did try with three cordinates an other time, have been trying to solve this for some houres so I mixed them up... But thanks, I'll try CMDACTIVE seemes to be exactly the thing that I was looking for. I'll try to learn about ActiveX later, it's a lot faster right? For this drawing command will be fine, thanks again for the help. :-)

  5. #5
    Forum Newbie
    Using
    AutoCAD 2006
    Join Date
    Nov 2007
    Posts
    3

    Default

    Thanks for the help both of you, I got it working with the osmode var, now I can finally get to work with my drawing.


    Code:
    (defun C:nyckelhal_uppe ()
      (setq mensur 360)
      (setq    hal_bredd 8)
      (setq    nyckel_langd 90)
      (setq antal 22)
      (setq loop 0)
      (setq langd 0)
      (setq old-osmode(getvar "osmode" ))
      (setvar "osmode" 0)
    
      (while (< loop antal)
        (setq loop (1+ loop))
        (if (> loop 5) (setq hal_bredd 7))
        (if (> loop 10) (setq hal_bredd 6))
        (if (> loop 13) (setq hal_bredd 5))
        (if (> loop 16) (setq hal_bredd 4))
        
        (setq langd (+ langd (/ (- mensur langd) 17.817)))
        (setq start (list (- 0 (/ nyckel_langd 2)) 25 (+ langd (/ hal_bredd 2))))
        (setq slut (list (/ nyckel_langd 2) 30 (- langd (/ hal_bredd 2))))
    
        (command "_.box" start slut)
      );while
      (setvar "osmode" old-osmode)
    )
    
    (defun C:nyckelhal_nere ()
      (setq mensur 360)
      (setq    hal_bredd 8)
      (setq    nyckel_langd 90)
      (setq antal 22)
      (setq loop 0)
      (setq langd 0)
      (setq old-osmode(getvar "osmode" ))
      (setvar "osmode" 0)
    
      (while (< loop antal)
        (setq loop (1+ loop))
        (if (> loop 5) (setq hal_bredd 7))
        (if (> loop 10) (setq hal_bredd 6))
        (if (> loop 13) (setq hal_bredd 5))
        (if (> loop 16) (setq hal_bredd 4))
        
        (setq langd (+ langd (/ (- mensur langd) 17.817)))
        (setq start (list (- 0 (/ nyckel_langd 2)) 15 (+ langd (/ hal_bredd 2))))
        (setq slut (list (/ nyckel_langd 2) 20 (- langd (/ hal_bredd 2))))
    
        (command "_.box" start slut)
      );while
      (setvar "osmode" old-osmode)
    )

  6. #6
    Senior Member devitg's Avatar
    Computer Details
    devitg's Computer Details
    Operating System:
    XP
    Monitor:
    VG2021WM VIEW SONIC
    Using
    AutoCAD 2008
    Join Date
    Apr 2005
    Location
    CORDOBA ARGENTINA
    Posts
    107

    Default

    Registered forum members do not see this ad.

    I learn a new one today , to make a box but 2 points , the 3 d point is need if the 2 first are on the same plane parallel to the wcs .

Similar Threads

  1. script LISP input won't wait
    By dkallberg in forum AutoCAD Beginners' Area
    Replies: 6
    Last Post: 31st Aug 2007, 04:25 pm
  2. VLISP in AutoCAD 2000
    By pefi in forum AutoLISP, Visual LISP & DCL
    Replies: 2
    Last Post: 17th Jul 2007, 02:08 pm
  3. ... make a layer to always draw...
    By erona in forum AutoCAD General
    Replies: 11
    Last Post: 5th Mar 2007, 06:27 am
  4. To Vista Now or Wait
    By HyperPics in forum AutoCAD RSS Feeds
    Replies: 0
    Last Post: 29th Jan 2007, 07:00 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