"unexploding" a block

"unexploding" a block

barry2104
Collaborator Collaborator
2,810 Views
21 Replies
Message 1 of 22

"unexploding" a block

barry2104
Collaborator
Collaborator

Hi
I often get files (dwgs/dxfs) from Architects which have circles that have been "dumbed down" to closed, straight-edged polylines with say 100 nodes around the circumference. I assume these come from a block which has been exploded, in which there are 10 of these circles of differing radius but with the same centre point, representing a block for a coordinate point. So for one point on a drawing I have 10 circles with a total of 1000 lines joined from 10 polylines. These coordinate points are all over the drawing, making it unnecessarily large. Is it possible to either:
1) get AutoCAD to recognise a "straight-edged circle" so as to then convert the polyline to an actual circle, thus reducing file size?
and/or
2) at one instance, select these 10 straight-edged circles of one coord-point, and convert it to a block (or replace with a simpler, preexisting block), and subsequently / through automation, convert all other coord-points to a block (in turn replacing all other 10x straight-edged circles)?

 

Seems like a reach but thought I'd ask anyway

Running AutoCAD Architecture 2020, in German
0 Likes
Accepted solutions (2)
2,811 Views
21 Replies
Replies (21)
Message 2 of 22

Kent1Cooper
Consultant
Consultant
Accepted solution

@barry2104 wrote:

.... Is it possible to ... get AutoCAD to recognise a "straight-edged circle" so as to then convert the polyline to an actual circle, thus reducing file size?....



If they're regular, you can use PolygonToCircle.lsp, with its Pg2C command, available >here<.

Kent Cooper, AIA
0 Likes
Message 3 of 22

ronjonp
Mentor
Mentor

If you have a seat of BricsCAD, they have the 'Blockify' command available. Maybe AutoCAD 2021 will add this feature.

0 Likes
Message 4 of 22

marko_ribar
Advisor
Advisor

@ronjonp wrote:

If you have a seat of BricsCAD, they have the 'Blockify' command available. Maybe AutoCAD 2021 will add this feature.


I've implemented shortened-simplified version for AutoCAD... Just tested it on concentrical circles and it worked well if all circles planar with WCS... Note that my version operates only in 2D...

Here is link :

http://www.theswamp.org/index.php?topic=55186.msg594547#msg594547

(you have to be logged to be able to download *.vlx)

 

Regards, M.R.

Marko Ribar, d.i.a. (graduated engineer of architecture)
Message 5 of 22

Kent1Cooper
Consultant
Consultant

@Kent1Cooper wrote:....

If they're regular, you can use....


If they don't respond to that, because they're not close enough to regular polygons, here's something that will take any closed Polyline [including with arc segments] or Ellipse or Spline, and draw the Circle of the same area, centered around the middle of the object's bounding box.  Deleting the source objects can easily be added, but without doing so, it's clearer whether it makes appropriate equivalent Circles for your needs.  It could also be made to not  require things to be closed, if that is needed.  Minimally tested, and not for different UCS's, and without such things as error handling yet:

