Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations IDS on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Macro for centerline

Status
Not open for further replies.

ercegs

Mechanical
Jun 26, 2007
69
Hi, does anyone have, or know how to create macro to convert single line to centerline of a circle with a single click?

 
Replies continue below

Recommended for you

Hi ercegs,

do you want to change the linetype?

Lothar

ADT 2004
 
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
 
Uh, I'm sorry. I'm using ACAD 2007.

Thanks
 
I need it in english. I don't know deutch.

How to create LSP file?
 
English?
Only two words:
"Linie wählen" -> "select line"

ADT 2004
 
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)
 
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
 
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.
 
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.
 
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
 
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.
 
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
 
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.

 
Make your button do this: (if (not C:CL) (load "CL"))
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor