AutoCAD/Matchprop of angle

Advertisement


Question
QUESTION: Bill, I need to match the angle property of one object to another object. The Match Properties command will not do this. Do you know of a lisp routine that will do this and that uses the same method as Match Properties. i.e. select source, select object to change.
Thanks in advance.

David

ANSWER: David.  Well, try this.  I wrote it tonight.  MANG.LSP
It will work with text and blocks, and XREFs.  Won't work on images.  Works to rotate dimensions, keeping the same definition points, thereby changing the dimension value.

Keep in touch
Bill DeShawn
http://my.sterling.net/~bdeshawn


---------- FOLLOW-UP ----------

QUESTION: Bill,
Thank you for your quick response. And for writing MANG.LSP.
I do not see where I can donwload the program. The "MANG.LSP" in your answer is not a link.
could you please e-mail it to david.adams@mustangeng.com & to daddyman5398@alltel.net
I give the second e-mail address just incase the first one is blocked by the company firewall.

Thank you so much!

David

ANSWER: Sorry about that.  I though I included it in my text.  Here is the code that I forgot to include in the message.  There is no way to attach a file to these messages, but you can paste the code below in a textfile (in NOTEPAD) and save it as MANG.LSP.

(defun mangerr (msg)
  (if (null wasworld) (command "_.ucs" "_p"))
  (if msg (princ msg))
  (if olderr (setq *error* olderr))
  (princ)
)

(defun c:mang (/ olderr wasworld ent elist orient sset ssqty index ssqty next nxlst nxrot nwlst)
  (setq olderr *error* *error* mangerr)
  (command "_.undo" "_g")
  (if (= (getvar "worlducs") 1)(setq wasworld T))
  (if (null wasworld) (command ".ucs" "w"))
  (setq ent (entsel))
  (setq elist (entget (car ent)))
  (setq orient (assoc 50 elist))
  (prompt "\nSelect objects to match rotation:  ")
  (setq sset (ssget))
  (setq ssqty (sslength sset))
  (setq index 0)
  (repeat ssqty
     (setq next (ssname sset  index))
     (setq nxlst (entget next))
     (setq nxrot (assoc 50 nxlst))
     (setq nwlst (subst orient nxrot nxlst))
     (entmod nwlst)
     (setq index (1+ index))
  )
  (if (null wasworld)(command "_.ucs" "_p"))
  (setq *error* olderr)
  (command "_.undo" "_end")
  (princ)
)

Keep in touch
Bill DeShawn
http://my.sterling.net/~bdeshawn



---------- FOLLOW-UP ----------

QUESTION: Hi Bill,

Thank you for the program.
I could not get it to work.
When I pick a text object and then a line I get:
Command: mang
_.undo Current settings: Auto = On, Control = All, Combine = Yes
Enter the number of operations to undo or [Auto/Control/BEgin/End/Mark/Back]
<1>: _g
Command:
Select object:
Select objects to match rotation:
Select objects: 1 found

Select objects:
_.undo Current settings: Auto = On, Control = All, Combine = Yes
Enter the number of operations to undo or [Auto/Control/BEgin/End/Mark/Back]
<1>: _end
Command:

when I pick a line and then a text object (this is what I need to do) I get:
Command: mang
_.undo Current settings: Auto = On, Control = All, Combine = Yes
Enter the number of operations to undo or [Auto/Control/BEgin/End/Mark/Back]
<1>: _g
Command:
Select object:
Select objects to match rotation:
Select objects: 1 found

Select objects:
bad DXF group: nil

If you can fix this it will be great but I know you must have more important things to do.
Thank you for your help

David

Answer
A line does not have an angle "property". I'll have to make the program figure out what the angle of the line is and then match the text to it.  I can add that, but it won't work the other way.  That would make my routine grow about 5 times as big and I'd use up a bunch of hours on it.  So, I'll just to this to apply a line angle to text.  It won't rotate another line to match.  It will just be for changing the angle of TEXT, MTEXT or a block or XREF to match the line that was picked first.  It will NOT work with a polyline.  It will not work on 3-D solid.  Remember if a line was drawn in the direction opposite to the desired direction, the newly rotated object will be 180 degrees off.

OK.  Here it is.  The error handler is a little weird, but it works pretty well.  The routine will work with a line as a source object but not a target object.  A polyline will not work at all:

