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

Solid object to Polyline

24 REPLIES 24
Reply
Message 1 of 25
JMongi5967
28297 Views, 24 Replies

Solid object to Polyline

Does anyone have a lisp routine or a way to convert 2D solid objects to a closed polyline. Or at least a way to draw a polyline around the perimeter of the 2D solid object. Any help would be appreciated.
24 REPLIES 24
Message 2 of 25
Anonymous
in reply to: JMongi5967

Try the "boundary" command


style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
Does
anyone have a lisp routine or a way to convert 2D solid objects to a closed
polyline. Or at least a way to draw a polyline around the perimeter of the 2D
solid object. Any help would be appreciated.
Message 3 of 25
Anonymous
in reply to: JMongi5967

Easy enough.


(defun c:outlinesolid(/ solid pt1 pt2 pt3 pt4)
(prompt "\nPlease select the solid you want to outline.")
(WHILE (NOT (setq solid (ssget ":S" '((0 . "SOLID")))))
(prompt "\nPlease select the solid you want to outline."))
(SETQ pt1 (cdr (assoc 10 (entget (ssname solid 0))))
pt2 (cdr (assoc 11 (entget (ssname solid 0))))
pt3 (cdr (assoc 12 (entget (ssname solid 0))))
pt4 (cdr (assoc 13 (entget (ssname solid 0))))
);SETQ
(COMMAND "_.PLINE" PT1 PT2 PT4 PT3 "C")
(command ".erase" solid "")
);DEFUN

You can comment out or delete the line
(command ".erase" solid "")
if all you want to do is erase it.

"JMongi5967" wrote in message
news:f08048c.-1@WebX.maYIadrTaRb...
Does anyone have a lisp routine or a way to convert 2D solid objects to a
closed polyline. Or at least a way to draw a polyline around the perimeter
of the 2D solid object. Any help would be appreciated.
Message 4 of 25
JMongi5967
in reply to: JMongi5967

Alex, Lisp routine works great. Thankyou very much.
Message 5 of 25
adamchr
in reply to: JMongi5967

bumping an old thread...hoping for new info

 

same issue

(i have a converted .dgn that has solids in it representing columns that i'd like to make outlines)

 

but using autocad lt for mac 2013

 

is there a command now that allows a 2d solid to be converted to a polyline? or even just line entities?

 

thanks up front!

 

adam

Message 6 of 25
hmsilva
in reply to: adamchr

Hi Adam,

firstly, I'm not a LT guy nor a mac user...

 

I think AutoCAD LT have the 'region' command ( LT help files have the command ), if so, you can use the region command to convert the solid objects to regions, then explode the regions to lines.

 

Hope that helps
Henrique

EESignature

Message 7 of 25
adamchr
in reply to: hmsilva

hmsilva, thanks for your suggestion

it unfortunately didn't work for me

"region" is in LT, but didn't do what you'd hoped...

it just gave me "0 regions created"

 

Adam

 

[edit] just found it

 

explode the solid

THEN, region the remaining solid to get the polyline

 

so, THANKS MUCH! in the end!

Message 8 of 25
hmsilva
in reply to: adamchr


@adamchr wrote:

hmsilva, thanks for your suggestion

it unfortunately didn't work for me

"region" is in LT, but didn't do what you'd hoped...

it just gave me "0 regions created"

 

Adam


If possible, attach a sample dwg with a few 'solids'.

 

Henrique

EESignature

Message 9 of 25
adamchr
in reply to: hmsilva

see edited note above

 

elements were blocks and needed to be exploded first

 

then region worked as suggested!

Message 10 of 25
hmsilva
in reply to: adamchr

You're welcome, Adam.
I'm glad it worked.

Henrique

EESignature

Message 11 of 25
CrashCramer
in reply to: JMongi5967

Hello everybody,

First of all, I'm really sorry for bumping this old thread, so please forgive me.

For a current project, I've got drawings that use solid objects (called "Körper" in the German installation of AutoCAD I use) as floor plan contours. I'd like to convert these objects to lines or polylines.

 

I initially found the listing at:

http://autocadtips1.com/2013/12/28/autolisp-convert-2d-solid-to-polyline-outline/

 

I loaded the LISP file above into AutoCAD Architecture 2015. When entering the outlinesolid command, it will show an error message:

 

Aufrufen von (command) aus *Fehler* nicht möglich, ohne vorheriges Aufrufen von (*push-error-using-command*).
Konvertieren von (command)-Aufrufen in (command-s) wird empfohlen.

Unfortunately I can't simply explode these solids.

 

I've also tried some of the listings found here:

http://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/lisp-help/m-p/783547/highlight/true#M...

But they did not work for me, since they resulted in the same error message

 

Any help will be highly appreciated.

 

Kind regards.

Message 12 of 25
hmsilva
in reply to: CrashCramer


@Maruku wrote:

Hello everybody,

First of all, I'm really sorry for bumping this old thread, so please forgive me.

For a current project, I've got drawings that use solid objects (called "Körper" in the German installation of AutoCAD I use) as floor plan contours. I'd like to convert these objects to lines or polylines.

 

I initially found the listing at:

http://autocadtips1.com/2013/12/28/autolisp-convert-2d-solid-to-polyline-outline/

 

I loaded the LISP file above into AutoCAD Architecture 2015. When entering the outlinesolid command, it will show an error message:

 

Aufrufen von (command) aus *Fehler* nicht möglich, ohne vorheriges Aufrufen von (*push-error-using-command*).
Konvertieren von (command)-Aufrufen in (command-s) wird empfohlen.

Unfortunately I can't simply explode these solids.

 

I've also tried some of the listings found here:

http://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/lisp-help/m-p/783547/highlight/true#M...

But they did not work for me, since they resulted in the same error message

 

Any help will be highly appreciated.

 

Kind regards.


Hello Maruku and welcome to the Autodesk Community!

 

If possible attach a sample dwg with one or two "Körper".

 

Henrique

EESignature

Message 13 of 25
G_WIDER
in reply to: hmsilva

Hallo Henrique,

 

attached an example file named "koerper.dwg".

Thanx Forehand for any hint.

 

Best regards

George

__________________________________________________________________________________

Georg Wider
Mitarbeiter Support bei

Bild

Message 14 of 25
hmsilva
in reply to: G_WIDER


@G_WIDER wrote:

Hallo Henrique,

 

attached an example file named "koerper.dwg".

Thanx Forehand for any hint.

 

Best regards

George


Hello George,

try this...

;; by Jeff Mishler
;; http://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/convert-solid-to-hatch/m-p/1218153#M170723

(defun get_space ()
    (if (= (getvar "cvport") 1)
        (vla-get-paperspace (vla-get-activedocument (vlax-get-acad-object)))
        (vla-get-modelspace (vla-get-activedocument (vlax-get-acad-object)))
    )
)

(defun convert2dsolids (/ 2dcoords coords count hatch obj pline space ss)
    (and (setq ss (ssget '((0 . "SOLID"))))
         (setq count -1)
         (setq space (get_space))
         (while (< (setq count (1+ count)) (sslength ss))
             (setq obj (vlax-ename->vla-object (ssname ss count)))
             (setq coords (vlax-get obj 'coordinates))
             (setq 2dcoords (list (car coords) (cadr coords)))
             (setq coords (cdr (cdr (cdr coords))))
             (setq 2dcoords (append 2dcoords (list (car coords) (cadr coords))))
             (setq coords (cdr (reverse (cdr (cdr (cdr coords))))))
             (setq 2dcoords (append 2dcoords (list (cadr coords) (car coords))))
             (setq coords (reverse coords))
             (setq 2dcoords (append 2dcoords (list (car coords) (cadr coords))))
             (setq pline (vlax-invoke space 'addlightweightpolyline 2dcoords))
             (vla-put-closed pline :vlax-true)
             ;(setq hatch (vlax-invoke space 'addhatch acHatchPatternTypePredefined "SOLID" :vlax-true))
             ;(vlax-invoke hatch 'appendouterloop (list pline))
             (vla-put-color pline (vla-get-color obj))
             ;(vla-put-color hatch (vla-get-color obj))
             (vla-put-layer pline (vla-get-layer obj))
             ;(vla-put-layer hatch (vla-get-layer obj))
             (vla-delete obj)
         )
    )
)
(defun c:cd () (convert2dsolids) (princ))

 

Hope this helps,
Henrique

EESignature

Message 15 of 25
G_WIDER
in reply to: hmsilva

Hi Henrique,

 

thank you very much. I will try it next time. Meanwhile a got a hint of Alfred he reaired my old version to this new one:

 

;;; Select a 2D solid and this will delete the solid and replace its outline with a polyline
;;; http://forums.autodesk.com/t5/Visual-LISP-AutoLISP-and-General/Solid-object-to-Polyline/td-p/783079
;;; Posted By: Schamenek, Alex

(defun c:outlinesolid(/ solid pt1 pt2 pt3 pt4)
   (prompt "\nPlease select the solid you want to outline.")
   (WHILE (NOT (setq solid (ssget "_:S:E" '((0 . "SOLID")))))
      (prompt "\nPlease select the solid you want to outline."))
      (SETQ pt1 (cdr (assoc 10 (entget (ssname solid 0))))
         pt2 (cdr (assoc 11 (entget (ssname solid 0))))
         pt3 (cdr (assoc 12 (entget (ssname solid 0))))
         pt4 (cdr (assoc 13 (entget (ssname solid 0))))
       );SETQ
   (COMMAND "_.PLINE" PT1 PT2 PT4 PT3 "_C")
   (command "_.erase" solid "")
);DEFUN

 

That is working also fine because he corrected following Sequenz:

 

Old: (ssget ":S" '((0 . "SOLID") to

New:  (ssget "_:S:E" '((0 . "SOLID")

 

I attached it as a file. Now it is working fine in every language.

 

Thank you very much

George

__________________________________________________________________________________

Georg Wider
Mitarbeiter Support bei

Bild

Message 16 of 25
hmsilva
in reply to: G_WIDER

You're welcome, Gerge!
Glad you got it working.

Henrique

EESignature

Message 17 of 25
Kent1Cooper
in reply to: JMongi5967

Solutions offered so far have some drawbacks that I notice [except @hmsilva's offering from Jeff Mishler in Post 14 doesn't have all of them]:

 

They [except Jeff's] can be thrown off by running Osnap modes.

 

For 3-sided Solids, they result in Polylines with coincident vertices, which can cause problems with certain other operations and custom routines.  3-sided ones have two causes: from hitting Enter when asked for the 4th corner, in which case the 3rd & 4th [the 12- & 13-code entries in entity data] are the same; or from continuing in the SOLID command after making a 3-sided one like that, in which case the 1st & 2nd [the 10- & 11-code entries] are the same, since in continuations, those coincide with the 12- & 13-code entries of the previous Solid.

 

It takes two U's to undo them [one to undo the Erasing of the Solid, and one for the drawing of the Polyline perimeter].  Jeff's has a variant problem, since it doesn't use (command) functions but has no Undo begin/end wrapping -- if you use U right after doing it, the Polylines all revert back to their original Solids AND the last command before that is also undone!

 

They [except Jeff's] allow selection of only one Solid per running of the command.

 

They allow selection of Solids on locked Layers, so they can then draw the Polyline perimeter, but can't erase the Solid.  In Jeff's with multiple selection, if any Solid on a locked Layer is not the last one in the selection, it won't convert any others after it runs into the error about the locked one.

 

They don't have *error* handling.

 

Attached is SolidsToPolylines.lsp with its S2P command, which overcomes all of those drawbacks.  See further comments in the file.

Kent Cooper, AIA
Message 18 of 25
mehboob.ali
in reply to: Kent1Cooper

I want to convert 3d solid (pipe)  to 3d lines any lisp there to do ?

Message 19 of 25
Kent1Cooper
in reply to: mehboob.ali


@mehboob.ali wrote:

I want to convert 3d solid (pipe)  to 3d lines any lisp there to do ?


This is about 2D Solid objects, those made with the SOLID command, which are an entirely different animal  from 3D Solids.  I suggest you Search the Forums first, and if you don't find anything like what you want, start a new thread.  In it, describe [or include an image or sample drawing showing] in what way  you would want "3d lines" to represent the original pipe shape [parallel along the surface?  how many?  inside and outside?  include something at the ends, and if so, Circles rather than lines?  etc.], and also what "3d lines" should be  [ordinary Lines? 3DPolylines? something else?].

Kent Cooper, AIA
Message 20 of 25
peterfarkas
in reply to: Anonymous

Hi

 

I am trying to use this lisp routine, but it somehow returns wrong coordinates, thus drawing the outlines somewhere else in the drawing.

 

Also weird that some it is not even a constant offset, but some outlines are drawn the right distance from one another, but others are completely at a different location.

 

I included a screencast.

 

I also checked one vertex of a solid and the properties bar says the coordinates are:

-101421,63   59591,75

While the lisp routine for the same solid vertex returns:

319131,0     620230,0

 

Would greatly appreciate some help.

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

Post to forums  

Autodesk Design & Make Report

”Boost