Any lisp program for creating boundary for 2d solid objects

Any lisp program for creating boundary for 2d solid objects

Anonymous
Not applicable
2,315 Views
9 Replies
Message 1 of 10

Any lisp program for creating boundary for 2d solid objects

Anonymous
Not applicable

In my autocad drawing there are lot of 2d solid objects for which i want to make boundary.

0 Likes
2,316 Views
9 Replies
Replies (9)
Message 2 of 10

Kent1Cooper
Consultant
Consultant

Put something like "extract linetype definition" or similar wording into the "Search the Community" window, and you'll find several threads on the subject, with links to routines that do that.

Kent Cooper, AIA
0 Likes
Message 3 of 10

Kent1Cooper
Consultant
Consultant

[Never mind that -- replying to a different topic, and too late to edit it....]

 

Are you talking about converting individual 2D Solid entities into Polyline boundaries of their shapes?  Or something more collective?  Post an image or sample drawing -- whatever you mean, it doesn't sound difficult.

Kent Cooper, AIA
0 Likes
Message 4 of 10

Kent1Cooper
Consultant
Consultant

@Kent1Cooper wrote:

.... 

Are you talking about converting individual 2D Solid entities into Polyline boundaries of their shapes? ....


If that's the idea, in simplest terms you can do this:

