To draw Center line for squares, circles etc.

To draw Center line for squares, circles etc.

trezatreza
Enthusiast Enthusiast
4,537 Views
12 Replies
Message 1 of 13

To draw Center line for squares, circles etc.

trezatreza
Enthusiast
Enthusiast

Hi everyone

 

Please can you help me for this lisp because it will save me a lot of time

 

I want to draw polyline a line passing from the middle of each element Where select all (As the attached picture)

 

Thank you so much in advance

0 Likes
Accepted solutions (1)
4,538 Views
12 Replies
Replies (12)
Message 2 of 13

Kent1Cooper
Consultant
Consultant
Accepted solution

Try this [minimally tested]:

(defun C:CHRCE ; = Cross-Hairs in Rectangles, Circles, Ellipses
  (/ ss ent pl)
  (if
    (setq ss
      (ssget
        (list
          '(-4 . "<OR")
            '(0 . "CIRCLE"); any Circle(s)
            '(-4 . "<AND") '(0 . "LWPOLYLINE") '(90 . 4) '(-4 . "&") '(70 . 1) '(-4 . "AND>")
              ; only 4-vertex closed Polyline(s)
            '(-4 . "<AND") '(0 . "ELLIPSE") '(41 . 0.0) (cons 42 (* pi 2)) '(-4 . "AND>")
              ; only closed Ellipse(s)
          '(-4 . "OR>")
        ); list
      ); ssget
    ); setq
    (repeat (setq n (sslength ss)) ; then
      (setq
        ent (ssname ss (setq n (1- n)))
        pl (= (cdr (assoc 0 (entget ent))) "LWPOLYLINE"); is a Polyline [T or nil]
      ); setq
      (command
        "_.line"
          "_none" (vlax-curve-getPointAtParam ent (if pl 0.5 0))
          "_none" (vlax-curve-getPointAtParam ent (if pl 2.5 pi)) ""
        "_.line"
          "_none" (vlax-curve-getPointAtParam ent (if pl 1.5 (/ pi 2)))
          "_none" (vlax-curve-getPointAtParam ent (if pl 3.5 (* pi 1.5))) ""
      ); command
    ); repeat
  ); if
); defun

I added Ellipses, because they can be done in exactly the same way as Circles using the (vlax-curve) parameters.

 

It draws the Lines on the current Layer, but a particular Layer setting could be built in [or any other desired properties].

 

It does not [yet, but could be enhanced to] verify that a 4-sided closed Polyline is, in fact, rectangular, nor that it contains only line segments, so it will also do things like these:
Crosshairs.PNG

Another thing it could be enhanced to recognize, if desired, is a "circle" that is actually a two-equal-arc-segment Polyline, such as made by the DONUT command.

Kent Cooper, AIA
0 Likes
Message 3 of 13

trezatreza
Enthusiast
Enthusiast

Wow ! This is what I wanted. Thank you very much

0 Likes
Message 4 of 13

Kent1Cooper
Consultant
Consultant

@Kent1Cooper wrote:

.... It does not [yet, but could be enhanced to] .....


 

I have been fiddling with enhancements, etc., for a more universalized and versatile command.  See the result in the attached CrossHairs.lsp with its eponymous command name.

 

It lets you specify an extension [or a shortfall, if negative] of the cross-hair Lines relative to the perimeter shape, and remembers that distance and offers it as default on subsequent use.  [Use zero for the same effect as in the CHRCE command with Line ends on  the perimeter.]  It also works with a "circle" that's actually a 2-half-circle-arc-segment LWPolyline, such as the DONUT command makes.  And it also works with "heavy" Polylines as well as lightweight ones, even 3D Polylines if they're planar [though with "heavy" ones, it can't filter for number of segments or planarity in selection, so it accepts any closed ones, but draws crosshairs in them only if they're 4-sided and planar].  It makes its own Layer for the crosshairs [EDIT the name/color/linetype as desired], and puts you back in the Layer you were in when done.  It works in or from any Coordinate System.  And it has the usual other stuff [*error* handling, command-echo and object-snap suppression, Undo begin/end wrapping].

 

See the comments at the top of and within the file for more information.

Kent Cooper, AIA
Message 5 of 13

trezatreza
Enthusiast
Enthusiast

Thank you very much for your efforts
is it possible Semi-first file, Where he does new layer name "A-CROS-HAIR" Red color

0 Likes
Message 6 of 13

Kent1Cooper
Consultant
Consultant

@trezatreza wrote:

.... is it possible Semi-first file, Where he does new layer name "A-CROS-HAIR" Red color


 

I'm not sure what you're asking.  You can change the Layer name and/or color and/or linetype, or leave out the linetype setting and it will be Continuous, or add other options such as lineweight or a Description, etc. -- anything that a Layer command can do can be built into the code -- or remove the entire line if you want them drawn on whatever the current Layer is.

Kent Cooper, AIA
0 Likes
Message 7 of 13

trezatreza
Enthusiast
Enthusiast

in "CrossHairs.lsp"
is it possible be the first value is 0 (As the picture)

 

gghfh.JPG

0 Likes
Message 8 of 13

Kent1Cooper
Consultant
Consultant

@trezatreza wrote:

in "CrossHairs.lsp" is it possible be the first value is 0 ....


 

The attached revised version does that.

Kent Cooper, AIA
0 Likes
Message 9 of 13

trezatreza
Enthusiast
Enthusiast

Thank you so much🌹

0 Likes
Message 10 of 13

claudemir-stz
Enthusiast
Enthusiast

Can you make this work with Arc as well?

0 Likes
Message 11 of 13

Kent1Cooper
Consultant
Consultant

@claudemir-stz wrote:

Você pode fazer isso funcionar também com Arc?


Post some examples of what you would want it to draw for an Arc, with different Arc extents.

 

Does DIMCENTER not do what you want, with the DIMCEN System Variable set to a negative value so it draws the lines out to/through the Arc itself, not just the cross in the center?

Kent1Cooper_0-1678468044238.png

 

Kent Cooper, AIA
0 Likes
Message 12 of 13

claudemir-stz
Enthusiast
Enthusiast

I use AutoCAD 2016.

DIMCEN value is fixed, i need to manually change it for each diameter.

0 Likes
Message 13 of 13

Kent1Cooper
Consultant
Consultant

@claudemir-stz wrote:

DIMCEN value is fixed, i need to manually change it for each diameter.


If you type in DIMCEN, does it not let you set a value that remains in effect for all diameters?  Is that not the way it has always worked?

 

And you haven't answered the request at the beginning of Message 11.

Kent Cooper, AIA
0 Likes