Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Center Line Circle

15 REPLIES 15
Reply
Message 1 of 16
Anonymous
2056 Views, 15 Replies

Center Line Circle

Please...

I need Lisp for Center Line in Circle.... for Example ..............
15 REPLIES 15
Message 2 of 16
Anonymous
in reply to: Anonymous

If you can live with the minor limitations, AutoCAD will do that for you
without any Lisp coding required. Use the DIMCENTER Command on a Layer with
a Center-type linetype (or with a linetype assigned to the pieces), with a
*negative* value for the DIMCEN System Variable. Limitations? DIMCEN
controls the size of the cross in the center, and the gaps between it and
the four lines, and the extension of the lines beyond the circle. And it
does make a central cross with four lines, rather than two through-lines.
If you need any of those things to be done differently, then you would want
to make a routine, but it would be pretty simple.
--
Kent Cooper


"Fabricio - Engenharia/Waltec" wrote...
Please...

I need Lisp for Center Line in Circle.... for Example ..............
Message 3 of 16
Anonymous
in reply to: Anonymous

Try this (beside the Cooper's sugestion):

(defun c:ccl (/ #osmode #rad #p1 #cen #diam qy+ qy- qx+ qx- #ss #sel loop qtde ent #e1)
(command "undo" "begin")
(setvar "cmdecho" 0)
(setq #osmode (getvar "osmode"))
(setvar "osmode" 0)
(setq #clayer (getvar "clayer"))
(if (not (tblsearch "layer" "centro"))
(command "layer" "m" "centro" "c" "1" "" "l" "dashdot" "" "" "");change your layer here
)
(command "layer" "set" "centro" "");change your layer here
(princ "\n Insert Centerline into Circles and Arcs... ")
(setq loop 0)
(prompt "\n Select the Arc(s) or Circle(s):")
(setq #sel (ssget (list (cons 0 "ARC,CIRCLE"))))
(if #sel
(progn
(setq qtde (sslength #sel))
(repeat qtde
(setq ent (ssname #sel loop))
(setq #e1 (entget ent))
(setq tipo (strcase (cdr (assoc 0 #e1))))
(if (or (= tipo "CIRCLE")(= tipo "ARC"))
(progn
(setq #rad (cdr (assoc 40 #e1)))
(setq #cen (cdr (assoc 10 #e1)))
(setq #diam (* 2 #rad))
(setq qy+ (polar #cen 1.5708 #rad))
(setq qy- (polar #cen 4.71239 #rad))
(setq qx+ (polar #cen 0 #rad))
(setq qx- (polar #cen 3.14159 #rad))
(setq #ss (ssadd))
(command "line" qy+ qy- "")
(setq #ss (ssadd (entlast) #ss))
(command "line" qx+ qx- "")
(setq #ss (ssadd (entlast) #ss))
(command "scale" #ss "" #cen "1.15");;change the scale factor (1.15) here
(setq loop (+ loop 1))
)
)
)
)
)
(setvar "clayer" #clayer)
(setvar "osmode" #osmode)
(command "undo" "end")
(princ))


:)

Rogerio
Message 4 of 16
Anonymous
in reply to: Anonymous

Well, just for fun, here's a way to do it without DIMCENTER, and with two
lines going all the way through instead of a separate center cross and four
lines. [And a lot more simply than Rogerio's, though that looks like it's
made to do multiple circles.] I assume that:
- you want the center-lines on a Layer of their own (not a dimensioning
layer -- I'll call it "circen"), which may not already exist in the drawing
when the routine is called up, and with a Dashdot linetype (as it appears in
your example) assigned to that Layer;
- you are working in metric units (does .br stand for Brazil?);
- you want the lines to extend, let's say, 5 mm outside the circle on paper,
whatever the drawing scale;
- you have a typical kind of "dimscale" variable, even though this won't use
a dimensioning command.

(defun C:CIRCEN (/ circlist circctr circrad cenlinlen curlay)
(setq
circlist (entget (car (entsel "Select Circle for Center-Lines: ")));
gets circle's association list
circctr (cdr (assoc 10 circlist)); saves center point
circrad (cdr (assoc 40 circlist)); saves radius
cenlinlen (+ circrad (* (getvar "dimscale") 5)); saves length from
center to line ends
curlay (getvar "clayer"); saves current layer
osmodes (getvar "osmode"); saves object snap modes
); end setq
(command "_.layer" "_m" "circen" "_l" "dashdot" "" ""); makes [or sets]
layer
(command "_.line"
(polar circtr 0 cenlinlen)
(polar circtr pi cenlinlen)
""); draws horizontal line
(command "_.line"
(polar circtr (/ pi 2) cenlinlen)
(polar circtr (* pi 1.5) cenlinlen)
""); draws vertical line
(setvar "clayer" curlay); sets layer back
(setvar "osmode" osmodes); resets object snap modes
); end defun

Change the 5, the layer name, and/or the linetype as you prefer. There are
other things you could add for more sophistication, but I think this ought
to work (though I haven't tested it).
--
Kent Cooper


"Fabricio - Engenharia/Waltec" wrote...
Please...

I need Lisp for Center Line in Circle.... for Example ..............
Message 5 of 16
Anonymous
in reply to: Anonymous

Try this out.
(defun C:CA (/ x ent pt1 d1 p1 p2)
(setq x (entsel "\nSelect circle: "))
(setq ent (car x))
(setq pt1 (cdr (assoc 10 (entget ent))))
(setq d1 (getdist pt1 "\nLength of line: "))
(setq p1 (polar pt1 0.0 d1))
(setq p2 (polar pt1 PI d1))
(command "line" p1 p2 "")
(command "chprop" "l" "" "lt" "center" "")
(command "array" "l" "" "P" pt1 "2" "90" "")
)
Message 6 of 16
Anonymous
in reply to: Anonymous

Very fun.

Only correct this line:

to

circctr (cdr (assoc 10 circlist)); saves center point

to

circtr (cdr (assoc 10 circlist)); saves center point

Thank you.

:)

Rogerio
Message 7 of 16
Anonymous
in reply to: Anonymous

[That's what happens when you don't test it....
--
Kent Cooper]


wrote...
Very fun.

Only correct this line:

to

circctr (cdr (assoc 10 circlist)); saves center point

to

circtr (cdr (assoc 10 circlist)); saves center point

Thank you.

:)

Rogerio
Message 8 of 16
Anonymous
in reply to: Anonymous

Simple, but with some possible drawbacks, depending on what the original
poster wants:
- requires (or allows, if that's preferable) the user to tell it how long to
make the lines, which can be automated to save a step if they have a
standard amount of extension;
- puts the lines on whatever layer is current (which could be for plumbing
fixtures, for all anyone can predict), so you might have such centerlines on
any number of layers in the same drawing;
- forces the linetype (but not the color -- wouldn't that be appropriate,
too?), so if you decided to change the linetype of all such lines, you
couldn't do it by changing the linetype of the layer they're on -- you'd
have to select them all.
- assumes the Units angle setting is for degrees.

[By the way, numerical input inside (command) functions doesn't need
quotation marks around it -- that makes it into text strings, which happens
to work as answers to these prompts, but it isn't necessary.]

It also makes a bunch of variables that aren't really needed. Instead of
saving a variable that's only going to be used once, I usually prefer to
just calculate the value where it will be used. Just a matter of
preference, perhaps, but it could be shortened a lot:

(defun C:CA (/ pt1 d1)
(setq pt1 (cdr (assoc 10 (entget (car (entsel "\nSelect circle: "))))))
(setq d1 (getdist pt1 "\nLength of line: "))
(command "line" (polar pt1 0.0 d1) (polar pt1 PI d1) "")
(command "chprop" "l" "" "lt" "center" "")
(command "array" "l" "" "P" pt1 2 90 "")
)

Or you could draw the line across and back in the line command, and then
rotate the last one 90 degrees. Or you could copy the first line in place,
and rotate the last one. Or you could use the little-known and I think
no-longer-documented Circular array option, which asks for an angle between
items rather than an angle to fill (except as a later option):

(command "array" "l" "" "C" pt1 90 2 "Y")
or
(command "array" "l" "" "C" pt1 90 -90 "Y")
[check out its prompts]

Or you could....
--
Kent Cooper


wrote...
Try this out.
(defun C:CA (/ x ent pt1 d1 p1 p2)
(setq x (entsel "\nSelect circle: "))
(setq ent (car x))
(setq pt1 (cdr (assoc 10 (entget ent))))
(setq d1 (getdist pt1 "\nLength of line: "))
(setq p1 (polar pt1 0.0 d1))
(setq p2 (polar pt1 PI d1))
(command "line" p1 p2 "")
(command "chprop" "l" "" "lt" "center" "")
(command "array" "l" "" "P" pt1 "2" "90" "")
)
Message 9 of 16
Anonymous
in reply to: Anonymous

Wow, I didn't think my little file would illicit so much criticism.
Does it work?
Message 10 of 16
Anonymous
in reply to: Anonymous

Not so much "criticism" as making the original poster aware of a few things
they might not like about the way it works, if they decide to try it. But
it depends on their needs; if they don't mind those things, it could be
fine, though I didn't test it.

(And a few efficiency suggestions, of course....)

[But here's an actual criticism -- the verb you want is "elicit". "Illicit"
is an adjective, roughly synonymous with "illegal."]

--
Kent Cooper


wrote...
Wow, I didn't think my little file would illicit so much criticism.
Does it work?
Message 11 of 16
Anonymous
in reply to: Anonymous

Kent,
Sorry I am not perfect.
Message 12 of 16
Anonymous
in reply to: Anonymous

Hi people, friends, ok? 😉

My other sugestion with excess control (only sugestion - no error treatment, nothing):

(defun c:ccl1 (/ #osmode #clayer loop #sel qtde ent #e1 tipo #rad #cen #diam qy+ qy- qx+ qx- excess)
(command "undo" "begin")
(setvar "cmdecho" 0)
(setq #osmode (getvar "osmode"))
(setvar "osmode" 0)
(setq #clayer (getvar "clayer"))
(if (not (tblsearch "ltype" "dashdot"))
(command "linetype" "load" "dashdot" "acadiso.lin" "" "" "")
)
(if (not (tblsearch "layer" "centro"))
(command "layer" "m" "centro" "c" "1" "" "l" "dashdot" "" "" "");change your layer here
)
(command "layer" "set" "centro" "");change your layer here
(princ "\n Insert Centerline into Circles and Arcs... ")
(initget 4)
(setq excess (getreal "\n Excess value <0>: "))
(if (= excess nil)(setq excess 0));;drawing units
(setq loop 0)
(prompt "\n Select the Arc(s) or Circle(s):")
(setq #sel (ssget (list (cons 0 "ARC,CIRCLE"))))
(if #sel
(progn
(setq qtde (sslength #sel))
(repeat qtde
(setq ent (ssname #sel loop))
(setq #e1 (entget ent))
(setq tipo (strcase (cdr (assoc 0 #e1))))
(if (or (= tipo "CIRCLE")(= tipo "ARC"))
(progn
(setq #rad (+ excess (cdr (assoc 40 #e1))))
(setq #cen (cdr (assoc 10 #e1)))
(setq #diam (* 2 #rad))
(setq qy+ (polar #cen 1.5708 #rad))
(setq qy- (polar #cen 4.71239 #rad))
(setq qx+ (polar #cen 0 #rad))
(setq qx- (polar #cen 3.14159 #rad))
(setq #ss (ssadd))
(command "line" qy+ qy- "")
(command "line" qx+ qx- "")
(setq loop (+ loop 1))
)
)
)
)
)
(setvar "clayer" #clayer)
(setvar "osmode" #osmode)
(command "undo" "end")
(princ))

:)

Rogerio
Message 13 of 16
Anonymous
in reply to: Anonymous

A couple of suggestions:

In my experience (up to Acad2004), in both macro and lisp formats, calling
for a linetype in making a Layer will bring it in, whether or not it is
already loaded in the drawing. So you don't need to check whether it is
loaded, or load it if it isn't. (You may need to do that to assign a
linetype to a drawing entity, but not in this situation.)

I think there's an extra "" at the end of the layer command.

I would use (getdist) for the "Excess value" instead of (getreal), because
it gives the user the option of picking the distance on-screen, as well as
typing something in. And they can type something in using any currently
valid units format [like feet and inches -- yes, I know this will probably
be metric], rather than being limited to real-number format.

It's just as easy to be as precisely accurate as the software can handle
about the angles in the (polar) functions, so the lines will be truly
orthogonal instead of just very close:
(setq qy+ (polar #cen (/ pi 2) #rad))
(setq qy- (polar #cen (* pi 1.5) #rad))
(setq qx+ (polar #cen 0 #rad))
(setq qx- (polar #cen pi #rad))

--
Kent Cooper


wrote...
Hi people, friends, ok? 😉

My other sugestion with excess control (only sugestion - no error
treatment, nothing):

(defun c:ccl1 (/ #osmode #clayer loop #sel qtde ent #e1 tipo #rad #cen #diam
qy+ qy- qx+ qx- excess)
(command "undo" "begin")
(setvar "cmdecho" 0)
(setq #osmode (getvar "osmode"))
(setvar "osmode" 0)
(setq #clayer (getvar "clayer"))
(if (not (tblsearch "ltype" "dashdot"))
(command "linetype" "load" "dashdot" "acadiso.lin" "" "" "")
)
(if (not (tblsearch "layer" "centro"))
(command "layer" "m" "centro" "c" "1" "" "l" "dashdot" "" "" "");change your
layer here
)
(command "layer" "set" "centro" "");change your layer here
(princ "\n Insert Centerline into Circles and Arcs... ")
(initget 4)
(setq excess (getreal "\n Excess value <0>: "))
(if (= excess nil)(setq excess 0));;drawing units
(setq loop 0)
(prompt "\n Select the Arc(s) or Circle(s):")
(setq #sel (ssget (list (cons 0 "ARC,CIRCLE"))))
(if #sel
(progn
(setq qtde (sslength #sel))
(repeat qtde
(setq ent (ssname #sel loop))
(setq #e1 (entget ent))
(setq tipo (strcase (cdr (assoc 0 #e1))))
(if (or (= tipo "CIRCLE")(= tipo "ARC"))
(progn
(setq #rad (+ excess (cdr (assoc 40 #e1))))
(setq #cen (cdr (assoc 10 #e1)))
(setq #diam (* 2 #rad))
(setq qy+ (polar #cen 1.5708 #rad))
(setq qy- (polar #cen 4.71239 #rad))
(setq qx+ (polar #cen 0 #rad))
(setq qx- (polar #cen 3.14159 #rad))
(setq #ss (ssadd))
(command "line" qy+ qy- "")
(command "line" qx+ qx- "")
(setq loop (+ loop 1))
)
)
)
)
)
(setvar "clayer" #clayer)
(setvar "osmode" #osmode)
(command "undo" "end")
(princ))

:)

Rogerio
Message 14 of 16
Anonymous
in reply to: Anonymous

Kent, thank you for the sugestions!

Very valid.

:)

Rogerio
Message 15 of 16
Anonymous
in reply to: Anonymous

My pleasure. But now I *really* have to get back to real work....
--
Kent Cooper


wrote...
Kent, thank you for the sugestions!

Very valid.

:)

Rogerio
Message 16 of 16
ladimirabdala
in reply to: Anonymous

Dear Fabricio,
Here is my routine:

;Caro amigo Fabricio,
;Segue meu exemplo que faz já os círculos com linha de centro. Bem mais prático.

;;DESENHA CIRCULOS C/LINHA DE CENTRO

(defun dtr (a) ;;; converte angulos em radianos
(* PI (/ (+ a ANG) 180.0))
)
(defun C:CIR( / os lala) ;;; inicio da rotina
(setq os (getvar "osmode"))
(setq lala (getvar "clayer"))
(setvar "cmdecho" 0)
(setvar "osmode" 0)
(if (= diam nil)
(while (= diam nil)
(setq diam (getdist "\nDiametro: "))
)
(progn
(setq di diam)
(setq diam (getdist (strcat "\nDiametro <" (rtos diam) ">: ")))
(if (= diam nil)
(setq diam di)
)
)
)

(command "LAYER" "M" "Centro" "") ;;;cria layer centro
(command "LAYER" "C" "Magenta" "" "")
(command "LAYER" "LT" "Center" "" "")
(setq ang 0.0)
(setq ponto (getpoint "Forneca o ponto de insercao: "))
(setq L1 (polar ponto (dtr 270) (* diam 0.80) ) )
(setq L2 (polar L1 (dtr 90) (* diam 1.6)))
(setq L3 (polar ponto (dtr 180) (* diam 0.80) ) )
(setq L4 (polar L3 (dtr 0) (* diam 1.6)))
(command "LAYER" "M" "Cont_G" "") ;;;cria layer Cont_G
(command "LAYER" "C" "Green" "" "")
(command "LAYER" "LT" "Continuous" "" "")

;; EXECUTA OS COMANDOS LINE E CIRCLE
(command "CLAYER" "CENTRO")
(command "LINE" L1 L2 "")
(command "LINE" L3 L4 "")
(command "CLAYER" "Cont_G")
(command "CIRCLE" ponto "D" DIAM)
(setq ANG nil)
(setq a nil)
(setvar "osmode" os)
(setvar "clayer" lala)
(PRINC)
)
(PRINC)

Ladimir Abdala
Porto Alegre.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost