Jump to content

Recommended Posts

Posted

I have a lisp (see below) that I'm writing to create a Revision Status of Sheets block on the front sheet of our drawings. It's supposed to be a long rectangle separated by vertical lines spaced equally 0.4" apart over a length determined by how many sheets are in the drawing. A horizontal line is also created dividing the block into two halves. The issue I'm having concerns the code that creates the vertical lines that are drawn to divide the block into equally spaced blocks. As part of the overall code it doesn't work and this is the result:

revsh1.jpg

 

Though you can't see it in the picture, this drawing has 11 sheets and 11 vertical lines are indeed drawn by the code. 3 are drawn at the end, 6 are drawn in the middle and 2 are drawn at the beginning :?

 

Yet if I enter the code line by line (only the bottom portion of the code) into AutoCAD then it works like I thought it would:

revsh2.jpg

 

Can anyone help me figure out what's wrong with my code? Thanks.

 

Lonnie

 

P.S. - I'm still learning so I know there are probably a thousand better ways to do what I'm doing but in an effort to learn I would appreciate tips on what's wrong with my code. Of course if you want to share your own code to do the same thing then I want to see it. Coding is about logic and I need to figure out what's wrong with mine so I can correct my thinking. Thanks again.

 

(defun c:revsh (/   n     linelength  ln1pt1
 ln1pt2x   ln1pt2y   ln1pt2    ln2pt1 ln2pt2x
 ln2pt2y   ln2pt2    ln3pt1    ln3pt2x ln3pt2y
 ln3pt2    k         x         ptx       pty
 ptz       lnpt1     lnpt2
       )

 ;; Draw bottom line
 (setq n (length (layoutlist)))
 (setq linelength (* n 0.4))
 (setq ln1pt1 "37.75,11,0")
 (setq ln1pt2x (- 37.75 linelength))
 (setq ln1pt2y "11")
 (setq ln1pt2 (strcat (rtos ln1pt2x 2 2) "," ln1pt2y ",0"))
 (command "line" ln1pt1 ln1pt2 "")

 ;; Draw top line
 (setq ln2pt1 "37.75,12,0")
 (setq ln2pt2x (- 37.75 linelength))
 (setq ln2pt2y "12")
 (setq ln2pt2 (strcat (rtos ln2pt2x 2 2) "," ln2pt2y ",0"))
 (command "line" ln2pt1 ln2pt2 "")

 ;; Draw middle line
 (setq ln3pt1 "37.75,11.5,0")
 (setq ln3pt2x (- 37.75 linelength))
 (setq ln3pt2y "11.5")
 (setq ln3pt2 (strcat (rtos ln3pt2x 2 2) "," ln3pt2y ",0"))
 (command "line" ln3pt1 ln3pt2 "")

 ;; Draw sheet separators
 (setq k 0)
 (setq k (length (layoutlist)))
 (setq x 1)
 (repeat k
   (setq ptx (- 37.75 (* x 0.4)))
   (setq pty 11)
   (setq ptz 12)
   (setq lnpt1 (strcat (rtos ptx 2 2) "," (rtos pty 2 2) ",0"))
   (setq lnpt2 (strcat (rtos ptx 2 2) "," (rtos ptz 2 2) ",0"))
   (command "line" lnpt1 lnpt2 "")
   (setq x (1+ x))
 )
)

Posted

First, you will need to disable auto-OSNAP by setting OSMODE variable to 0 - it is a good ideea to store his current state into a variable to restore it at end:

(setq MyOldOsmode (getvar "OSMODE"))       ;store current state
(setq "OSMODE" 0)                          ;disable
;;; your draw code goes here
(setvar  "OSMODE" MyOldOsmode)             ;restore previus state

By doing this will prevent entites added using COMMAND statement to colapse to nearest OSNAP points.

 

Regards,

Posted

Second, will be more effective to construct your points as lists instead of strings:

(setq n          (length (layoutlist)))
(setq linelength (* n 0.4))
(setq ln1pt1     '(37.75 11.0 0.0))
(setq ln1pt2x    (- 37.75 linelength))
(setq ln1pt2y    11.0)
(setq ln1pt2     (list ln1pt2x ln1pt2y 0.0))

(command "line" ln1pt1 ln1pt2 "")

 

 

Regards

Posted

Another suggestion is to comment out the local variables during design time in order to be able to list their values for debug.

 

Regards,

Posted

Setting OSMODE to 0 did the trick. I have seen this practice in much of the code I've seen I just needed to be affected by it to really understand it.

 

As for your other suggestions, especially about making my points into lists instead of strings, thanks a lot! Being a novice I'm not forward thinking too much and most of the time I'm still doing things the most basic way (and you can tell from my code :oops: ), lol. Thanks again.

 

Lonnie

Posted

You're welcome! Good luck with your learning!

 

Please take a look to POLAR function - it will help you a lot to calculate displacements from a given point when you know the size and direction (angle) of displacement.

This way the above excerpt will become:

 (setq n          (length (layoutlist)))
(setq linelength (* n 0.4))
(setq ln1pt1     '(37.75 11.0 0.0))
(setq ln1pt2     (polar ln1pt1 pi linelength))

(command "line" ln1pt1 ln1pt2 "")

 

 

Regards,

Posted

I actually tried to do that first but I really got no where and I'm sure it's do to the same problem I mention above about being too basic with my code. Here's what I had before:

(setq ptx (- 37.75 (* n 0.4)))
(setq pty 11)
(setq lnpt1 (ptx pty))
(setq lnpt2 (polar (lnpt1) 90 1))

Posted

Some corrections:

 

  1. To construct the point use LIST function - in fact a point is a list of 2 or 3 reals.
  2. The point used as argument for POLAR don't need to be surrounded by parenthesis.
  3. The angle for POLAR statement MUST be in radians not in decimal degrees.

 

(setq ptx (- 37.75 (* n 0.4)))
(setq pty 11)
(setq lnpt1 ([color=Red]list[/color] ptx pty))
(setq lnpt2 (polar [color=Red]lnpt1[/color] [color=Red](* 0.5 [/color][color=Red]pi)[/color] 1))

Regards,

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...