(defun C:Area2Circle (/ ss n ent minpt maxpt)
  (prompt "\nTo convert closed shapes to equivalent-area Circles,")
  (if (setq ss (ssget '((0 . "*POLYLINE,SPLINE,*ELLIPSE"))))
    (repeat (setq n (sslength ss)); then
      (setq ent (ssname ss (setq n (1- n))))
      (if (vlax-curve-isClosed ent); skip open-ended Polylines/Splines & partial Ellipses
        (progn ; then
          (setq obj (vlax-ename->vla-object ent))
          (vla-getboundingbox obj 'minpt 'maxpt)
          (command "_.circle"
            "_none" (mapcar '/ (mapcar '+ (vlax-safearray->list minpt) (vlax-safearray->list maxpt)) '(2 2 2))
            (sqrt (/ (vlax-curve-getArea obj) pi))
          ); command
        ); progn
      ); if [closed]
    ); repeat
  ); if
  (princ)
); defun
Kent Cooper, AIA
0 Likes
Message 6 of 22

ronjonp
Mentor
Mentor

Using Kent's code as a base here's my take on it:

(defun c:a2c (/ a e fz mn mx n o p s)
  ;; RJP » 2020-02-21
  (setq fz 1e-4)
  (if (setq s (ssget ":L" '((0 . "*POLYLINE,SPLINE,*ELLIPSE"))))
    (repeat (setq n (sslength s))	; then
      (setq e (ssname s (setq n (1- n))))
      ;; Check that start and end points are 'equal'
      (cond ((and (equal (vlax-curve-getstartpoint e) (vlax-curve-getendpoint e) fz)
		  (not (vla-getboundingbox (setq o (vlax-ename->vla-object e)) 'mn 'mx))
		  (setq p (mapcar 'vlax-safearray->list (list mn mx)))
		  ;; Check that X and Y distance are 'equal' ( square )
		  (equal (setq a (apply '- (mapcar 'car p))) (apply '- (mapcar 'cadr p)) fz)
	     )
	     ;; Create circle using ent layer along with other byobject properties ( if any )
	     (entmakex (append (list '(0 . "CIRCLE")
				     (cons 10 (mapcar '/ (mapcar '+ (car p) (cadr p)) '(2 2 2)))
				     (cons 40 (abs (/ a 2)))
			       )
			       (vl-remove-if-not
				 '(lambda (x) (vl-position (car x) '(6 8 48 62 370 420 430 440)))
				 ;; Linetype, Layer, Linetype Scale, Index Color, Lineweight, TrueColor, ColorBook, Transparency
				 (entget e)
			       )
		       )
	     )
	     ;; Delete ent
	     (entdel e)
	    )
      )
    )
  )
  (princ)
)

 2020-02-21_12-26-40.gif

0 Likes
Message 7 of 22

ronjonp
Mentor
Mentor

On the flip side, here's code to convert circles to polylines.

(defun c:circle2pline (/ c e r s)
  ;; RJP » 2020-02-21
  (if (setq s (ssget ":L" '((0 . "CIRCLE"))))
    (foreach x (vl-remove-if 'listp (mapcar 'cadr (ssnamex s)))
      (setq c (cdr (assoc 10 (setq e (entget x)))))
      (setq r (cdr (assoc 40 e)))
      (entmakex	(append	(list '(0 . "LWPOLYLINE")
			      '(100 . "AcDbEntity")
			      '(100 . "AcDbPolyline")
			      '(90 . 2)
			      '(70 . 1)
			      (cons 10 (mapcar '+ c (list r 0 0)))
			      '(42 . 1.0)
			      (cons 10 (mapcar '- c (list r 0 0)))
			      '(42 . 1.0)
			)
			(vl-remove-if-not
			  '(lambda (x) (vl-position (car x) '(6 8 48 62 370 420 430 440 210)))
			  ;; Linetype, Layer, Linetype Scale, Index Color, Lineweight, TrueColor, ColorBook, Transparency
			  e
			)
		)
      )
      (entdel x)
    )
  )
  (princ)
)
0 Likes
Message 8 of 22

Kent1Cooper
Consultant
Consultant

@ronjonp wrote:

On the flip side, here's code to convert circles to polylines. ....


 

That's really off-topic here, but the same thread I linked to is originally on that very topic [the polygon  to Circle question was actually off-topic], and CirclePolylineSwap.lsp >there< has commands to go in both directions between Circles and circular Polylines [such as DONUT makes].

Kent Cooper, AIA
0 Likes
Message 9 of 22

ronjonp
Mentor
Mentor

@Kent1Cooper wrote:

@ronjonp wrote:

On the flip side, here's code to convert circles to polylines. ....


 

That's really off-topic here ..


Very true .. just had a quick idea and decided to share. Hopefully someone else finds it useful even if I recreated 'your' wheel with shinier rims. 🍻

0 Likes
Message 10 of 22

Kent1Cooper
Consultant
Consultant

@ronjonp wrote:

....

....
;; Check that start and end points are 'equal' (cond ((and (equal (vlax-curve-getstartpoint e) (vlax-curve-getendpoint e) fz) .... ;; Check that X and Y distance are 'equal' ( square ) ....

The (vlax-curve-isClosed) test is better than comparing the start and end points for equality -- far less code, and no fuzz factor required.

 

I would advise against using a test for whether an object's bounding box is square.  To take it to something of an extreme, this regular polygon [yellow hexagon] should "qualify" to be turned into a Circle, but its bounding box [dotted red] is far from square, so your test would not convert it:

HexagonBoundingBox.PNG

and the same principle applies if it has any number of sides that is not a multiple of 4 [I assume from the OP's wording "...with say  100 nodes..." that they're not always that number exactly], unless you use a much larger fuzz factor than a 10,000th  of a drawing unit.  A 98-gon with a "radius" of only 1 drawing unit, drawn in Inscribed mode with the radius point in an orthogonal direction from the center, has a difference in bounding box dimensions of just over one 1,000th  of a drawing unit, and of course that increases with the size, as well as with any reduction of the number of sides.

 

In addition, whatever turned what were presumably Circles into multi-sided polygons could easily distort the proportions -- for example, did it come through something like a .PDF intermediary?  It can't be from simply Exploding a Block as they surmise, because that would not change Circles, unless the Block was unequally scaled, in which case they would become Ellipses, not polygons.

Kent Cooper, AIA
0 Likes
Message 11 of 22

ronjonp
Mentor
Mentor

@Kent1Cooper wrote:

@ronjonp wrote:

....

....
;; Check that start and end points are 'equal' (cond ((and (equal (vlax-curve-getstartpoint e) (vlax-curve-getendpoint e) fz) .... ;; Check that X and Y distance are 'equal' ( square ) ....

The (vlax-curve-isClosed) test is better than comparing the start and end points for equality -- far less code, and no fuzz factor required.


I'd have to disagree, is it far less code but many times we have 'closed' objects that aren't marked as closed so that check fails.

image.png

The 'square' check was mainly based off of the OP's description of a circle made up of many points and can be easily removed. Thanks for the input! 🍻

0 Likes
Message 12 of 22

Kent1Cooper
Consultant
Consultant

@ronjonp wrote:
.... many times we have 'closed' objects that aren't marked as closed so that check fails. ....

True -- I wasn't thinking of the only-visually-"closed" possibility.  In the OP's case, they should be able to say whether such things as they receive them are typically closed in the formal sense, or might not always be.

Kent Cooper, AIA
0 Likes
Message 13 of 22

marko_ribar
Advisor
Advisor

I have to add this note (unfortunately)...

Curves that are to be processed through BLOCKIFY must be exact copies of originals... So this is also true and for circles that OP searches for... I don't know how DWG really looks like, but if some algorithm is to be applied to convert polylines to circles - it has to be really bulletproof to make circles exact copies... None of solutions here provided won't match BLOCKIFY standards... I assume this is also true and for BricsCAD BLOCKIFY - there is no joke with this - there are no fuzz factors... Well, maybe in my routine, but still I haven't considered this when programming and I won't be willing to post my version - only in *.vlx file type... And yet I've revised it in meantime so that it works and in custom UCS assuming that all curves are planar to it (can be above or below UCS, but must is PLANAR)...

Marko Ribar, d.i.a. (graduated engineer of architecture)
0 Likes
Message 14 of 22

Kent1Cooper
Consultant
Consultant

@marko_ribar wrote:

@ronjonp wrote:

If you have a seat of BricsCAD, they have the 'Blockify' command available. Maybe AutoCAD 2021 will add this feature.


I've implemented shortened-simplified version for AutoCAD... Just tested it on concentrical circles ....


 

But did you test it on 100(+/-)-sided polygons, to turn them into  Circles?  That's what the OP is looking for.  I haven't tried it, so I don't know whether it's capable of that, but they're not  starting with Circles.

Kent Cooper, AIA
0 Likes
Message 15 of 22

marko_ribar
Advisor
Advisor

@Kent1Cooper wrote:

@marko_ribar wrote:

@ronjonp wrote:

If you have a seat of BricsCAD, they have the 'Blockify' command available. Maybe AutoCAD 2021 will add this feature.


I've implemented shortened-simplified version for AutoCAD... Just tested it on concentrical circles ....


 

But did you test it on 100(+/-)-sided polygons, to turn them into  Circles?  That's what the OP is looking for.  I haven't tried it, so I don't know whether it's capable of that, but they're not  starting with Circles.


How I understood OP is that he/she has plethora polygons that are circle like and one small group of them present point and are actually few concentric circle like polygons... OP has hundreds of this looking groups and he/she wants to firstly convert all those polygons into circles and then select one group with BLOCKIFY and convert all point concentric circles into blocks making DWG file even more smaller...

 

What I suggest is this :

OP should convert just one small point group of concentric circle looking polygons into concentric circles (if after converting concentric property is lost, he/she should fix that manually)... Then he/she should copybase those group of circles with base point as center of circles... Then he/she should proceed with converting all polygons to circles... Then he/she should get all centers of circles stored in point list... Then he/she should make list without duplicate points - this involves specifying fuzz tolerances (those polygons when converted to circles may not be exactly concentric)... Then he/she should remove all circles/polygons and iterate through point list doing pasteclip his/her concentric group of circles stored in clipboard into points from point list... Finally he/she should apply BLOCKIFY with that first small group of concentric circles (assuming they lie in UCS (above or below but planar) - my new version of *.vlx or in WCS (above or below but planar) - my already posted version of *.vlx)...

Marko Ribar, d.i.a. (graduated engineer of architecture)
0 Likes
Message 16 of 22

marko_ribar
Advisor
Advisor

Here is my new version of just (c:blockify) in *.vlx file format... So if you want to use it with previous functions too, you firstly load old *.vlx and after that this new one (overwriting old definition)...

 

HTH., M.R.

Marko Ribar, d.i.a. (graduated engineer of architecture)
0 Likes
Message 17 of 22

marko_ribar
Advisor
Advisor

Actually, I've just noticed small mistake... Here is correct one...

Marko Ribar, d.i.a. (graduated engineer of architecture)
Message 18 of 22

trevor.bird.au
Advocate
Advocate
Accepted solution

Hi Matthew,

 

Please find my approach to your request below.

 

It will create and insert a coordinate block for each set of concentric circles created from the selected polygons.

 

A new coordinate block will be created for a set of concentric circles if the radii of the concentric circles is different to a previously processed set of concentric circles.

 

I would assume that your drawings with concentric polygons created from another package are probably the same radii and therefore only one coordinate block will be created and inserted at their locations.

 

Without an example drawing to test with, I created my own test drawing (attached) with random radius concentric polygons and individual polygons with various numbers of sides e.g. 31, 100.

 

;;  CirclesFromPolygons.lsp by Trevor Bird
;;
;;  2020-02-22

;;------------------------------------------------------------------------------
(defun c:circlesfrompolygons
  (
    /

    block_handle
    block_name

    Center_wcs_list
    Center_wcs_X
    Center_wcs_Y
    Center_wcs_Z

    circle_center
    circle_normal
    circle_radius

    col_ActiveBlock
    col_Blocks
    col_Block_coordinate
    col_Block_unnamed

    Coordinates_ocs_list
    Coordinates_ocs_var
    Coordinates_wcs_list

    Coordinate_ocs_list
    Coordinate_ocs_var
    Coordinate_wcs_list

    distances_list
    distance_check

    dps__block
    dps__blocks
    dps__circle1
    dps__circle2
    dps__circles
    dps__radii1

    ename_polyline

    fuzz_equal

    list_handles
    list_radii1
    list_radii2
    list_temp

    Normal_list
    Normal_var

    ObjectName
    obj_ACAD
    obj_AD
    obj_BlockRef
    obj_circle
    obj_polygon
    obj_polyline

    polygon_Handle
    polyline_Handle

    ssC
    ss_blockrefs
    ss_Filter
    ss_Polylines
    sv_cvport

    vertex_bulge
    vertex_count
    vertex_index
    vertex_Z
  )
  (setq sv_cvport (getvar 'CVPORT))

  (setq ss_Filter
    (list
      '(0 . "*POLYLINE")

      '(-4 . "<AND")

        '(-4 . "&")
        '(70 . 1)       ;  1 = This is a closed polyline

        '(-4 . "<NOT")  ;  Exclude 3D polylines
          '(-4 . "&=")  ;  8 = This is a 3D polyline
          '(70 . 8)
        '(-4 . "NOT>")

      '(-4 . "AND>")

      (if (= sv_cvport 1)
        (cons 410 (getvar 'CTAB))
        '(410 . "Model")
      );if (= sv_cvport 1)
    );list
  );setq


  (setq ss_Polylines  (ssget ss_Filter))

  (cond
    ( (not ss_Polylines)
      ;;  Do nothing.
    );(not ss_Polylines)


    (ss_Polylines
      (setq obj_ACAD    (vlax-get-acad-object)
            obj_AD      (vlax-get-property obj_ACAD 'ActiveDocument)
            col_Blocks  (vlax-get-property obj_AD 'Blocks)
      );setq

      (if (= sv_cvport 1)
        (setq col_ActiveBlock (vlax-get-property obj_AD 'PaperSpace))
        (setq col_ActiveBlock (vlax-get-property obj_AD 'ModelSpace))
      );if (= sv_cvport 1)

      (setq dps__circles  nil
            fuzz_equal    1.0e-4
            ssC           -1
      );setq

      (repeat (sslength ss_Polylines)
        (setq ename_polyline        (ssname ss_Polylines (setq ssC  (1+ ssC)))
              obj_polyline          (vlax-ename->vla-object ename_polyline)

              polyline_Handle       (vlax-get-property obj_polyline 'Handle)

              ObjectName            (vlax-get-property obj_polyline 'ObjectName)

              Normal_var            (vlax-get-property obj_polyline 'Normal)
              Normal_list           (vlax-safearray->list (vlax-variant-value Normal_var))

              Coordinates_ocs_var   (vlax-get-property obj_polyline 'Coordinates)
              Coordinates_ocs_list  (vlax-safearray->list (vlax-variant-value Coordinates_ocs_var))

              Coordinates_wcs_list  nil
        );setq


        (cond
          ( (= ObjectName "AcDbPolyline")
            ;;  Lightweight Polyline
            (setq vertex_count  (/ (length Coordinates_ocs_list) 2)
                  vertex_Z      (vlax-get-property obj_Polyline 'Elevation)
            );setq
          )

          ( (or (= ObjectName "AcDb2dPolyline")
                (= ObjectName "AcDb3dPolyline")
            );or
            ;;  Heavy Polyline
            (setq vertex_count  (/ (length Coordinates_ocs_list) 3)
                  vertex_Z      nil
            );setq
          )
        );cond


        (setq vertex_index  0)

        (while (< vertex_index vertex_count)
          (setq Coordinate_ocs_var  (vlax-get-property obj_polyline 'Coordinate vertex_index)
                Coordinate_ocs_list (vlax-safearray->list (vlax-variant-value Coordinate_ocs_var))
                vertex_bulge        (vlax-invoke-method obj_polyline 'GetBulge vertex_index)
                vertex_index        (1+ vertex_index)
          );setq


          (cond
            ( (not (zerop vertex_bulge))
              ;;  Quit while loop.
              (setq vertex_index          vertex_count
                    Coordinates_wcs_list  nil
              );setq
            );(not (zerop vertex_bulge))

            ( (zerop vertex_bulge)
              (if vertex_Z
                (setq Coordinate_ocs_list (append Coordinate_ocs_list (list vertex_Z)))
              );if vertex_Z

              (setq Coordinate_wcs_list   (trans Coordinate_ocs_list ename_polyline 0)
                    Coordinates_wcs_list  (append Coordinates_wcs_list (list Coordinate_wcs_list))
              );setq
            );(zerop vertex_bulge)
          );cond
        );repeat vertex_count




        (cond
          ( (not Coordinates_wcs_list)
            ;;  Do not convert polygon to a circle.
            ;;  Polygon has vertices with bulges.
          );(not Coordinates_wcs_list)

          (Coordinates_wcs_list
            (setq Center_wcs_X    (/ (apply '+ (mapcar 'car Coordinates_wcs_list)) (length Coordinates_wcs_list))
                  Center_wcs_Y    (/ (apply '+ (mapcar 'cadr Coordinates_wcs_list)) (length Coordinates_wcs_list))
                  Center_wcs_Z    (/ (apply '+ (mapcar 'caddr Coordinates_wcs_list)) (length Coordinates_wcs_list))

                  Center_wcs_list (list Center_wcs_X Center_wcs_Y Center_wcs_Z)

                  distances_list  (mapcar (function (lambda ( _point ) (distance Center_wcs_list _point))) Coordinates_wcs_list)

                  ;;  distance_check is the radius of the circle.
                  distance_check  (car distances_list)
                  distances_list  (cdr distances_list)

                  distances_list  (vl-remove-if (function (lambda ( _distance ) (equal _distance distance_check fuzz_equal))) distances_list)
            );setq


            (cond
              ( (not distances_list)
                ;;  All distances from center of polygon to vertices are equal.
                (setq circle_radius distance_check)

                ;;  Determine if polygon has the same center and the same normal as other polygons i.e. concentric.
                (setq list_temp
                  (vl-remove-if-not
                    (function
                      (lambda ( _list1 )
                        (setq circle_center (cdr (assoc "Center" _list1))
                              circle_normal (cdr (assoc "Normal" _list1))
                        );setq

                        (and
                          (equal Center_wcs_X (car circle_center) fuzz_equal)
                          (equal Center_wcs_Y (cadr circle_center) fuzz_equal)
                          (equal Center_wcs_Z (caddr circle_center) fuzz_equal)

                          (equal (car Normal_list) (car circle_normal) fuzz_equal)
                          (equal (cadr Normal_list) (cadr circle_normal) fuzz_equal)
                          (equal (caddr Normal_list) (caddr circle_normal) fuzz_equal)
                        );and
                      );lambda
                    );function

                    dps__circles
                  );vl-remove-if-not
                );setq


                (cond
                  ( (not list_temp)
                    ;;  Add to list.
                    ;;  Include Handle of source polygon with its radius (distance_check) to allow querying properties of source polygon when creating coordinate block of concentric circles.
                    (setq dps__circles
                      (append dps__circles
                        (list
                          (list
                            (cons "Center" Center_wcs_list)
                            (cons "Normal" Normal_list)
                            (list "radii" (cons polyline_Handle distance_check))
                          );list
                        );list
                      );append
                    );setq
                  );(not list_temp)


                  ( (setq dps__circle1  (car list_temp))
                    (setq dps__radii1  (cdr (assoc "radii" dps__circle1))
                          list_radii1  (mapcar 'cdr dps__radii1)
                    );setq

                    (if (not (member circle_radius list_radii1))
                      (setq dps__radii1  (append dps__radii1 (list (cons polyline_Handle circle_radius))))
                    );if (not (member circle_radius list_radii1))

                    (setq dps__circle2  (subst (cons "radii" dps__radii1) (assoc "radii" dps__circle1) dps__circle1)
                          dps__circles  (subst dps__circle2 dps__circle1 dps__circles)
                    );setq
                    ;;  dps__circle2  =  (("Center" 8543.17 3092.91 381.967) ("Normal" 0.610589 0.0 0.791948) ("radii" ("44D" . 569.089) ("448" . 329.114)))
                  );dps__circle1
                );cond
              );(not distances_list)


              (distances_list
                ;;  Not all distances from center of polygon to vertices are equal.
              );distances_list
            );cond
          );Coordinates_wcs_list
        );cond


        (vlax-release-object obj_polyline)
      );repeat (sslength ss_Polylines)




      ;;  Process dps__circles
      (cond
        ( (not dps__circles)
          ;;  No circles from polygons determined.
        );(not dps__circles)

        (dps__circles
          (setq ss_blockrefs  (ssadd)
                dps__blocks   nil
          );setq

          (foreach fe__list1 dps__circles
                  ;;  Center_wcs_list will be the insertion point of the block.
            (setq Center_wcs_list (cdr (assoc "Center" fe__list1))
                  Normal_list     (cdr (assoc "Normal" fe__list1))
                  dps__radii1     (cdr (assoc "radii" fe__list1))
                  list_radii1     (mapcar 'cdr dps__radii1)
            );setq


            ;;  <!--  Determine if a coordinate block has already been created for this set of concentric circles.
            (setq list_temp
              (vl-remove-if-not
                (function
                  (lambda ( _list2 )
                    (setq block_name  (cdr (assoc "Block" _list2))
                          list_radii2 (cdr (assoc "radii" _list2))
                    );setq
                    (equal list_radii1 list_radii2 fuzz_equal)
                  );lambda
                );function

                dps__blocks
              );vl-remove-if-not
            );setq


            (cond
              ( (not list_temp)
                ;;  Add to list.
                ;;  Include Handle of source polygon with its radius (distance_check) to allow querying properties of source polygon when creating block of concentric circles.
                ;;  Create an anonymous (unamed) block to generate a new Handle which will be used as a suffix for the new blocks.
                (setq col_Block_unnamed (vlax-invoke-method col_Blocks 'Add (vlax-3D-point '(0.0 0.0 0.0)) "*U")
                      block_handle      (vlax-get-property col_Block_unnamed 'Handle)
                );setq

                (vlax-invoke-method col_Block_unnamed 'Delete)

                ;;  Create a new "Coordinate_" block that will contain the concentric circles.
                (setq block_name            (strcat "Coordinate_" block_handle)
                      col_Block_coordinate  (vlax-invoke-method col_Blocks 'Add (vlax-3D-point '(0.0 0.0 0.0)) block_name)
                );setq


                ;;  Add circles to block.
                (foreach fe__list2  dps__radii1
                  (setq polygon_Handle  (car fe__list2)
                        circle_radius   (cdr fe__list2)
                        obj_polygon     (vlax-invoke-method obj_AD 'HandleToObject polygon_Handle)
                  );setq

                  (setq obj_circle  (vlax-invoke-method col_Block_coordinate 'AddCircle (vlax-3D-point '(0.0 0.0 0.0)) circle_radius))
                    (vlax-put-property obj_circle 'Normal (vlax-get-property obj_polygon 'Normal))
                    (vlax-put-property obj_circle 'Color acByBlock)
                    (vlax-put-property obj_circle 'Linetype "BYBLOCK")

                  (vlax-release-object obj_circle)

                  (vlax-release-object obj_polygon)
                );fe__list2


                (setq dps__blocks
                  (append dps__blocks
                    (list
                      (list
                        (cons "Block" block_name)
                        (cons "Normal" Normal_list)
;                        (cons "radii" dps__radii1)
                        (cons "radii" list_radii1)
                      );list
                    );list
                  );append
                );setq
              );(not list_temp)


              ( (setq dps__block  (car list_temp))
                (setq block_name  (cdr (assoc "Block" dps__block)))
              );dps__block
            );cond
            ;;  -->


            ;;  <!--  Insert coordinate block.
            (setq obj_BlockRef
              (vlax-invoke-method col_ActiveBlock
                'InsertBlock
                  (vlax-3D-point '(0.0 0.0 0.0))
                    block_name
                      1.0
                        1.0
                          1.0
                            0.0
              );'InsertBlock
            );setq
            (vlax-put-property obj_BlockRef 'Color acByLayer)

            (vlax-put-property obj_BlockRef 'Normal (vlax-3D-point Normal_list))
            (vlax-put-property obj_BlockRef 'InsertionPoint (vlax-3D-point Center_wcs_list))

            (ssadd (vlax-vla-object->ename obj_BlockRef) ss_blockrefs)

            (vlax-release-object obj_BlockRef)
            ;;  -->


            ;;  <!--  Delete source polygons.
            (setq list_handles  (mapcar 'car dps__radii1))

            (foreach fe__handle list_handles
              (setq obj_polygon (vlax-invoke-method obj_AD 'HandleToObject fe__handle))

              (vlax-invoke-method obj_polygon 'Delete)
              (vlax-release-object obj_polygon)
            );fe__handle
            ;;  -->
          );fe__list1


          ;;  Grip and select.
          (sssetfirst nil ss_blockrefs)
        );dps__circles
      );cond




      (vlax-release-object col_ActiveBlock)
      (vlax-release-object col_Blocks)
      (vlax-release-object obj_ACAD)
      (vlax-release-object obj_AD)
    );ss_Polylines
  );cond

  (princ)
);c:circlesfrompolygons


;;------------------------------------------------------------------------------
(princ "\nCirclesFromPolygons loaded.  Start command with CIRCLESFROMPOLYGONS.")
(princ)

CirclesFromPolygons.gif

Regards,

Trevor

Message 19 of 22

barry2104
Collaborator
Collaborator

This code seems to work quite well!

Also works to turn multiple (offset) jagged circles into a block like I need it to. Since my drawing has say 300 of these coordinate points in it, I'm not sure if I can get everything converted in one go or whether I have to do the 300 commands & clicks?

@Kent1CooperI tried your code on one of my cases but it didn't seem to work - not sure why. Then I created a basic octagon and tried your lisp again, and that seemed to work. I checked the differences between the octagon and my polygon and couldn't see any problems... each were closed polylines and all segments were of equal length

Running AutoCAD Architecture 2020, in German
0 Likes
Message 20 of 22

trevor.bird.au
Advocate
Advocate

Hi Matthew,

 

You can select all the polygons together in your drawing and the code determines if there are concentric polygons which will have the same center point.

A coordinate block will be inserted at each single polygon or concentric polygon set i.e. there will be individual insertions.

 

Regards,

Trevor

0 Likes