Jump to content

Freeze by linetype? - VBA


Recommended Posts

Hello all. I have a dream..... I would like to iterate through all objects in the dwg (that are displayed), select by linetype, and freeze (or not display) objects with that line type. Specifically even if they are in a block reference..... could I change thier line types to "blank" line type

? Hmmmm, only for certain conditions ovbiously.......


Link to comment
Share on other sites

I don't know how to do it in VBA but here's a way to do it with AutoLISP:



(setq ss1 (ssget "x" (list (cons (6 LINETYPENAME))))
(setq ent-index 0)
(repeat (sslength ss1)
 (setq entname (ssname ss1 ent-index))
 (setq entlist (entget entname))
 (if (assoc 60 entlist)
   (setq entlist (subst '(60 . 1) (assoc 60 entlist) entlist))
   (setq entlist (append entlist '((60 . 1)))))
 (entmod entlist)
 (setq ent-index (1+ ent-index))

Link to comment
Share on other sites

Uddfl, that will skip entities with linetype set to "bylayer"...


Just a thought.. :P

Well, I just threw a cheap and dirty one out there. I didn't feel like typing that much (yes, Friday).


Ahh, and one more thing - watch out for selection sets over 32767 ents... repeat method won't work for these...
Hmmm... true. How do you address those? WHILE function? :?
Link to comment
Share on other sites

Check this one -


;;  Select by Linetype and Make Invisible ~ Lee McDonnell 27.02.09

(defun lsel (ltyp / tdef laylst)
 (setq laylst "")
 (while (setq tdef (tblnext "LAYER" (not tdef)))
      (if (eq (strcase ltyp) (cdr (assoc 6 tdef)))
    (setq laylst (strcat (cdr (assoc 2 tdef)) (chr 44) laylst))))
 (substr laylst 1 (1- (strlen laylst))))

(defun c:test (/ lt ss)
 (if (and (setq lt (strcase (getstring "\nSpecify Linetype to Select:  ")))
      (tblsearch "LTYPE" lt)
          (setq ss (ssget "X" (list (cons -4 "<OR") (cons 8 (lsel lt)) (cons 6 lt) (cons -4 "OR>")
            (if (getvar "CTAB") (cons 410 (getvar "CTAB")) (cons 67 (- 1 (getvar "TILEMODE"))))))))
     (setq ss (vl-remove-if '(lambda (x) (if (assoc 6 x) (/= lt (cdr (assoc 6 x)))))
        (mapcar 'entget (mapcar 'cadr (ssnamex ss)))))
     (foreach e ss
   (if (assoc 60 e)
     (entmod (subst (cons 60 1) (assoc 60 e) e)) (entmod (append e (list (cons 60 1)))))))
   (princ "\nError in Selection Set Retrieval..."))

Need to account for all situations...

  • On layer with required linetype, with object linetype set to bylayer (need these...)
  • On layer with required linetype, object linetype set to something different (get rid of these..)
  • Not on layer with required linetype, but object set to required linetype. (need these...)

Not an easy task...

Link to comment
Share on other sites

If you didn't want to convert the selection set into a list of entity names, you could use something like this to iterate through ss:


(defun c:test  (/ ss i ent)
 (setq    ss (ssget) i  (sslength ss))
 (while (not (minusp (setq i (1- i))))
   (setq ent (ssname ss i))
   (princ (strcat "\n" (vl-princ-to-string (cdadr (entget ent))))))


Silly example I know, but just wanted to show you the idea :thumbsup:

Link to comment
Share on other sites

Haha... I probably could have done it without vl functions, but it would have taken a ton of coding :)


Using the ssnamex to put it into a list is good because instead of shuffling through the set, which is a tedious method - you can use what LISP was meant for: a list.


So then you can use all the list functions such as foreach, mapcar.. etc etc.


Hope this helps :)



Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...