Author Topic: Block select Lisp needed...  (Read 17406 times)

0 Members and 1 Guest are viewing this topic.

hudster

  • Gator
  • Posts: 2848
Block select Lisp needed...
« on: August 26, 2004, 05:03:23 AM »
I'm looking for a lisp that will allow me to move blocks to a new layer depending on their attribute values.

I need to move emergency lighting blocks only to a new layer for building warrant purposes, and It's a bit of a pain having to manually change each one to a new layer.

The blocks all have attribute values ending in E.

Cheers for any help
Andy.
Revit BDS 2017, 2016, 2015, 2014, AutoCAD 2017, 2016, Navisworks 2017, 2016, BIM360 Glue

SMadsen

  • Guest
Block select Lisp needed...
« Reply #1 on: August 26, 2004, 07:44:22 AM »
You could choose to write it yourself.
- Make a selection set of all blocks with attributes {hint: '((0 . "INSERT")(66 . 1)) }
- Run through each insert in the selection to test for attribute values {hints: ENTNEXT and WCMATCH}
- Remove any insert that doesn't match {hint: SSREMOVE}
- Return finished selection set

Mark

  • Custom Title
  • Seagull
  • Posts: 28762
Block select Lisp needed...
« Reply #2 on: August 26, 2004, 08:45:24 AM »
Quote from: SMadsen

- Remove any insert that doesn't match {hint: SSREMOVE}

I don't see that in my docs Stig, is that one of your functions?
TheSwamp.org  (serving the CAD community since 2003)

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Block select Lisp needed...
« Reply #3 on: August 26, 2004, 08:51:22 AM »
I think he meant ssdel. :)
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

daron

  • Guest
Block select Lisp needed...
« Reply #4 on: August 26, 2004, 08:51:45 AM »
I was wondering the same thing.  ssdel comes to mind though.

SMadsen

  • Guest
Block select Lisp needed...
« Reply #5 on: August 26, 2004, 09:01:26 AM »
Doh! Yep, SSDEL  :roll:

Mark

  • Custom Title
  • Seagull
  • Posts: 28762
Block select Lisp needed...
« Reply #6 on: August 26, 2004, 09:04:32 AM »
Stig you ready for another race?
TheSwamp.org  (serving the CAD community since 2003)

SMadsen

  • Guest
Block select Lisp needed...
« Reply #7 on: August 26, 2004, 09:12:07 AM »
Bring it on :)
What kind, where, how?

Mark

  • Custom Title
  • Seagull
  • Posts: 28762
Block select Lisp needed...
« Reply #8 on: August 26, 2004, 09:16:01 AM »
I'm thinking of solving the problem posted by Hudster. I have (almost) the solution using VLAX methods.
TheSwamp.org  (serving the CAD community since 2003)

hudster

  • Gator
  • Posts: 2848
Block select Lisp needed...
« Reply #9 on: August 26, 2004, 09:22:03 AM »
I've not quite got the necessary skills regarding selection sets yet.

I'm only at the lisp stage where I can write basic routines. :(

***edit***

Stig, are your autolisp lessons nearly ready?
Revit BDS 2017, 2016, 2015, 2014, AutoCAD 2017, 2016, Navisworks 2017, 2016, BIM360 Glue

Mark

  • Custom Title
  • Seagull
  • Posts: 28762
Block select Lisp needed...
« Reply #10 on: August 26, 2004, 10:10:56 AM »
Here is my first shot at it. It is rather slow.
Code: [Select]



(defun startTimer ()
  (setq time (getvar "DATE"))
  )

(defun endTimer (func)
  (setq time    (- (getvar "DATE") time)
        seconds (* 86400.0 (- time (fix time)))
        )
  (gc)
  (outPut seconds func)
  )

(defun outPut (secs def)
  ;(princ "\nPurging...")
  ;(command "PURGE" "Layers" "*" "N")
  (gc)
  (princ (strcat "\nTimed " def ": " (rtos secs 2 6)))
  (princ)
  )


(defun get-mspace ()
  (vla-get-modelspace
    (vla-get-activedocument
      (vlax-get-acad-object)
      )
    )
  )

(defun check-for-char (obj char / attrib-list ans_lst)
  (setq attrib-list
        (vlax-safearray->list
          (vlax-variant-value
            (vla-GetAttributes obj)
            )
          )
        )

  (mapcar
    '(lambda (x / ts)
       (setq ts (vla-get-textstring x))
       (cond ((= (substr ts (strlen ts)) char)
              (setq ans_lst (cons "yes" ans)))
             )
       )
    attrib-list
    ); mapcar

  (if (vl-position "yes" ans_lst)
    T nil
    )
  )
 

(defun chg-blk-to-lay (/ mspace o_name has_attrs)

  (setq mspace (get-mspace))
  (startTimer)
  (vlax-for blk mspace
            (setq o_name (vla-get-objectname blk))

            (cond ((= o_name "AcDbBlockReference")
                   (cond ((vlax-property-available-p blk 'HasAttributes)
                          (if (check-for-char blk "E"); change the char here
                            (vla-put-layer blk "0"); change layer name here
                            )
                          )
                         )
                   ); 1st cond.
                  (T (princ "\r searching ............."))
                  )
            )
  (endTimer (vl-symbol-name 'chg-blk-to-lay))
  (princ)
  )

TheSwamp.org  (serving the CAD community since 2003)

SMadsen

  • Guest
Block select Lisp needed...
« Reply #11 on: August 26, 2004, 10:13:33 AM »
Here's a simple take on it. A bit primitive at the command interface but you can change it to whatever suits the task best

Code: [Select]
(defun getAttrib (ent val / att blk entl)
  (setq blk ent)
  (while (and ent (/= "SEQEND" (cdr (assoc 0 (setq entl (entget ent))))))
    (and (= "ATTRIB" (cdr (assoc 0 entl)))
         (wcmatch (cdr (assoc 1 entl)) val)
         (setq att blk)
    )
    (setq ent (entnext ent))
  )
  att
)

(defun ss_attval (/ a ent sset)
  (cond ((setq sset (ssget "X" '((0 . "INSERT") (66 . 1))))
         (setq a 0)
         (repeat (sslength sset)
           (setq ent (ssname sset a)
                 a   (1+ a))
           (and (not (getAttrib ent "*E"))
                (ssdel ent sset)
                (setq a (1- a)))
         )
        )
  )
  sset
)

(defun C:ATTLAY (/ ss)
  (cond ((setq ss (ss_attval))
         (command "_CHPROP" ss "" "Layer")
        )
  )
)


Thanks for the reminder on the lessons. I've been a bit hung up this summer so they're not entirely translated yet. But enough to start it up and get translations ready during.

SMadsen

  • Guest
Block select Lisp needed...
« Reply #12 on: August 26, 2004, 10:14:06 AM »
Dang, 3 minutes late :)

SMadsen

  • Guest
Block select Lisp needed...
« Reply #13 on: August 26, 2004, 10:18:13 AM »
By the way, Mark. I've developed a preference for the MILLISECS variable. It's quite accurate and easier to deal with for timers

(setq time (getvar "MILLISECS"))
(setq time (/ (- (getvar "MILLISECS") time) 1000.0))
(princ (strcat "Elapsed time: " (rtos time) " seconds"))

Mark

  • Custom Title
  • Seagull
  • Posts: 28762
Block select Lisp needed...
« Reply #14 on: August 26, 2004, 10:23:06 AM »
I just changed mine a bit but it didn't help!

thanks Stig that's nice.
TheSwamp.org  (serving the CAD community since 2003)