Jump to content

Begining & End of Line


Bill Tillman

Recommended Posts

I've been using code almost identical to this for some tasks which automate the insertion of blocks for pickets on handrails. It works well with a few exceptions. I modified slightly to insert a block which is a plan view of the handrail posts. Basically, I draw a line which represents the centerline of the rail and it places the posts along the length and equal spacing. Saves loads of time. What I've noticed is that when it runs and asks the user to select the line (the lines must be vertical or horizontal, I'll get skewed lines working with it later) if I select a point on the left side of a horizontal line or the top part of a vertical line it works perfect. If however, I select a point to the right of the midpoint of a horizontal line or below the midpoint of a vertical line it works but it doesn't insert the blocks correctly. Okay,  no big deal, I'm the only one using this code for the moment so I can just work around this. I've also noticed that I can run it once, erase the blocks which were inserted and modify the line by stretching or shortening it and everything goes south. And by that I mean a horizontal line ends up placing the blocks in a vertical space, not horizontal. I think this has to do with my logic which decides if the line is horizontal or vertical. I also know there is a more efficient way of doing this but that comes later once I've worked out the other bugs. If anyone can examine this and let me know what might be the issue... I think it has something to do with the line being modified which causes the endpoints to be changed to something I'm not following just yet. And of course, as soon as I try to work with this, the mean old boss comes in to spy on my progress and he hates LISP and doesn't want us using it for anything on his computers, so I have to work this from home.


(vl-load-com)

(defun c:rlayout ()

  (defun *error* ( m )
    (and vars (mapcar 'setvar '(osmode pickbox) vars))
    (princ m) (princ)
  )
  
  (setq vars (mapcar 'getvar '(osmode pickbox))
    impmet 1  ;;; change this for Imperial or Metric - 1=Imperial, 2.54=cm 25.4=mm, etc...
    picketthk (* impmet 1.)
    )

  (setq a90 (dtr 90.)
            a270 (dtr 270.)
    )

  (setq msg "\nSelect a line : ")
  (leftside msg)

  ;;; CHECK FOR HORIZONTAL OR VERTICAL LINE
  (if (= (cadr pt1) (cadr pt2))
    (dohorizontal)
    (dovertical)
    )  

 

  ;;; Reset environment variables
  (mapcar 'setvar '(osmode pickbox) vars)

  (princ)
  )

(defun dohorizontal (/ count)

  (setq count 0
    maxoc 51.
    numcores (+ 2 (fix (/ (distance pt1 pt2) maxoc)))
    post_oc (/ (distance pt1 pt2) (1+ (fix (/ (distance pt1 pt2) maxoc))))
    )

  (repeat numcores
    (command-s "._INSERT" "HR Post Plan View" (polar pt1 0 (* post_oc count)) "" "" "")    
    (setq count (1+ count))
    )  
  (princ)
  )

 

(defun dovertical (/ count)

  (setq count 0
    maxoc 51.
    numcores (+ 2 (fix (/ (distance pt1 pt2) maxoc)))
    post_oc (/ (distance pt1 pt2) (1+ (fix (/ (distance pt1 pt2) maxoc))))
    )

  (repeat numcores
    (command-s "._INSERT" "HR Post Plan View" (polar pt1 a270 (* post_oc count)) "" "" "")
    (setq count (1+ count))
    )  
  (princ)
  )

 

(defun leftside    (msg / tp1 tpp1 pt3)
  (setq tp1 (entsel msg))
  (setq tpp1 (entget (car tp1)))
  (setq pt1 (cdr (assoc 10 tpp1)))
  (setq pt2 (cdr (assoc 11 tpp1)))
  (setq pt3 (cadr tp1))
  (setq d1 (distance pt1 pt3))
  (setq d2 (distance pt2 pt3))
  (if (> d1 d2)
    (progn
      (setq temp pt1)
      (setq pt1 pt2)
      (setq pt2 temp)
    )
  )
  (setq ang (angle pt1 pt2))
)

Edited by Bill Tillman
Link to comment
Share on other sites

try change this sub , it's not generic which has global vars (pt1 , pt2) to be used in main routine

 

(defun leftside	(msg / s pts)
  (terpri)
  (and
    (princ msg)
    (setq s (ssget "_:S:E+." '((0 . "LINE"))))
    (setq pts (mapcar ''((x) (cdr (assoc x (entget (ssname s 0)))))
		      '(10 11)
	      )
    )
    (apply 'angle
	   (mapcar 'set
		   '(pt1 pt2)
		   (if (apply '< (mapcar 'car pts))
		     pts
		     (reverse pts)
		   )
	   )
    )
  )
)

 

Link to comment
Share on other sites

Many thanks hanhphuc. There still is something not quit right as I chose a horizontal line and it placed the blocks on a vertical pattern. That was easily rotated 90° to make the layout work. This weekend when I'm not here at this friggin' office where the manager has sworn to kill anyone using LISP will not bother me, I'll work through it and post back what, if anything I find.

Link to comment
Share on other sites

Your using the near end so why not add the angle to the block pt so line is at any angle no need to check. I would make the pick line the rail edge rather than centreline. had a go as per PM will add this one as well. I rewrote the block to be a 1x1 sq so it scales the size of the picket.  Ver2 would use multigetvals.lsp.

(vl-load-com)

(defun c:rlayout ( / vars impmet picketthk maxoc num numcores post_oc)
 
  (defun *error* ( m )
    (and vars (mapcar 'setvar '(osmode pickbox aunits angdir ) vars))
    (princ m) (princ)
  )
  
  ;;; impet1 change this for Imperial or Metric - 1=Imperial, 2.54=cm 25.4=mm, etc...
  (setq vars (mapcar 'getvar '(osmode pickbox aunits angdir))
    impmet 1
    picketthk (* impmet 1.)
    )
  
	(leftside)

	(setq num 0
    maxoc 151.
    numcores (+ 2 (fix (/ (distance pt1 pt2) maxoc)))
    post_oc (/ (distance pt1 pt2) (1+ (fix (/ (distance pt1 pt2) maxoc))))
	len 75.0
	wid 12.0
    )
	
	(setvar 'aunits 3)
	(setvar 'osmode 0)
	(setvar 'angdir 0)
	(repeat numcores
    (command-s "._INSERT" "1sq" (polar pt1 ang (* post_oc num)) len wid ang)    
    (setq num (1+ num))
    )

	(mapcar 'setvar '(osmode pickbox aunits angdir) vars)
  
	(princ)
)


(defun leftside    ( / tp1 tpp1 pt3)
  (setq tp1 (entsel "\nSelect a line : "))
  (setq tpp1 (entget (car tp1)))
  (setq pt1 (cdr (assoc 10 tpp1)))
  (setq pt2 (cdr (assoc 11 tpp1)))
  (setq pt3 (cadr tp1))
  (setq d1 (distance pt1 pt3))
  (setq d2 (distance pt2 pt3))
  (if (> d1 d2)
    (progn
      (setq temp pt1)
      (setq pt1 pt2)
      (setq pt2 temp)
    )
  )
  (setq ang (angle pt1 pt2))
)

image.png.de470d432567fa1b6cdb75aec4568145.pngimage.png.6da27fd0c30a3f3679b3c3c28ef58259.png

 

You have an error in working out the 1st point so some hints as the code I am using is confidential I have not fully rewritten.

c-c (+ gap wid)

(setq dist (distance pt1 pt2))
(setq num  (- (fix  (/ dist c-c)) 1))
(setq endd (/ (- dist (* num c-c)) 2.0))

 

 

  • Like 1
Link to comment
Share on other sites

Hi Bill and any one else out there what about the cloud could hide all your lisps on your cloud account.

 

save this on your cloud and drag and drop onto Autocad

(defun c:wow () (alert "this was on the cloud\n\ndragged and dropped"))
(c:wow)

 

Link to comment
Share on other sites

On 3/31/2020 at 1:21 PM, BIGAL said:

Hi Bill and any one else out there what about the cloud could hide all your lisps on your cloud account.

 


save this on your cloud and drag and drop onto Autocad

(defun c:wow () (alert "this was on the cloud\n\ndragged and dropped"))
(c:wow)

 

 

OneDrive ? ? googleDrive

maybe not sync?

 

my cloud problem was a LISP file 14KB but zero contents blank! 😂 

it happened weeks ago for a post by @Grrr

 

 

tmp200321 invert FILLET.LSP

Edited by hanhphuc
Link to comment
Share on other sites

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...