(defun C:2DS2P ; = 2D Solid {to} Polyline
  (/ ss n sol sdata)
  (if (setq ss (ssget ":L" '((0 . "SOLID"))))
    (repeat (setq n (sslength ss))
      (setq
        sol (ssname ss (setq n (1- n)))
        sdata (entget sol)
      ); setq
      (command "_.pline"
        (cdr (assoc 10 sdata))
        (cdr (assoc 11 sdata))
        (cdr (assoc 13 sdata))
        (cdr (assoc 12 sdata)); [12 & 13 are the same for 3-sided Solids]
        "_close"
        "_.erase" sol ""
      ); command
    ); repeat
  ); if
  (princ)
); defun

BUT if that's what you're after, it needs further enhancement.  It doesn't yet control for possible running Object Snap [turn that off to test it].  Nor does it work right on Solids drawn in other-than-parallel-to-the-World Coordinate Systems, if you might have any of those.  Nor does it account for the difference between 3-sided and 4-sided Solids -- it will work  on 3-sided ones, but will result in Polylines having coincident vertices and zero-length segments, which [depending on what you want to do with the resulting Polylines] could sometimes cause problems.  All those things can be dealt with easily enough, but first see whether the general idea is what you're after.

 

Kent Cooper, AIA
0 Likes
Message 5 of 10

Kent1Cooper
Consultant
Consultant

@Kent1Cooper wrote:

@Kent1Cooper wrote:

.... 

Are you talking about converting individual 2D Solid entities into Polyline boundaries of their shapes? ....


If that's the idea, in simplest terms you can do this:

....

BUT ....  It doesn't yet control for possible running Object Snap....  Nor does it work right ... in other-than-parallel-to-the-World Coordinate Systems....  Nor does it account for the difference between 3-sided and 4-sided Solids....  All those things can be dealt with easily enough, but first see whether the general idea is what you're after.

 


The attached 2DSolidToPline.lsp with its 2DS2P command takes care of those things.

 

There's a peculiarity about how entity data for 2D Solids is stored that comes out in a strange way for those not in or parallel to the WCS, different from the way [for example] other-UCS Polyline data is stored.  I haven't yet found a way to account for it reliably except by forcing it to start in the WCS, and shift UCS from there for each Solid.  I tried a variety of (trans)-based approaches, etc., but haven't hit the right one yet to avoid shifting to the WCS first -- if/when I figure that out, it will avoid the saving/restoring/deleting of a dedicated UCS name that's part of this routine.  But in the meantime, this seems to work in limited testing.  See comments at the top of the file.

Kent Cooper, AIA
0 Likes
Message 6 of 10

_gile
Consultant
Consultant

@Kent1Cooper wrote:

There's a peculiarity about how entity data for 2D Solids is stored that comes out in a strange way for those not in or parallel to the WCS, different from the way [for example] other-UCS Polyline data is stored.  I haven't yet found a way to account for it reliably except by forcing it to start in the WCS, and shift UCS from there for each Solid.  I tried a variety of (trans)-based approaches, etc., but haven't hit the right one yet to avoid shifting to the WCS first -- if/when I figure that out, it will avoid the saving/restoring/deleting of a dedicated UCS name that's part of this routine.  But in the meantime, this seems to work in limited testing.  See comments at the top of the file.


Both SOLID and LWPOLYLINE are 2d entities which coordinates are defined in the entity OCS.

 

You can use the entity ename or the entity 210 group code value with the trans function.

 

;; get the dxf data of a SOLID
(setq elst (entget solid))

;; transform the first vertex to WCS coordinates
(trans (cdr (assoc 10 elst)) solid 0)

;; transform the second vertex to current UCS coordinates
(trans (cdr (assoc 11 elst)) (cdr (assoc 210 elst)) 1)

With LWPOLYLINE entities, you have to pay attention to the elevation of the polyline because coordinates are 2d only.

 

;; get the dxf data of a LWPOLYLINE
(setq elst      (entget pline)
      vertex    (cdr (assoc 10 elst))
      elevation (cdr (assoc 38 elst))
)
;; transform the first vertex to WCS coordinates
(trans (list (car vertex) (cadr vertex) elevation) pline 0)


Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes
Message 7 of 10

marko_ribar
Advisor
Advisor

Although @_gile answered, there is no need for UCS manipulations... Analyze this simple snippet :

 

(defun C:2DS2P ; = 2D Solid(s) {to} Polyline(s)
  ( / ss i sol solx )
  (if (setq ss (ssget "_:L" '((0 . "SOLID"))))
    (repeat (setq i (sslength ss))
      (setq sol (ssname ss (setq i (1- i))))
      (setq solx (entget sol))
      (entmake
        (append
          (list
            '(0 . "LWPOLYLINE")
            '(100 . "AcDbEntity")
            '(100 . "AcDbPolyline")
            (cons 90 (if (equal (cdr (assoc 12 solx)) (cdr (assoc 13 solx)) 1e-4) 3 4))
            (cons 70 (1+ (* 128 (getvar 'plinegen))))
            (cons 38 (caddr (cdr (assoc 10 solx))))
          )
          (if (equal (cdr (assoc 12 solx)) (cdr (assoc 13 solx)) 1e-4)
            (list
              (cons 10 (cdr (assoc 10 solx)))
              (cons 10 (cdr (assoc 11 solx)))
              (cons 10 (cdr (assoc 13 solx)))
            )
            (list
              (cons 10 (cdr (assoc 10 solx)))
              (cons 10 (cdr (assoc 11 solx)))
              (cons 10 (cdr (assoc 13 solx)))
              (cons 10 (cdr (assoc 12 solx)))
            )
          )
          (list (assoc 210 solx))
        )
      )
      (entdel sol)
    )
  )
  (princ)
)

Still I am under impression that OP actually don't want simple 2DSOLID replacement, but complex boundary of SOLID hatches... For that he'll need :

 

(vl-cmdf "_.-HATCHEDIT" hatchename "_B" "_P" "_N") ;;; last "_N" is associativity
(entdel hatchename)
Marko Ribar, d.i.a. (graduated engineer of architecture)
0 Likes
Message 8 of 10

mehsan
Advocate
Advocate

Yes, What ever the shapes i have i want a bounday around them or polyline around them.

thanks 

0 Likes
Message 9 of 10

Sea-Haven
Mentor
Mentor

This has been asked many times, post an image or dwg showing what you want a boundary around. You may need to look at "Super Boundary".

0 Likes
Message 10 of 10

mehsan
Advocate
Advocate

Yes , what ever the shape is i need a boundary line around them.

thanks 

0 Likes