×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Macro for centerline

Macro for centerline

Macro for centerline

(OP)
Hi, does anyone have, or know how to create macro to convert single line to centerline of a circle with a single click?

RE: Macro for centerline

Hi ercegs,

do you want to change the linetype?

Lothar

ADT 2004

RE: Macro for centerline

(OP)
No, not linetype. Maybe my first question was not clear enough. I want with single click on line to get centerline of a circle If my first line is inscribed in circle. So, when I draw a circle and one line inside (e.g. horizotal) I want to rotate and copy that line arround it's middle point with one click of a mouse. Actually the result of this action would be a cross.

Thanks

RE: Macro for centerline

(OP)
Uh, I'm sorry. I'm using ACAD 2007.

Thanks

RE: Macro for centerline

(OP)
I need it in english. I don't know deutch.

How to create LSP file?

RE: Macro for centerline

English?
Only two words:
"Linie wählen" -> "select line"

ADT 2004

RE: Macro for centerline

(OP)
Thanks

RE: Macro for centerline

Copy this, save it to a file called CL.LSP, in AutoCAD type (Load"CL") and it will run, asking you to pick a circle, then the length of the extension past the circle.  

(defun clerr (s)
  (if (/= s "Function cancelled")     ; If an error (such as CTRL-C) occurs
    (princ (strcat "\nError: " s))    ; while this command is active...
  )
  (if e (redraw e 4))
  (command "_.UCS" "_P")                 ; Restore previous UCS
  (setvar "BLIPMODE" sblip)           ; Restore saved modes
  (setvar "GRIDMODE" sgrid)
  (setvar "HIGHLIGHT" shl)
  (setvar "UCSFOLLOW" sucsf)
  (command "_.UNDO" "_E")
  (setvar "CMDECHO" scmde)
  (setq *error* olderr)               ; Restore old *error* handler
  (princ)                             
)

;;; --------------------------- Main Program ---------------------------------;

  (setq olderr *error*
        *error* clerr)
  (setq scmde (getvar "CMDECHO"))
  (command "_.UNDO" "_GROUP")
  (setq clay (getvar "CLAYER"))
  (setq sblip (getvar "BLIPMODE"))
  (setq sgrid (getvar "GRIDMODE"))
  (setq shl (getvar "HIGHLIGHT"))
  (setq sucsf (getvar "UCSFOLLOW"))
  (setvar "CMDECHO" 0)
  (setvar "GRIDMODE" 0)
  (setvar "UCSFOLLOW" 0)
  (setq e nil)
  (progn
   (while (null e)
    (setq e (entsel "\nSelect arc or circle: "))
    (if e
     (progn
       (setq e (car e))
       (if (and (/= (cdr (assoc 0 (entget e))) "ARC")
                (/= (cdr (assoc 0 (entget e))) "CIRCLE")
           )
         (progn
           (prompt "\nEntity is a ")
           (princ (cdr (assoc 0 (entget e))))
           (setq e nil)
         )
       )
      (if e (redraw e 3))
     )
    )
      (command "_.UCS" "_E" e)
      (setq cen (trans (cdr (assoc 10 (entget e))) e 1))
      (setq rad (cdr (assoc 40 (entget e))))
      (prompt "\nRadius is ")
      (princ (rtos rad))
      (initget 7 "Length")
      (setq d (getdist "\nLength/<Extension>: "))
      (if (= d "Length")
        (progn
          (initget 7)
          (setq d (getdist cen "\nLength: "))
        )
        (setq d (+ rad d))
      )
      (setvar "BLIPMODE" 0)
      (setvar "HIGHLIGHT" 0)
;      (command "_.LAYER" "_M" "CL" "")
      (command "_.LINE" (list (car cen) (- (cadr cen) d) (caddr cen))
               (list (car cen) (+ (cadr cen) d) (caddr cen)) ""
      )
      (command "_.CHANGE" "_L" "" "_P" "_LT" "CENTER" "")
      (command "_.LINE" (list (- (car cen) d) (cadr cen) (caddr cen))
               (list (+ (car cen) d) (cadr cen) (caddr cen)) ""
      )
      (command "_.CHANGE" "_L" "" "_P" "_LT" "CENTER" "")
    )
  )
  (redraw e 4)
  (command "_.UCS" "_P")                 ; Restore previous UCS
  (setvar "BLIPMODE" sblip)           ; Restore saved modes
  (setvar "GRIDMODE" sgrid)
  (setvar "HIGHLIGHT" shl)
  (setvar "UCSFOLLOW" sucsf)
  (command "_.UNDO" "_E")
  (setvar "CMDECHO" scmde)
  (setq *error* olderr)               ; Restore old *error* handler
  (princ)

RE: Macro for centerline

(OP)
Ok. Thanks

RE: Macro for centerline

(OP)
I have some problems with this function. It works, but just for once. I go to TOOLS-LOADAPP and choose it, but it works only then. I can't call that function anymore but to go again to TOOLS-LOADAPP...

And if I type (Load"CL") this in acad's command line I get this as an answer:

Error: LOAD failed: "cl"
No previous coordinate system saved.
; error: An error has occurred inside the *error* functionFunction cancelled

Is there any help? Function is very good I would realy like to use it.

I dont know but I think that there is a mistake in the first row of a code: defun clerr

and because of that i can't recall function again.

Looking at the other lisp files I saw that the definition of function is like this:

defun c:ba

Thanks anyway

RE: Macro for centerline

(OP)
Sorry to be annoying about this but this is very good function. There is no mistake in the code,that was my stupidity.

I have other macros that I'm using and I'm using them through icons on my customized toolbar. I put them all to the load application startup suite and they are allways on.

But this function (that is the most important to me) won't work.

RE: Macro for centerline

(OP)
What do I have to change in this code to make centerline in curent layer?

I need all to be "BY LAYER", but this code change linetype in CENTER.

RE: Macro for centerline

I haven't tested it (make a backup first) but try to change these lines
(command "_.CHANGE" "_L" "" "_P" "_LT" "CENTER" "")
to
(command "_.CHANGE" "_L" "" "_P" "_LT" "BYLAYER" "")

____________________
Acad2006, Terramodel

RE: Macro for centerline

(OP)
Great.It works. But there is still the same problem from the begining. When I load app it can be run just once. Whenever I want to use this command I allways have to type appload, and then to choose lsp file. Beside that it works perfect.

Is there any help for this?

Thanks.

RE: Macro for centerline

Put this in as the first line of the code:
(defun c:cl ()

and this as the very last line
);defun c:cl

save, reload the application, type cl to use the application

____________________
Acad2006, Terramodel

RE: Macro for centerline

(OP)
I don't know how to thank You. This is great option for me because I'm working in ACAD 9h every day.

Thanks a lot.

RE: Macro for centerline

Make your button do this:  (if (not C:CL) (load "CL"))

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources