Jump to content

How to get this LISP to add an additional 90 degrees to its rotate


msirois

Recommended Posts

Hi there,

 

You'll have to forgive my ignorance and I'm new to the whole LISP routine area. My work has this old LISP routine for rotating text which I modified to include MTEXT and blocks. I was hoping to change it solely for block rotation in another lisp routine. The way we have our blocks setup, I would need this LISP routine to add an additional 90 degrees to the matching rotation of the line. Could anyone please help me go about doing this? Every attempt at it has failed so far. Here is the code

 

(defun rottxt_err (s)
  (if (/= s "Function cancelled")
      (princ (strcat "\nError: " s))
  ) 
  (setq *error* old_error)
  (princ)
)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun rot ()
  (setq leng (sslength txt_set)
        n 0
  )
  (while (/= n leng)
         (setq ent (entget (ssname txt_set n))
               n (1+ n)
               ent (subst (cons 50 ang)
                          (assoc 50 ent)
                          ent
                   )
         )
         (entmod ent)
  )
)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun chk ()
  (cond ((= ent nil)
         (princ "\nNothing found there.\nSelect a \"LINE\" to align. ")
         (setq ent (entsel))
         (chk)
        )
        ((/= (cdr (assoc 0 (entget (car ent)))) "LINE")
         (princ "\nNo \"LINE\" found there.\nSelect a \"LINE\" to align. ")
         (setq ent (entsel))
         (chk)
        )
  )
)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun rottxt ()
  (princ "\nSelect a \"LINE\" to align. ")
  (setq ent (entsel))
  (chk)
  (setq ang (angle (cdr (assoc 10 (entget (car ent))))
                   (cdr (assoc 11 (entget (car ent))))
            )
  )
  (rot)
  (setq ans (getstring "\nOK like this? y/n <y> "))
  (if (= (strcase ans) "N")
      (progn (setq ang (+ ang pi))
             (rot)
      )
  )
  (princ)
)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun c:rottxt ()
  (setq old_error *error*
        *error* rottxt_err
  )
  (princ "\nSelect TEXT to rotate. ")
  (setq txt_set (ssget '((0 . "TEXT,MTEXT"))))
  (if txt_set
      (rottxt)
      (alert "No \"TEXT\" found.")
  )
  (setq *error* old_error
        old_error nil
        txt_set nil
        leng nil
        ent nil
        ang nil
        ans nil
        n nil
  )
  (princ)
)

Link to comment
Share on other sites

The code is very poorly written, but after a cursory glance, change:

(cons 50 ang)

to:

(cons 50 (+ (/ pi 2.0) ang))

 

Ya sorry. This code is incredibly old. Probably why I was getting so confused. This seemed to have worked. But I noticed one more issue that I'm hoping you could help me with. The attributes in the block don't rotate with the block. I thought I saw somewhere that you could control that by changing

(setq txt_set (ssget '((0 . "TEXT,Mtext,INSERT"))))

to something like this

(setq txt_set (ssget '((60 . "TEXT,Mtext,INSERT"))))

 

But when I tried it saw it was invalid. Any thoughts?

Link to comment
Share on other sites

A slight variation is to use a two point pick instead of a line this has some advantages you imply which side the block is to go on left-right pick, inverse right-left so no need for an extra pick about which side. This also removes the must be a "line", two pts on a pline.

Link to comment
Share on other sites

Try It :-

(defun c:rottxt (/ proc getang a b c)
 (vl-load-com)
 (defun proc (x y / i)
   (repeat (setq i (sslength x))
     (vla-put-rotation
(vlax-ename->vla-object (ssname x (setq i (1- i))))
y
     )
   )
 )
[b]  (defun getang (/ o)[/b]
[b]    (while (not (setq o (car (entsel "\nSelect Line : "))))[/b]
[b]      (alert "Please Select Object Properly...")[/b]
[b]    )[/b]
[b]    (if o[/b]
[b]      (angle (cdr (assoc 10 (entget o)))[/b]
[b]      (cdr (assoc 11 (entget o)))[/b]
[b]      )[/b]
[b]      nil[/b]
[b]    )[/b]
 )
 (if (and (setq a (ssget '((0 . "TEXT,MTEXT,INSERT"))))
   (setq b (getang))
     )
   (progn
   [color=red] [b] ;;add angle here e.g. 90° (setq b (+ b (/ pi 2)))[/b][/color]
     (proc a b)
     (initget "Y N")
     (setq c (getkword "\nRevert Objects [Yes/No] : "))
     (if (eq c "Y")
(proc a (+ b pi))
     )
   )
 )
 (princ)
)

Edited by satishrajdev
Updated new code
Link to comment
Share on other sites

Try it

(defun c:rottxt	(/ proc a b c)
 (vl-load-com)
 (defun proc (x y / i)
   (repeat (setq i (sslength x))
     (vla-put-rotation
(vlax-ename->vla-object (ssname x (setq i (1- i))))
y
     )
   )
 )
 (if (setq a (ssget '((0 . [color="blue"]"TEXT,MTEXT,INSERT"[/color]))))
   (progn
     (setq b (getangle "\nSpecify Angle :")) [color="red"][b];;add angle here e.g. 90° (setq b (+ (getangle "\nSpecify Angle :") (/ pi 2)))[/b][/color]
     (proc a b)
     (initget "Y N")
     (setq c (getkword "\nRevert Objects [Yes/No] : "))
     (if (eq c "Y")
(proc a (+ b pi))
     )
   )
 )
 (princ)
)

 

 

This works really well. However, part of the appeal of the other one was that I didn't have to select the points myself. I could just click the line, which works better for the way our site plan is set up. How would I go about adding that back in?

Link to comment
Share on other sites

Ya sorry. This code is incredibly old. Probably why I was getting so confused. This seemed to have worked. But I noticed one more issue that I'm hoping you could help me with. The attributes in the block don't rotate with the block. I thought I saw somewhere that you could control that by changing

(setq txt_set (ssget '((0 . "TEXT,Mtext,INSERT"))))

to something like this

 

 

But when I tried it saw it was invalid. Any thoughts?

You got an invalid result because the 0 used in the ssget function is the dxf code group for a text string indicating the entity type (ie "LWPOlYLINE" or "MTEXT"), it isn't the rotation angle. By changing it to 60 you aren't changing the angle, you are changing what the ssget function is grabbing (in this case it is the entity visibility, which TEXT,MTEXT,INSERT are invalid inputs). You need to rotate the txt_set after you grab it.
Link to comment
Share on other sites

You got an invalid result because the 0 used in the ssget function is the dxf code group for a text string indicating the entity type (ie "LWPOlYLINE" or "MTEXT"), it isn't the rotation angle. By changing it to 60 you aren't changing the angle, you are changing what the ssget function is grabbing (in this case it is the entity visibility, which TEXT,MTEXT,INSERT are invalid inputs). You need to rotate the txt_set after you grab it.

 

Thank you. That's very useful to know. This stuff is over my head most of the time.

Link to comment
Share on other sites

This works really well. However, part of the appeal of the other one was that I didn't have to select the points myself. I could just click the line, which works better for the way our site plan is set up. How would I go about adding that back in?

 

I have updated my code...Check once

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