code to create 3DPOLY from 3D LINes

code to create 3DPOLY from 3D LINes

autoid374ceb4990
Collaborator Collaborator
1,306 Views
39 Replies
Message 1 of 40

code to create 3DPOLY from 3D LINes

autoid374ceb4990
Collaborator
Collaborator

I have a routine that creates a series of 3d LINEs for the boundary of a group of 3DFACEs.

Does anyone have an autoLisp (not visual lisp, I am using R14) that would join the 3D LINEs into  a 3D POLYINE?  The 3D LINEs are not in any order.

boundary.jpg

0 Likes
Accepted solutions (2)
1,307 Views
39 Replies
Replies (39)
Message 2 of 40

Sea-Haven
Mentor
Mentor

A couple of ideas, this expects that all the lines are in same direction and in sequence.

 

(defun c:wow ( / ss lst ent pt)
(setq ss (ssget '((0 . "LINE"))))
(setq lst '())
(repeat (setq x (sslength ss))
  (setq ent (entget (ssname ss (setq x (1- x)))))
  (setq  lst (cons (cdr (assoc 10 ent)) lst))
)

(entmake '((0 . "POLYLINE") (70 . 9)))
(foreach pt lst (entmake (list '(0 . "VERTEX") '(70 . 32) (cons 10 pt))))
(entmake '((0 . "SEQEND")))

(princ)
)

A good idea is post a sample dwg use say WBLOCK to export your 3d lines. 

0 Likes
Message 3 of 40

autoid374ceb4990
Collaborator
Collaborator

Well the lines are not in the same direction and not in sequence, if you define sequence as created sequentially.  drawing attached.

 

0 Likes
Message 4 of 40

chriscowgill7373
Mentor
Mentor

It is unfortunate that you are stuck on almost 30 year old software. The JOIN command would be able to handle it in newer versions. Have you tried the PLJOIN Bonus tool to make sure it didnt work?

Couldnt you just select all the lines, obtain the list of coordinates, sort that list and the remove duplicates and start the command feeding the filtered list into it?  Or, were those functions not available in R14?  It is very difficult to look at a task like this because it cant be tested.  Maybe it works similar to lisp in LT or in MAC, so someone with one of those software might be able to write a code and test it.


Christopher T. Cowgill, P.E.

AutoCAD Certified Professional
Civil 3D Certified Professional
Civil 3D 2026 on Windows 11

Please select the Accept as Solution button if my post solves your issue or answers your question.

Message 5 of 40

autoid374ceb4990
Collaborator
Collaborator

@chriscowgill7373 wrote:

It is unfortunate that you are stuck on almost 30 year old software. The JOIN command would be able to handle it in newer versions. Have you tried the PLJOIN Bonus tool to make sure it didnt work?

Couldnt you just select all the lines, obtain the list of coordinates, sort that list and the remove duplicates and start the command feeding the filtered list into it?  Or, were those functions not available in R14?  It is very difficult to look at a task like this because it cant be tested.  Maybe it works similar to lisp in LT or in MAC, so someone with one of those software might be able to write a code and test it.


You are probably correct.  I have found several PLJOIN type lisp routines, but of course they will not work with my old R14. Guess I will have to write my own.

0 Likes
Message 6 of 40

marko_ribar
Advisor
Advisor

Here, try these 2 variants... First one should be much faster... Untested though (quickly written)...

 

(defun c:lins23dpoly ( / ss i lil lix liln li lii )
  (if (setq ss (ssget (list (cons 0 "LINE"))))
    (progn
      (repeat (setq i (sslength ss))
        (setq lil (cons (list (cdr (assoc 10 (setq lix (entget (ssname ss (setq i (1- i))))))) (cdr (assoc 11 lix))) lil))
      )
      (setq liln (cons (car lil) liln))
      (while (setq li (car lil))
        (setq lil (cdr lil))
        (setq lii (vl-some (function (lambda (x) (if (or (equal (cadr li) (car x) 1e-8) (equal (cadr li) (cadr x) 1e-8)) x))) lil))
        (cond
          ( (and lii (equal (cadr li) (car lii) 1e-8))
            (setq liln (cons lii liln) lil (cons lii (vl-remove lii lil)))
          )
          (  lii
            (setq liln (cons (reverse lii) liln) lil (cons (reverse lii) (vl-remove lii lil)))
          )
        )
      )
      (entmake (list (cons 0 "POLYLINE") (cons 70 9)))
      (foreach pt (mapcar (function car) liln)
        (entmake (list (cons 0 "VERTEX") (cons 70 32) (cons 10 pt)))
      )
      (entmake (list (cons 0 "SEQEND")))
    )
  )
  (princ)
)

(defun c:lins23dpoly-vanilla ( / _reverse _vl-some _vl-remove ss i lil lix liln li lii )

  (defun _reverse ( lst / r )
    (while lst
      (setq r (cons (car lst) r))
      (setq lst (cdr lst))
    )
    r
  )

  (defun _vl-some ( fun lst / func el r )
    (setq func (eval fun)) 
    (while (setq el (car lst))
      (if (setq r (func el))
        (setq lst nil)
      )
      (setq lst (cdr lst))
    )
    r
  )

  (defun _vl-remove ( el lst / e r )
    (while (setq e (car lst))
      (if (not (equal e el))
        (setq r (cons e r))
      )
      (setq lst (cdr lst))
    )
    (_reverse r)
  )

  (if (setq ss (ssget (list (cons 0 "LINE"))))
    (progn
      (repeat (setq i (sslength ss))
        (setq lil (cons (list (cdr (assoc 10 (setq lix (entget (ssname ss (setq i (1- i))))))) (cdr (assoc 11 lix))) lil))
      )
      (setq liln (cons (car lil) liln))
      (while (setq li (car lil))
        (setq lil (cdr lil))
        (setq lii (_vl-some (function (lambda (x) (if (or (equal (cadr li) (car x) 1e-8) (equal (cadr li) (cadr x) 1e-8)) x))) lil))
        (cond
          ( (and lii (equal (cadr li) (car lii) 1e-8))
            (setq liln (cons lii liln) lil (cons lii (_vl-remove lii lil)))
          )
          (  lii
            (setq liln (cons (_reverse lii) liln) lil (cons (_reverse lii) (_vl-remove lii lil)))
          )
        )
      )
      (entmake (list (cons 0 "POLYLINE") (cons 70 9)))
      (foreach pt (mapcar (function car) liln)
        (entmake (list (cons 0 "VERTEX") (cons 70 32) (cons 10 pt)))
      )
      (entmake (list (cons 0 "SEQEND")))
    )
  )
  (princ)
)

 

HTH.

M.R.

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

autoid374ceb4990
Collaborator
Collaborator

@marko_ribar wrote:

Here, try these 2 variants... First one should be much faster... Untested though (quickly written)...

HTH.

M.R.

 


I appreciate the effort, but as stated in my original post,  I am usingR14, NO VL functions.  The AI websites have the same reaction.

0 Likes
Message 8 of 40

leeminardi
Mentor
Mentor

@marko_ribar 

Tested it and got

leeminardi_0-1786292297671.png

 

lee.minardi
0 Likes
Message 9 of 40

marko_ribar
Advisor
Advisor

Thanks for reporting bug... Now fixed...

 

M.R.

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

autoid374ceb4990
Collaborator
Collaborator

@marko_ribar wrote:

Here, try these 2 variants... First one should be much faster... Untested though (quickly written)...

HTH.

M.R.

 


I tried the vanilla version in R14.  Seems to work correctly down to this line:

(setq lii (_vl-some (function (lambda (x) (if (or (equal (cadr li) (car x) 1e-8) (equal (cadr li) (cadr x) 1e-8)) x))) lil))

Gives me: "ACAD error: null function"

 

0 Likes
Message 11 of 40

Sea-Haven
Mentor
Mentor

@marko_ribar worked fine in Bricscad, is the problem (_vl-some which may not be in R14 being a VL function.

 

My biggest suggestion would be maybe look at upgrading software to something more current, Bricscad Lite has lisp. There are others.

SeaHaven_0-1786328399635.png

 

0 Likes
Message 12 of 40

marko_ribar
Advisor
Advisor

Here, I changed just slightly (_vl-some) function and line with (_vl-some) in routine body... It worked on my BricsCAD...

 

(defun c:lins23dpoly-vanilla ( / _reverse _vl-some _vl-remove ss i lil lix liln li lii )

  (defun _reverse ( lst / r )
    (while lst
      (setq r (cons (car lst) r))
      (setq lst (cdr lst))
    )
    r
  )

  (defun _vl-some ( fun lst / el r )
    (while (setq el (car lst))
      (if (apply fun (list el))
        (setq r el lst nil)
      )
      (setq lst (cdr lst))
    )
    r
  )

  (defun _vl-remove ( el lst / e r )
    (while (setq e (car lst))
      (if (not (equal e el))
        (setq r (cons e r))
      )
      (setq lst (cdr lst))
    )
    (_reverse r)
  )

  (if (setq ss (ssget (list (cons 0 "LINE"))))
    (progn
      (repeat (setq i (sslength ss))
        (setq lil (cons (list (cdr (assoc 10 (setq lix (entget (ssname ss (setq i (1- i))))))) (cdr (assoc 11 lix))) lil))
      )
      (setq liln (cons (car lil) liln))
      (while (setq li (car lil))
        (setq lil (cdr lil))
        (setq lii (_vl-some (function (lambda (x) (or (equal (cadr li) (car x) 1e-8) (equal (cadr li) (cadr x) 1e-8)))) lil))
        (cond
          ( (and lii (equal (cadr li) (car lii) 1e-8))
            (setq liln (cons lii liln) lil (cons lii (_vl-remove lii lil)))
          )
          (  lii
            (setq liln (cons (_reverse lii) liln) lil (cons (_reverse lii) (_vl-remove lii lil)))
          )
        )
      )
      (entmake (list (cons 0 "POLYLINE") (cons 70 9)))
      (foreach pt (mapcar (function car) liln)
        (entmake (list (cons 0 "VERTEX") (cons 70 32) (cons 10 pt)))
      )
      (entmake (list (cons 0 "SEQEND")))
    )
  )
  (princ)
)

 

HTH.

M.R.

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

autoid374ceb4990
Collaborator
Collaborator

@marko_ribar wrote:

Here, I changed just slightly (_vl-some) function and line with (_vl-some) in routine body... It worked on my BricsCAD...

HTH.

M.R.


Still getting "null function" at this line:

(setq lii (_vl-some (function (lambda (x) (or (equal (cadr li) (car x) 1e-8) (equal (cadr li) (cadr x) 1e-8)))) lil))

Not getting to the "_vl-some" routine.

I am no expert lisp programmer, but could it be that the "function" call is not supported in my old R14?

Don't worry about this problem.  I will write a "C" program that works in R14.

 

 

 

0 Likes
Message 14 of 40

marko_ribar
Advisor
Advisor

@autoid374ceb4990 wrote:

@marko_ribar wrote:

Here, I changed just slightly (_vl-some) function and line with (_vl-some) in routine body... It worked on my BricsCAD...

HTH.

M.R.


Still getting "null function" at this line:

(setq lii (_vl-some (function (lambda (x) (or (equal (cadr li) (car x) 1e-8) (equal (cadr li) (cadr x) 1e-8)))) lil))

Not getting to the "_vl-some" routine.

I am no expert lisp programmer, but could it be that the "function" call is not supported in my old R14?

Don't worry about this problem.  I will write a "C" program that works in R14.

 

 

 


That is possible... Your AutoCAD is too old, but I prepared this mod. that may succeed... Please, test it now... It also worked on my BricsCAD...

(defun c:lins23dpoly-vanilla-foo ( / _reverse _foo _vl-remove ss i lil lix liln li lii )

  (defun _reverse ( lst / r )
    (while lst
      (setq r (cons (car lst) r))
      (setq lst (cdr lst))
    )
    r
  )

  (defun _foo ( li lst / el r )
    (while (setq el (car lst))
      (if (or (equal (cadr li) (car el) 1e-8) (equal (cadr li) (cadr el) 1e-8))
        (setq r el lst nil)
      )
      (setq lst (cdr lst))
    )
    r
  )

  (defun _vl-remove ( el lst / e r )
    (while (setq e (car lst))
      (if (not (equal e el))
        (setq r (cons e r))
      )
      (setq lst (cdr lst))
    )
    (_reverse r)
  )

  (if (setq ss (ssget (list (cons 0 "LINE"))))
    (progn
      (repeat (setq i (sslength ss))
        (setq lil (cons (list (cdr (assoc 10 (setq lix (entget (ssname ss (setq i (1- i))))))) (cdr (assoc 11 lix))) lil))
      )
      (setq liln (cons (car lil) liln))
      (while (setq li (car lil))
        (setq lil (cdr lil))
        (setq lii (_foo li lil))
        (cond
          ( (and lii (equal (cadr li) (car lii) 1e-8))
            (setq liln (cons lii liln) lil (cons lii (_vl-remove lii lil)))
          )
          (  lii
            (setq liln (cons (_reverse lii) liln) lil (cons (_reverse lii) (_vl-remove lii lil)))
          )
        )
      )
      (entmake (list (cons 0 "POLYLINE") (cons 70 9)))
      (foreach pt (mapcar (function car) liln)
        (entmake (list (cons 0 "VERTEX") (cons 70 32) (cons 10 pt)))
      )
      (entmake (list (cons 0 "SEQEND")))
    )
  )
  (princ)
)

HTH.

M.R.

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

autoid374ceb4990
Collaborator
Collaborator

@marko_ribar wrote:

That is possible... Your AutoCAD is too old, but I prepared this mod. that may succeed... Please, test it now... It also worked on my BricsCAD...

HTH.

M.R.


Tried it, same error.

 

And for everyone that has suggested upgrading my AutoCAD - NOT going to do that. I am a retired civil engineer and land surveyor and I wrote all the software starting with AC 9 that I used in my business.  I even still have an old HP 7580B pen plotter.  Got tired of having to buy a new compiler every time AutoCAD upgraded, plus I did not like their "lend-lease" pricing policy.  End rant.

0 Likes
Message 16 of 40

Sea-Haven
Mentor
Mentor

I run lisp code I wrote back in the 80's on current Acad and Bricscad, with no code changes. You refer to compiler did you also do some ADS coding ?

 

Bricscad can be purchased as perpetual. 

0 Likes
Message 17 of 40

autoid374ceb4990
Collaborator
Collaborator

@Sea-Haven wrote:

I run lisp code I wrote back in the 80's on current Acad and Bricscad, with no code changes. You refer to compiler did you also do some ADS coding ?

Bricscad can be purchased as perpetual. 


When I started in business I purchased an Apple II and started writing my business software in interpreted Basic.  Then Apple brought out the Macintosh, and you had to purchase a $6000 Lisa machine to program the Mac.  I switched to the IBM PC and converted all my Apple stuff to "C".  Been using it ever since, compiled the "C" code into ARX programs for R14.

0 Likes
Message 18 of 40

jochen2
Observer
Observer

Try out my PEDIT3D 

Free download from 

www.black-cad.de

Regards

Jochen

 

0 Likes
Message 19 of 40

autoid374ceb4990
Collaborator
Collaborator

@jochen2 wrote:

Try out my PEDIT3D 

Free download from 

www.black-cad.de

Regards

Jochen


Tried to load it.  Got a "Load failed' error.  Probably because I am using R14.

0 Likes
Message 20 of 40

autoid374ceb4990
Collaborator
Collaborator

For those who have written code to do this, how about some pseudo code to explain the steps you used to convert the lines to a 3D POLY?

 

0 Likes