Run the code

Run the code

Automohan
Advocate Advocate
2,249 Views
5 Replies
Message 1 of 6

Run the code

Automohan
Advocate
Advocate

How to run the code...

[color=GREEN];;------------=={ 3D Polylines to LWPolylines }==-------------;;[/color]
[color=GREEN];;                                                            ;;[/color]
[color=GREEN];;  Converts a selection of 3D Polylines to LWPolylines with  ;;[/color]
[color=GREEN];;  elevation equal to the Z-component of the first vertex of ;;[/color]
[color=GREEN];;  the 3D Polyline. Retains all properties of the original   ;;[/color]
[color=GREEN];;  3D Polyline.                                              ;;[/color]
[color=GREEN];;------------------------------------------------------------;;[/color]
[color=GREEN];;  Author: Lee Mac, Copyright © 2012 - www.lee-mac.com       ;;[/color]
[color=GREEN];;------------------------------------------------------------;;[/color]

([color=BLUE]defun[/color] c:3d2lw ( [color=BLUE]/[/color] e i l s v x )
   ([color=BLUE]if[/color] ([color=BLUE]setq[/color] s ([color=BLUE]ssget[/color] [color=MAROON]"_:L"[/color] '((0 . [color=MAROON]"POLYLINE"[/color]) (-4 . [color=MAROON]"&="[/color]) (70 . )))
       ([color=BLUE]repeat[/color] ([color=BLUE]setq[/color] i ([color=BLUE]sslength[/color] s))
           ([color=BLUE]setq[/color] e ([color=BLUE]ssname[/color]  s ([color=BLUE]setq[/color] i ([color=BLUE]1-[/color] i)))
                 l ([color=BLUE]entget[/color]  e)
                 e ([color=BLUE]entnext[/color] e)
                 x ([color=BLUE]entget[/color]  e)
                 v [color=BLUE]nil[/color]
           )
           ([color=BLUE]while[/color] ([color=BLUE]eq[/color] [color=MAROON]"VERTEX"[/color] ([color=BLUE]cdr[/color] ([color=BLUE]assoc[/color] 0 x)))
               ([color=BLUE]setq[/color] v ([color=BLUE]cons[/color] ([color=BLUE]assoc[/color] 10 x) v)
                     e ([color=BLUE]entnext[/color] e)
                     x ([color=BLUE]entget[/color]  e)
               )
           )
           ([color=BLUE]if[/color] ([color=BLUE]entmake[/color]
                   ([color=BLUE]append[/color]
                       ([color=BLUE]list[/color]
                          '(000 . [color=MAROON]"LWPOLYLINE"[/color])
                          '(100 . [color=MAROON]"AcDbEntity"[/color])
                          '(100 . [color=MAROON]"AcDbPolyline"[/color])
                           ([color=BLUE]cons[/color]  038 ([color=BLUE]cadddr[/color] ([color=BLUE]last[/color] v)))
                           ([color=BLUE]cons[/color]  090 ([color=BLUE]length[/color] v))
                           ([color=BLUE]cons[/color]  070 ([color=BLUE]logand[/color] 129 ([color=BLUE]cdr[/color] ([color=BLUE]assoc[/color] 70 l))))
                           ([color=BLUE]assoc[/color] 008 l)
                           ([color=BLUE]cond[/color] (([color=BLUE]assoc[/color] 006 l)) ('(006 . [color=MAROON]"BYLAYER"[/color])))
                           ([color=BLUE]cond[/color] (([color=BLUE]assoc[/color] 039 l)) ('(039 . 0.0)))
                           ([color=BLUE]cond[/color] (([color=BLUE]assoc[/color] 062 l)) ('(062 . 256)))
                           ([color=BLUE]cond[/color] (([color=BLUE]assoc[/color] 370 l)) ('(370 . -1)))
                           ([color=BLUE]assoc[/color] 210 l)
                           ([color=BLUE]assoc[/color] 410 l)
                       )
                       ([color=BLUE]mapcar[/color] '([color=BLUE]lambda[/color] ( v ) ([color=BLUE]list[/color] 10 ([color=BLUE]cadr[/color] v) ([color=BLUE]caddr[/color] v))) ([color=BLUE]reverse[/color] v))
                   )
               )
               ([color=BLUE]entdel[/color] ([color=BLUE]cdr[/color] ([color=BLUE]assoc[/color] -1 l)))
           )
       )
   )
   ([color=BLUE]princ[/color])
)
([color=BLUE]princ[/color])

Found at https://www.cadtutor.net/forum/topic/39796-3d-polyline-vector-z-value-to-2d-polyline-elevation/

"Save Energy"
Did you find this reply helpful? If so please use the Accept as Solution
0 Likes
Accepted solutions (2)
2,250 Views
5 Replies
Replies (5)
Message 2 of 6

CodeDing
Advisor
Advisor

@Automohan,

 

See: http://www.lee-mac.com/runlisp.html

 

In short:

- save your lsp file

- load into AutoCAD (probably use APPLOAD command)

- run your command by typing into the command line (in this case: 3D2LW)

 

Best,

~DD

Message 3 of 6

marko_ribar
Advisor
Advisor
Accepted solution

The code with removed BBC tags...

;;------------=={ 3D Polylines to LWPolylines }==-------------;;
;;                                                            ;;
;;  Converts a selection of 3D Polylines to LWPolylines with  ;;
;;  elevation equal to the Z-component of the first vertex of ;;
;;  the 3D Polyline. Retains all properties of the original  ;;
;;  3D Polyline.                                              ;;
;;------------------------------------------------------------;;
;;  Author: Lee Mac, Copyright © 2012 - www.lee-mac.com      ;;
;;------------------------------------------------------------;;

(defun c:3d2lw ( / e i l s v x )
  (if (setq s (ssget "_:L" '((0 . "POLYLINE") (-4 . "&=") (70 . )))
      (repeat (setq i (sslength s))
          (setq e (ssname  s (setq i (1- i)))
                l (entget  e)
                e (entnext e)
                x (entget  e)
                v nil
          )
          (while (eq "VERTEX" (cdr (assoc 0 x)))
              (setq v (cons (assoc 10 x) v)
                    e (entnext e)
                    x (entget  e)
              )
          )
          (if (entmake
                  (append
                      (list
                          '(000 . "LWPOLYLINE")
                          '(100 . "AcDbEntity")
                          '(100 . "AcDbPolyline")
                          (cons  038 (cadddr (last v)))
                          (cons  090 (length v))
                          (cons  070 (logand 129 (cdr (assoc 70 l))))
                          (assoc 008 l)
                          (cond ((assoc 006 l)) ('(006 . "BYLAYER")))
                          (cond ((assoc 039 l)) ('(039 . 0.0)))
                          (cond ((assoc 062 l)) ('(062 . 256)))
                          (cond ((assoc 370 l)) ('(370 . -1)))
                          (assoc 210 l)
                          (assoc 410 l)
                      )
                      (mapcar '(lambda ( v ) (list 10 (cadr v) (caddr v))) (reverse v))
                  )
              )
              (entdel (cdr (assoc -1 l)))
          )
      )
  )
  (princ)
)

(princ)

HTH. M.R.

Marko Ribar, d.i.a. (graduated engineer of architecture)
Message 4 of 6

Kent1Cooper
Consultant
Consultant
Accepted solution

It's not just a question of how to load and run AutoLisp code.  Somehow you're first going to need to strip away all the color-encoding elements in that collection of text, which I assume came out of the VLIDE somehow, though I haven't seen them appear in that format in the AutoCAD Forums.  I think @Lee_Mac sees this Forum, at least from time to time, and has a website with a lot of good stuff on it, but that seems to have been a one-off solution [at least, searching there for that command name doesn't return anything] -- you might ask him if he can supply a version without the color encoding.

[EDIT:  Marko got a stripped version in while I was writing....]

Kent Cooper, AIA
0 Likes
Message 5 of 6

Lee_Mac
Advisor
Advisor

Many thanks for the mention @Kent1Cooper - unfortunately I'm not able to visit the forum as often as I used to, but still try to contribute to the CAD community as time permits.

 

I see that @marko_ribar has kindly provided a version of the code free of BBCode tags. Such tags could previously be used to add AutoLISP syntax highlighting to code when posting on forums which permitted the use of BBCode within preformatted code tags (CADTutor being one such forum).

 

Unfortunately, when the underlying forum software subsequently changes, the ability to use formatting within code blocks is sometimes lost, resulting in the BBCode tags becoming visible. I try to fix posts containing such code as and when I see them.

 

Thanks,

 

Lee

Message 6 of 6

analanll003
Community Visitor
Community Visitor

(defun c:DrawPart()

  (setq p1 '(0 0 0)) ; نقطة البداية

  ;; رسم القاعدة المستطيلة

  (command "_.rectangle" p1 "85,50") 

  

  ;; رسم الفتحة الدائرية

  (setq center '(42.5 25))

  (command "_.circle" center 10) 

 

  ;; رسم الجزء العلوي (المستطيل الصغير)

  (setq p2 '(35 50))

  (command "_.rectangle" p2 "15,15") 

  

  ;; رسم الاسطوانة العلوية

  (setq center2 '(42.5 65))

  (command "_.circle" center2 10) 

 

  (princ "\nتم إنشاء المجسم بنجاح!")

)

0 Likes