Author Topic: need to assign polylines to layers with vl-some  (Read 1476 times)

0 Members and 1 Guest are viewing this topic.

neeboy

  • Guest
need to assign polylines to layers with vl-some
« on: November 08, 2016, 11:32:51 AM »
I am trying to use a LISP routine to send polylines to various layers based on their "Vertex X" parameter as seen in the Properties palette.  I cannot get the assignment to work, there's some bug in my program where I'm trying to use vl-some.  :?

I've attached the LISP file and the block that has a polyline (L-shaped) I want to change with the LISP.  This will not be the final version of the program, I'm trying to learn from this, so if someone could help me get the pline (with Vertex X of 30) onto the layer as assigned in the program, I should be able to handle it from there.  Thanks in advance for any help!

ribarm

  • Gator
  • Posts: 3279
  • Marko Ribar, architect
Re: need to assign polylines to layers with vl-some
« Reply #1 on: November 08, 2016, 12:38:08 PM »
Here you are :

Code: [Select]
(defun c:spiralpl (/ removedup addprop bks cmd nm bkl a b c d e i)

  (defun *error* (msg)
    (if (not
          (wcmatch (strcase msg t) "*break,*cancel*,*exit*")
        )
      (progn
        (princ "")
        (setvar 'nomutt nm)
        (setvar 'cmdecho cmd)
        (vla-endundomark
          (vla-get-activedocument (vlax-get-acad-object))
        )
      )
    )
    (princ)
  )
  (defun removedup (l)
    (if l
      (cons (car l) (removedup (vl-remove (car l) (cdr l))))
      ;; removing duplicate element from the list
    )
  )
  (defun addprop (obj layer)
    (vla-put-color obj 256)
    ;; put color to bylayer
    (vla-put-layer obj layer)
    ;; put in the layer specifed
  )

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

  (if (setq bks (ssget '((0 . "insert"))))
    ;; select block on screen
    (progn
      (vla-startundomark
        (vla-get-activedocument (vlax-get-acad-object))
      )
      ;; setting the undo mark
      (setq cmd (getvar 'cmdecho)
            nm  (getvar 'nomutt)
      )
      (setvar 'cmdecho 0)
      ;; hiding command window
      (setvar 'nomutt 1)
      ;; hiding other command details
      (mapcar '(lambda (x y)
                 (if (not (tblsearch "layer" x))
                                        ; verifies layer are present or not
                   (entmakex (list
                               '(0 . "layer")
                               (cons 100 "AcDbSymbolTableRecord")
                               (cons 100 "AcDbLayerTableRecord")
                               (cons 2 x)
                               ;; add layername
                               (cons 70 0)
                               (cons 62 y)
                               ;; add color
                               (cons 6 "Continuous")
                             )
                   )
                 )
                 ;; creating layer
               )
              (list "HILMOT-ROLLERS"
                    "HILMOT-SENSORS"
                    "HILMOT-FRAMES"
                    "HILMOT-MDR"
              )
              ;; layer list
              (list 8 1 4 5 5 3)
              ;; color code for the layers
      )
      (repeat (setq i (sslength bks))
        ;; setting the repeat count
        (setq bkl
               (cons
                 (cdr (assoc 2 (entget (ssname bks (setq i (1- i))))))
                 bkl
               )
        )
        ;; getting the selected block list
      )
      (setq bkl (removedup bkl))
      ;;removing duplicate names of block
      (foreach bk bkl
        ;; running code for every block
        (command "-bedit" bk)
        ;; opening block editor
        (vla-zoomextents (vlax-get-acad-object))
        (setq e nil)
        (if (setq a (ssget "_x" '((0 . "*polyline"))))
          ;; selecting all polylines inside block in block editor
          (progn
            (repeat (setq i (sslength a))
              (setq
                b (vlax-ename->vla-object (ssname a (setq i (1- i))))
              )
              ;; getting each polyline object
              (cond ;; applying conditions here
                    ((and (eq (vla-get-objectname b) "AcDbPolyline")
                          ;; check object is POLYLINE
                          (setq c (car (vlax-get b 'coordinates)))
                          ;; Get "X" coordinate of start point
                          (vl-some '(lambda (x)
                                      (equal c x 1e-4)
                                    )
                                   '(20 30 -26.0633 13.7408)
                          )
                          ;; Check whether the x coordinate of the polyline start point matches with the list if matches then do this
                     )
                     (addprop b "HILMOT-SENSORS")
                    )
                    (t (addprop b "HILMOT-ROLLERS"))
                    ;; All rest objects goes to this layer
                    (print x)
                    (print c)
              )
            )
          )
        )
        (vl-cmdf "_.bclose" "_sav")
        ;;closing block editor
        (initcommandversion)
      )
      ;; foreach
      (setvar 'nomutt nm)
      (setvar 'cmdecho cmd)
      ;;restoring the variables again
      (vla-endundomark
        (vla-get-activedocument (vlax-get-acad-object))
      )
      ;;ending the undo mark
    )
    ;; progn
  )
  ;; if
  (princ)
)

(vl-load-com)
(princ)
(princ
  (strcat
    "\n:: Spiral.lsp ::"
    "\n:: Based on a program Created by Satish Rajdev | "
    (menucmd "M=$(edtime,$(getvar,date),DDDD\",\" D MONTH YYYY)"
    )
    " ::"
    "\n:: Type \"spiralpl\" to Invoke ::"
  )
)
(princ)

Regards...
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: need to assign polylines to layers with vl-some
« Reply #2 on: November 08, 2016, 12:42:51 PM »
Replace your foreach loop with this:
Code - Auto/Visual Lisp: [Select]
  1.       (foreach blk bkl
  2.           (setq ent (tblobjname "block" blk))
  3.           (while (setq ent (entnext ent))
  4.               (setq enx (entget ent))
  5.               (entmod
  6.                   (subst
  7.                       (if
  8.                           (and
  9.                               (= (cdr (assoc 0 enx)) "LWPOLYLINE")
  10.                               (setq xco (cadr (assoc 10 enx)))
  11.                               (vl-some '(lambda ( x ) (equal xco x 1e-4)) '(20 30 -26.0633 13.7408))
  12.                           )
  13.                          '(8 . "HILMOT-SENSORS")
  14.                          '(8 . "HILMOT-ROLLERS")
  15.                       )
  16.                       (assoc 8 enx) enx
  17.                   )
  18.               )
  19.           )
  20.       )

(Untested)

neeboy

  • Guest
Re: need to assign polylines to layers with vl-some
« Reply #3 on: November 08, 2016, 01:17:02 PM »
Thanks for the help everyone!  :smitten: