LISP routine works until I attach to another entity

LISP routine works until I attach to another entity

wicj2015
Participant Participant
289 Views
3 Replies
Message 1 of 4

LISP routine works until I attach to another entity

wicj2015
Participant
Participant

Hi all:

 

Please help me see the error of my ways:

This little routine to draw an oft-drawn shape in AutoCAD works as intended unless I select a point on another block, shape, entity when choosing the startpoint. To be clear, when I select the startpoint in space without snapping it to another entity, it draws the pline shape as intended and rotates it to the angle specified, but I really need this to work when attached to something else as that is the end use.

 

Feel free to criticize my coding structure/methods as I am just starting to learn AutoLISP. 

 

(defun c:BUSH ( / bushstart bushend bushangle startpoint)
(setq bushstart (getdist "\nEnter start size: "))
(setq bushend (getdist "\nEnter end size: "))
(setq bushangle (getangle "\nEnter rotation: "))
(initget 129)
(setq startpoint (getpoint "\npick location of first point: "))
  ; (alert (strcat "Bushing will be "  bushstart  " by "  bushend "\nRotated " bushangle " degrees. \nlocated at " startpoint))
  (setq x_val (car startpoint) )
  (setq y_val (cadr startpoint) )
  (setq y_val1 (+ 0.5 y_val) )
  (setq y_val2 (+ 1 y_val) )
  (setq x_val1 (- x_val (/ bushstart 2)))
  (setq x_val2 (- x_val (/ bushend 2)))
  (setq x_val3 (+ x_val (/ bushstart 2)))
  (setq x_val4 (+ x_val (/ bushend 2)))
  (setq pt2 (list x_val1 y_val))
  (setq pt3 (list x_val1 y_val1))
  (setq pt4 (list x_val2 y_val1))
  (setq pt5 (list x_val2 y_val2))
  (setq pt6 (list x_val4 y_val2))
  (setq pt7 (list x_val4 y_val1))
  (setq pt8 (list x_val3 y_val1))
  (setq pt9 (list x_val3 y_val))
  (setq rotang (* 180.0 (/ bushangle pi)))
  (command "_.layer" "_set" "0" "")
  (command "pline" startpoint "w" "0" "0" pt2 pt3 pt4 pt5 pt6 pt7 pt8 pt9 startpoint "")
  (command "rotate" (entlast) "" startpoint  rotang)
  (setq rotang)
  (princ)
)

 

AutoCAD 2024 on Windows 11.

 

0 Likes
Accepted solutions (1)
290 Views
3 Replies
Replies (3)
Message 2 of 4

paullimapa
Mentor
Mentor
Accepted solution

Try turning off your object snap 

include at start of your code:

(setq osmode (getvar "osmode")) ; save current setting
(setvar "osmode" 0) ; turn off

then at end of your code restore original setting:

(setvar "osmode" osmode)

 


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
Message 3 of 4

wicj2015
Participant
Participant

Thank you so much paullimapa, that was it and something I don't think I ever would have guessed. I ended up setting the osmode to 0 after the prompts for the angle and startpoint, but setting it before the pline was drawn made all the difference. 

 

0 Likes
Message 4 of 4

paullimapa
Mentor
Mentor

Glad to have helped..cheers!!!


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes