Move command not working in AutoLISP

Move command not working in AutoLISP

davidlanesmith673
Enthusiast Enthusiast
804 Views
4 Replies
Message 1 of 5

Move command not working in AutoLISP

davidlanesmith673
Enthusiast
Enthusiast

I have written a code where you place a point and then place the label to that point. I want to write the code to automatically use the move command to place the label where you want it. I tried the concept in a separate function and it worked perfectly.

 

(defun c:test()
(setq bpt (getpoint "Pick a point: "))
(setq dis (sqrt (* (expt (* textH 0.6) 2) 2)))
(setq a (* dis (cos (+ rAng (/ PI 4)))))
(setq b (* dis (sin (+ rAng (/ PI 4)))))
(setq pntf (list (+ (car bpt) a) (+ (cadr bpt) b)))
(command "._text" pntf textH textA num)
(bns_tcircle (addpnts textH textA pntf num) "Variable" "Rectangles" nil 0.5)
(setq dis (sqrt (* (expt (* textH 0.1) 2) 2)))
(setq rAng (* textA (/ PI 180)))
(setq a (* dis (cos (+ rAng (/ PI 4)))))
(setq b (* dis (sin (+ rAng (/ PI 4)))))
(setq pntb (list (+ (car bpt) a) (+ (cadr bpt) b)))
(setq ss (addpnts textH textA pntf 344))
(command "._move" ss "" pntb)
(princ)
)

 

I then tried to implement this into my code, but the pntb in the move command doesn't seem to register and since the code is in a loop (not shown here) it asks for the next point before it moves the label. When you click again it just breaks the program and then you can just place the label, but youve already left the loop.

 

(if (< (getvar "osmode") 16384)
(progn
(setq os 1)
(setvar "osmode" (+ (getvar "osmode") 16384))
)
(setq os 0)
)
(setq pnt2 (getpoint "\nChoose text position: "))
;(setq pnt2 pnt1)
(setq dis (sqrt (* (expt (* textH 0.6) 2) 2)))
(setq rAng (* textA (/ PI 180)))
(setq a (* dis (cos (+ rAng (/ PI 4)))))
(setq b (* dis (sin (+ rAng (/ PI 4)))))
(setq pntf (list (+ (car pnt2) a) (+ (cadr pnt2) b)))
(command "._text" pntf textH textA num)
(if (= m3 1)
(progn
(setq ss (addpnts textH textA pntf num))
(bns_tcircle ss "Variable" "Rectangles" nil 0.5)
) ; progn
) ; if
(setq dis (sqrt (* (expt (* textH 0.1) 2) 2)))
(setq a (* dis (cos (+ rAng (/ PI 4)))))
(setq b (* dis (sin (+ rAng (/ PI 4)))))
(setq pntb (list (+ (car pnt2) a) (+ (cadr pnt2) b)))
(setq sel (addpnts textH textA pntf num))
(command ".move" sel "" pntb)
(if (= os 1) (setvar "osmode" (- (getvar "osmode") 16384)))

 

I don't understand how my second code is any different than my first, and why it isn't working.

0 Likes
Accepted solutions (1)
805 Views
4 Replies
Replies (4)
Message 2 of 5

CodeDing
Advisor
Advisor

@davidlanesmith673 ,

 

Step 1, ALWAYS declare your local variables:

(defun c:test( / bpt dis a b pntf rAng pntb ss)
.....
)

 

Next, where are these values coming from? Do you define them elsewhere?

(defun c:test( / bpt dis a b pntf rAng pntb ss)
  .....
  (setq dis (sqrt (* (expt (* textH 0.6) 2) 2)))
  .....
  (command "._text" pntf textH textA num)
  (bns_tcircle (addpnts textH textA pntf num) "Variable" "Rectangles" nil 0.5)
  (setq dis (sqrt (* (expt (* textH 0.1) 2) 2)))
  (setq rAng (* textA (/ PI 180)))
  .....
  (setq ss (addpnts textH textA pntf 344))
   .....
)

 

Best,

~DD

0 Likes
Message 3 of 5

davidlanesmith673
Enthusiast
Enthusiast

So textH and textA are global variables and I forgot to change the num variable to an integer. Thats the code that works though, its the other one that i'm having the issues with.

0 Likes
Message 4 of 5

CodeDing
Advisor
Advisor
Accepted solution

@davidlanesmith673 ,

 

It's hard to test your code when you have so many pieces that we would need to try to define ourselves.. Try adding this because since your MOVE command is not finished yet, you do not want to run more code until the user has selected a new position:

.....
(setq sel (addpnts textH textA pntf num))
(command ".move" sel "" pntb pause) ;<-- add pause here
(if (= os 1) (setvar "osmode" (- (getvar "osmode") 16384)))
.....

 

Best,

~DD

0 Likes
Message 5 of 5

davidlanesmith673
Enthusiast
Enthusiast

That did it, thank you so much!! That saves a lot more frustration!!

0 Likes