(defun mangerr (msg)
  (if msg (setq oldmsg msg))
  (setq msg "Done")
  (if (null wasworld) (command "_.ucs" "_p"))
  (if olderr (setq *error* olderr))
  (command "_.undo" "end")
  (command)
  (princ msg)
  (setq ent_is_line nil olderr nil orient nil sset nil ssqty nil index nil next nil nxlst nil nxrot nil nwlst nil)
  (setq msg oldmsg)
  (princ)(princ)
)

(defun mtchlin ()
  (setq ent1_is_line T)
  (setq orient (angle (cdr (assoc 10 elist)) (cdr (assoc 11 elist))))
  (setq orient (cons 50 orient))
  (prompt "\nSelect objects to match rotation:  ")
  (setq sset (ssget))
  (setq ssqty (sslength sset))
  (setq index 0)
  (repeat ssqty
     (setq next (ssname sset  index))
     (setq nxlst (entget next))
     (if (= (cdr (assoc 0 nxlst)) "LINE") (progn (alert "No can do.  Target object is a line")(exit)))
     (if (= (cdr (assoc 0 nxlst)) "LWPOLYLINE") (progn (alert "No can do.  Target object is a polyline")(exit)))
     (if (= (cdr (assoc 0 nxlst)) "POLYLINE") (progn (alert "No can do.  Target object is a polyline")(exit)))
     (setq nxrot (assoc 50 nxlst))
     (setq nwlst (subst orient nxrot nxlst))
     (entmod nwlst)
     (setq index (1+ index))
  )
  (if (null wasworld)(command "_.ucs" "_p"))
  (setq *error* olderr)
  (setq ent_is_line nil olderr nil orient nil sset nil ssqty nil index nil next nil nxlst nil nxrot nil nwlst nil)
  (command "_.undo" "_end")
  (command)
  (princ "\nDone.  ")(princ)
  (princ)
)

(defun c:mang ()
  (setq olderr *error* *error* mangerr)
  (command "_.undo" "_g")
  (if (= (getvar "worlducs") 1)(setq wasworld T))
  (if (null wasworld) (command ".ucs" "w"))
  (setq ent1 (entsel))
  (setq elist (entget (car ent1)))
  (if (= (cdr (assoc 0 elist)) "LINE") (progn (mtchlin) (mangerr msg) (exit)))
  (if (= (cdr (assoc 0 elist)) "LWPOLYLINE") (progn (alert "No can do.  Source object is a polyline")(exit)))
  (if (= (cdr (assoc 0 elist)) "POLYLINE") (progn (alert "No can do.  Source object is a polyline")(exit)))
  (setq orient (assoc 50 elist))
  (prompt "\nSelect objects to match rotation:  ")
  (setq sset (ssget))
  (setq ssqty (sslength sset))
  (setq index 0)
  (repeat ssqty
     (setq next (ssname sset  index))
     (setq nxlst (entget next))
     (setq nxrot (assoc 50 nxlst))
     (setq nwlst (subst orient nxrot nxlst))
     (entmod nwlst)
     (setq index (1+ index))
  )
  (if (null wasworld)(command "_.ucs" "_p"))
  (setq *error* olderr)
  (setq ent_is_line nil olderr nil orient nil sset nil ssqty nil index nil next nil nxlst nil nxrot nil nwlst nil)
  (command "_.undo" "_end")
  (command)
  (princ "\nDone.  ")(princ)
  (princ)
)

Keep in touch
Bill DeShawn
http://my.sterling.net/~bdeshawn  

AutoCAD

All Answers


Answers by Expert:


Ask Experts

Volunteer


Bill DeShawn

Expertise

I can address all 2-D questions and some 3-D questions. I do programming in AutoLISP if it doesn`t involve solid modeling. I can also address menu customization issues and can help you find answers to questions I can`t answer by taking your question directly to Autodesk via their newsgroups.

Experience

I used to do electronic and mechanical design for a flat panel monitor manufacturer, and now I do architectural drafting for an architect. I did and do AutoLISP and menu customization and take pride in making my lisp routines to do the work exactly the way the client likes them done.

Publications
I had a routine published in CADENCE magazine (no longer in publication and taken over by CADALYST). Some of my routines are published on my website at http://my.sterling.net/~bdeshawn

©2012 About.com, a part of The New York Times Company. All rights reserved.